示例#1
0
 def render_change_form(self,
                        request,
                        context,
                        add=False,
                        change=False,
                        form_url='',
                        obj=None):
     if not add:
         if request.method == 'GET' and not obj.is_active:
             messages.warning(request, 'This account is disabled.')
         context.update({
             'services':
             sorted([
                 model._meta
                 for model in services.get() if model is not Account
             ],
                    key=lambda i: i.verbose_name_plural.lower()),
             'accounts':
             sorted([
                 model._meta
                 for model in accounts.get() if model is not Account
             ],
                    key=lambda i: i.verbose_name_plural.lower())
         })
     return super(AccountAdmin,
                  self).render_change_form(request, context, add, change,
                                           form_url, obj)
示例#2
0
 def render_change_form(self, request, context, add=False, change=False, form_url='', obj=None):
     if not add:
         if request.method == 'GET' and not obj.is_active:
             messages.warning(request, 'This account is disabled.')
         context.update({
             'services': sorted(
                 [model._meta for model in services.get() if model is not Account],
                 key=lambda i: i.verbose_name_plural.lower()
             ),
             'accounts': sorted(
                 [model._meta for model in accounts.get() if model is not Account],
                 key=lambda i: i.verbose_name_plural.lower()
             )
         })
     return super(AccountAdmin, self).render_change_form(
         request, context, add, change, form_url, obj)
示例#3
0
def get_accounts():
    childrens=[]
    if isinstalled('orchestra.contrib.payments'):
        url = reverse('admin:payments_transactionprocess_changelist')
        childrens.append(items.MenuItem(_("Transaction processes"), url))
    if isinstalled('orchestra.contrib.issues'):
        url = reverse('admin:issues_ticket_changelist')
        childrens.append(items.MenuItem(_("Tickets"), url))
    for model, options in accounts.get().items():
        if options.get('menu', True):
            opts = model._meta
            url = reverse('admin:{}_{}_changelist'.format(
                    opts.app_label, opts.model_name))
            name = capfirst(options.get('verbose_name_plural'))
            childrens.append(items.MenuItem(name, url))
    return sorted(childrens, key=lambda i: i.title)
示例#4
0
 def change_view(self, request, object_id, form_url='', extra_context=None):
     if request.method == 'GET':
         account = self.get_object(request, unquote(object_id))
         if not account.is_active:
             messages.warning(request, 'This account is disabled.')
     context = {
         'services': sorted(
             [model._meta for model in services.get() if model is not Account],
             key=lambda i: i.verbose_name_plural.lower()
         ),
         'accounts': sorted(
             [model._meta for model in accounts.get() if model is not Account],
             key=lambda i: i.verbose_name_plural.lower()
         )
     }
     context.update(extra_context or {})
     return super(AccountAdmin, self).change_view(request, object_id,
             form_url=form_url, extra_context=context)