예제 #1
0
 def add_view(self, request, form_url='', extra_context=None):
     """ Redirects to select account view if required """
     if request.user.is_superuser:
         from_account_id = self.get_account_from_preserve_filters(request)
         if from_account_id:
             set_url_query(request, 'account', from_account_id)
         account_id = request.GET.get('account')
         if account_id or Account.objects.count() == 1:
             kwargs = {}
             if account_id:
                 kwargs = dict(pk=account_id)
             self.account = Account.objects.get(**kwargs)
             opts = self.model._meta
             context = {
                 'title':
                 _("Add %s for %s") %
                 (opts.verbose_name, self.account.username),
                 'from_account':
                 bool(from_account_id),
                 'from_select':
                 True,
                 'account':
                 self.account,
                 'account_opts':
                 Account._meta,
             }
             context.update(extra_context or {})
             return super(AccountAdminMixin,
                          self).add_view(request,
                                         form_url=form_url,
                                         extra_context=context)
     return HttpResponseRedirect('./select-account/?%s' %
                                 request.META['QUERY_STRING'])
예제 #2
0
 def changeform_view(self, request, object_id=None, form_url='', extra_context=None):
     account_id = self.get_account_from_preserve_filters(request)
     if not object_id:
         if account_id:
             # Preselect account
             set_url_query(request, 'account', account_id)
     context = {
         'from_account': bool(account_id),
         'account': not account_id or Account.objects.get(pk=account_id),
         'account_opts': Account._meta,
     }
     context.update(extra_context or {})
     return super(AccountAdminMixin, self).changeform_view(request,
             object_id=object_id, form_url=form_url, extra_context=context)
예제 #3
0
 def changeform_view(self,
                     request,
                     object_id=None,
                     form_url='',
                     extra_context=None):
     account_id = self.get_account_from_preserve_filters(request)
     if not object_id:
         if account_id:
             # Preselect account
             set_url_query(request, 'account', account_id)
     context = {
         'from_account': bool(account_id),
         'account': not account_id or Account.objects.get(pk=account_id),
         'account_opts': Account._meta,
     }
     context.update(extra_context or {})
     return super(AccountAdminMixin,
                  self).changeform_view(request,
                                        object_id,
                                        form_url=form_url,
                                        extra_context=context)
예제 #4
0
 def add_view(self, request, form_url='', extra_context=None):
     """ Redirects to select account view if required """
     if request.user.is_superuser:
         from_account_id = self.get_account_from_preserve_filters(request)
         if from_account_id:
             set_url_query(request, 'account', from_account_id)
         account_id = request.GET.get('account')
         if account_id or Account.objects.count() == 1:
             kwargs = {}
             if account_id:
                 kwargs = dict(pk=account_id)
             self.account = Account.objects.get(**kwargs)
             opts = self.model._meta
             context = {
                 'title': _("Add %s for %s") % (opts.verbose_name, self.account.username),
                 'from_account': bool(from_account_id),
                 'account': self.account,
                 'account_opts': Account._meta,
             }
             context.update(extra_context or {})
             return super(AccountAdminMixin, self).add_view(request,
                     form_url=form_url, extra_context=context)
     return HttpResponseRedirect('./select-account/?%s' % request.META['QUERY_STRING'])