Fill 'Latest Apps' section with recently deployed/uploaded Apps

Each App that was recently added to an Environment using Deploy/Quick
deploy button (actually, just pressing that button is enough) or
uploaded to catalog at Packages panel is added to Latest Apps list on
top of AppCatalog. To refresh that list with newly deployed App, on
final step Wizard is redirected to AppCatalog panel instead of simply
closing modal form. This fixes bug #1306579 as well.

That commit is dependent on https://review.openstack.org/#/c/90315/
and should be merged once that change gets into
python-muranoclient>=0.5.1.

Change-Id: Iefe2abb9efb5ae8cbe2d26809eb876eb0ecd5906
Closes-Bug: #1312213
Closes-Bug: #1306579
This commit is contained in:
Timur Sufiev 2014-04-24 17:34:35 +04:00
parent 47736f0727
commit 56a1d9277a
3 changed files with 45 additions and 7 deletions

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
import copy
import functools
import json
@ -44,6 +45,7 @@ from muranodashboard import utils
LOG = logging.getLogger(__name__)
ALL_CATEGORY_NAME = 'All'
LATEST_APPS_QUEUE_LIMIT = 6
class DictToObj(object):
@ -111,6 +113,24 @@ def create_quick_environment(request):
return api.environment_create(request, params)
def update_latest_apps(func):
@functools.wraps(func)
def __inner(request, **kwargs):
apps = request.session.setdefault('latest_apps', collections.deque())
app_id = kwargs['app_id']
if app_id in apps: # move recent app to the beginning
apps.remove(app_id)
apps.appendleft(app_id)
if len(apps) > LATEST_APPS_QUEUE_LIMIT:
apps.pop()
return func(request, **kwargs)
return __inner
@update_latest_apps
@auth_dec.login_required
def quick_deploy(request, app_id):
env = create_quick_environment(request)
@ -144,6 +164,7 @@ class LazyWizard(wizard_views.SessionWizardView):
raise TypeError(u"%s() received an invalid keyword %r" % (
cls.__name__, key))
@update_latest_apps
def view(request, *args, **kwargs):
forms = initforms
if hasattr(initforms, '__call__'):
@ -235,7 +256,8 @@ class Wizard(views.ModalFormMixin, LazyWizard):
response["X-Horizon-Add-To-Field"] = field_id
return response
else:
return http.HttpResponse('Done')
ns_url = 'horizon:murano:catalog:index'
return http.HttpResponseRedirect(url.reverse(ns_url))
def get_form_initial(self, step):
init_dict = {'request': self.request,
@ -285,10 +307,14 @@ class IndexView(list_view.ListView):
if category != ALL_CATEGORY_NAME:
query_params['category'] = category
pkgs = []
pkgs, self.mappings = [], {}
with api.handled_exceptions(self.request):
client = api.muranoclient(self.request)
pkgs = client.packages.filter(**query_params)
for pkg in pkgs:
self.mappings[pkg.id] = pkg
return pkgs
def get_template_names(self):
@ -296,7 +322,10 @@ class IndexView(list_view.ListView):
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['latest_list'] = []
app_ids = self.request.session.get('latest_apps', [])
context['latest_list'] = [self.mappings[app_id] for app_id in app_ids
if app_id in self.mappings]
categories = []
with api.handled_exceptions(self.request):

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
from django import forms
from django.core.files import uploadedfile
from django.utils.translation import ugettext_lazy as _
@ -22,6 +23,8 @@ from horizon import exceptions
from horizon import messages
from muranoclient.common.exceptions import HTTPException
from muranodashboard.environments import api
from muranodashboard.catalog import views
LOG = logging.getLogger(__name__)
@ -68,9 +71,15 @@ class UploadPackageForm(SelfHandlingForm):
LOG.debug('Uploading package {0}'.format(data))
try:
data, files = split_post_data(data)
result = api.muranoclient(request).packages.create(data, files)
messages.success(request, _('Package uploaded.'))
return result
package = api.muranoclient(request).packages.create(data, files)
@views.update_latest_apps
def _handle(_request, app_id):
messages.success(_request, _('Package uploaded.'))
return package
return _handle(request, app_id=package.id)
except HTTPException:
LOG.exception(_('Uploading package failed'))
redirect = reverse('horizon:murano:packages:index')

View File

@ -5,5 +5,5 @@ six>=1.5.2
PyYAML>=3.1.0
django-floppyforms>=1.1
yaql>=0.2.2,<0.3
python-muranoclient>=0.5.0
python-muranoclient>=0.5.1