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

This commit is contained in:
Jenkins 2014-04-30 11:53:54 +00:00 committed by Gerrit Code Review
commit 60205a1e4c
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
@ -46,6 +47,7 @@ from muranodashboard import utils
LOG = logging.getLogger(__name__)
ALL_CATEGORY_NAME = 'All'
LATEST_APPS_QUEUE_LIMIT = 6
class DictToObj(object):
@ -113,6 +115,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)
@ -155,6 +175,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__'):
@ -246,7 +267,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,
@ -296,10 +318,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):
@ -307,7 +333,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