From e71f176e8c85ac0111b480ad4106455dafc4e003 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 9 Jan 2011 04:14:41 +0100 Subject: Manage own items shortcuts (refs #54) --- ishtar/furnitures/context_processors.py | 14 +++++++++++++- ishtar/furnitures/forms.py | 9 ++++++++- ishtar/furnitures/models.py | 7 +++++++ ishtar/furnitures/urls.py | 2 ++ ishtar/furnitures/views.py | 8 ++++++++ ishtar/templates/base.html | 21 +++++++++++++++++++-- static/js/ishtar.js | 8 ++++++++ static/media/style.css | 31 +++++++++++++++++++++++++++++-- 8 files changed, 94 insertions(+), 6 deletions(-) diff --git a/ishtar/furnitures/context_processors.py b/ishtar/furnitures/context_processors.py index df401cda0..ed6fb1252 100644 --- a/ishtar/furnitures/context_processors.py +++ b/ishtar/furnitures/context_processors.py @@ -17,11 +17,14 @@ # See the file COPYING for details. +from django.utils.translation import ugettext, ugettext_lazy as _ + from ishtar import settings from menus import Menu +import models def get_base_context(request): - dct = {} + dct = {'URL_PATH':settings.URL_PATH} if settings.APP_NAME: dct["APP_NAME"] = settings.APP_NAME dct["COUNTRY"] = settings.COUNTRY @@ -35,5 +38,14 @@ def get_base_context(request): dct['MENU'] = request.session['MENU'] dct['JQUERY_URL'] = settings.JQUERY_URL dct['JQUERY_UI_URL'] = settings.JQUERY_UI_URL + dct['current_menu'] = [] + for lbl, model in ((_(u"Archaelogical file"), models.File),): + model_name = model.__name__.lower() + current = model_name in request.session and request.session[model_name] + items = [] + for item in model.get_owns(request.user): + items.append((item.pk, unicode(item), unicode(item.pk) == current)) + if items: + dct['current_menu'].append((lbl, model_name, items)) return dct diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index 64acaa5c5..6c1b48fc4 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -295,6 +295,13 @@ class Wizard(NamedUrlSessionFormWizard): if current_obj: return self.get_instanced_init(current_obj, request, storage, step) + elif step.startswith('selec-') and step in self.form_list \ + and 'pk' in self.form_list[step].associated_models: + model_name = self.form_list[step].associated_models['pk' + ].__name__.lower() + val = model_name in request.session and request.session[model_name] + if val: + return {'pk':val} return super(Wizard, self).get_form_initial(request, storage, step) def get_instanced_init(self, obj, request, storage, step): @@ -419,7 +426,7 @@ def get_now(): class FileFormSelection(forms.Form): form_label = _("Archaelogical file") associated_models = {'pk':models.File} - pk = forms.IntegerField(label=_("Archaelogical file"), + pk = forms.IntegerField(label=_("References/location"), widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-file'), associated_model=models.File), validators=[models.valid_id(models.File)]) diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py index 6664adb72..ef5ad8cb2 100644 --- a/ishtar/furnitures/models.py +++ b/ishtar/furnitures/models.py @@ -269,6 +269,13 @@ class File(BaseHistorizedItem, OwnPerms): items = [u'%d-%d' % (self.year, self.numeric_reference)] + items return u" - ".join(items) + @classmethod + def get_owns(cls, user, order_by=['-year', '-numeric_reference']): + if user.is_anonymous(): + return [] + return cls.objects.filter(history_modifier=user).order_by(*order_by + ).all() + class OperationType(GeneralType): class Meta: verbose_name = _(u"Operation type") diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index 4a9349700..762aa135f 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -47,4 +47,6 @@ urlpatterns += patterns('ishtar.furnitures.views', name='autocomplete-organization'), url(BASE_URL + r'autocomplete-file/$', 'autocomplete_file', name='autocomplete-file'), + url(BASE_URL + r'update-current-item/$', 'update_current_item', + name='update-current-item'), ) diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index dcf0f28d9..ba05d0b39 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -42,6 +42,14 @@ def index(request): return render_to_response('index.html', dct, context_instance=RequestContext(request)) +def update_current_item(request): + if not request.is_ajax() and not request.method == 'POST': + return Http404() + print request.POST + if 'value' in request.POST and 'item' in request.POST: + request.session[request.POST['item']] = request.POST['value'] + return HttpResponse('ok') + def check_permission(request, action_slug, obj_id=None): if obj_id: return menu.items[action_slug].is_available(request.user, obj_id) diff --git a/ishtar/templates/base.html b/ishtar/templates/base.html index 6a1136021..2b2b440c8 100644 --- a/ishtar/templates/base.html +++ b/ishtar/templates/base.html @@ -8,13 +8,15 @@ {% block title %}Ishtar{% if APP_NAME %} - {{APP_NAME}}{%endif%}{% endblock %} + -
- {% block context %}{% endblock %} + {% block context %}{% if current_menu %} +
+
+ {% trans "Default items"%} +
    + {% for lbl, model_name, items in current_menu %} +
  • +
  • + {% endfor %} +
+
+
+ {% endif %}{% endblock %}