コード例 #1
0
ファイル: admin.py プロジェクト: jccode/partsms
 def get_actions(self, request):
     # if statusUrl.get_url_status(request) != Status.DRAFT:
     #     return None
     actions = super(PartsRecycleAdmin, self).get_actions(request)
     # print actions
     if statusUrl.get_url_status(request) != Status.DRAFT:
         actions.pop('delete_selected', None)
     if statusUrl.get_url_status(request) != statusUrl.STATUS_QUERY:
         actions.pop('export_admin_action', None)
     print actions
     print self.action_form
     return actions
コード例 #2
0
ファイル: admin.py プロジェクト: jccode/partsms
    def response_add(self, request, obj, post_url_continue=None):
        """
        Override response_add. for 'continue' button when add a new object
        """
        if post_url_continue == None:
            status = statusUrl.get_url_status(request)
            url_suffix = statusUrl.get_url_suffix_by_status(status) if status != -1 else None
            opts = obj._meta
            pk_value = obj._get_pk_val()

            url_name = 'admin:%s_%s_change' % (opts.app_label, opts.model_name) \
                       if status == -1 else \
                          'admin:%s_%s_change_%s' % (opts.app_label, opts.model_name, url_suffix)
            # if status == -1:
            #     post_url_continue = reverse('admin:%s_%s_change' %
            #                                 (opts.app_label, opts.model_name),
            #                                 args=(pk_value,),
            #                                 current_app=self.admin_site.name)
            # else:
            #     url_suffix = statusUrl.get_url_suffix_by_status(status)
            #     post_url_continue = reverse('admin:%s_%s_change_%s' %
            #                                 (opts.app_label, opts.model_name, url_suffix),
            #                                 args=(pk_value,),
            #                                 current_app=self.admin_site.name)
            post_url_continue = reverse(url_name,
                                        args=(pk_value,),
                                        current_app=self.admin_site.name)            
        return super(PartsRecycleAdmin, self).response_add(request, obj, post_url_continue)
コード例 #3
0
ファイル: admin.py プロジェクト: jccode/partsms
 def get_queryset(self, request):
     qs = super(PartsRecycleAdmin, self).get_queryset(request)
     status = statusUrl.get_url_status(request)
     if(status != -1 and status != statusUrl.STATUS_QUERY):
         return qs.filter(state = status)
     else:
         return qs
コード例 #4
0
ファイル: admin.py プロジェクト: jccode/partsms
 def get_readonly_fields(self, request, obj=None):
     url_status = statusUrl.get_url_status(request)
     if url_status == statusUrl.STATUS_QUERY:
         status = statusUrl.STATUS_QUERY
     elif obj:
         status = obj.state
     else:
         status = Status.DRAFT
     readonly_fields = reduce(operator.add, [ v['fields'] for v in self._fields if v['status'] < status ], ())
     return readonly_fields
コード例 #5
0
ファイル: admin.py プロジェクト: jccode/partsms
 def get_redirect_url(self, request, obj):
     """
     adjust redirect when fsm_admin button clicked
     """
     opts = self.model._meta
     status = statusUrl.get_url_status(request)
     if self.has_change_permission(request, None):
         if status == -1:
             post_url = reverse('admin:%s_%s_changelist' %
                                (opts.app_label, opts.model_name, ),
                                current_app=self.admin_site.name)
         else:
             url_suffix = statusUrl.get_url_suffix_by_status(status)
             post_url = reverse('admin:%s_%s_changelist_%s' %
                                (opts.app_label, opts.model_name, url_suffix),
                                current_app=self.admin_site.name)
         preserved_filters = self.get_preserved_filters(request)
         post_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, post_url)
     else:
         post_url = reverse('admin:index',
                            current_app=self.admin_site.name)
     return post_url
コード例 #6
0
ファイル: admin.py プロジェクト: jccode/partsms
    def response_change(self, request, obj):
        """
        Override FSMTransitionMixin response_change() function. 
        To handle '_saveasnew' & '_addanother' button redirection
        """
        opts = self.model._meta
        pk_value = obj._get_pk_val()
        preserved_filters = self.get_preserved_filters(request)
        msg_dict = {'name': force_text(opts.verbose_name), 'obj': force_text(obj)}

        status = statusUrl.get_url_status(request)
        url_suffix = statusUrl.get_url_suffix_by_status(status) if status != -1 else None
        
        if '_partsrecycle_saveasnew' in request.POST:
            msg = _('The %(name)s "%(obj)s" was added successfully. You may edit it again below.') % msg_dict
            self.message_user(request, msg, messages.SUCCESS)
            url_name = 'admin:%s_%s_change' % (opts.app_label, opts.model_name) \
                       if status == -1 else \
                          'admin:%s_%s_change_%s' % (opts.app_label, opts.model_name, url_suffix)
            redirect_url = reverse(url_name,
                                   args=(pk_value,),
                                   current_app=self.admin_site.name)
            redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url)
            return HttpResponseRedirect(redirect_url)
            
        elif '_partsrecycle_addanother' in request.POST:
            msg = _('The %(name)s "%(obj)s" was changed successfully. You may add another %(name)s below.') % msg_dict
            self.message_user(request, msg, messages.SUCCESS)
            url_name = 'admin:%s_%s_add' % (opts.app_label, opts.model_name) \
                       if status == -1 else \
                          'admin:%s_%s_add_%s' % (opts.app_label, opts.model_name, url_suffix)
            redirect_url = reverse(url_name,
                                   current_app=self.admin_site.name)
            redirect_url = add_preserved_filters({'preserved_filters': preserved_filters, 'opts': opts}, redirect_url)
            return HttpResponseRedirect(redirect_url)
            
        else:
            return super(PartsRecycleAdmin, self).response_change(request, obj)
コード例 #7
0
ファイル: admin.py プロジェクト: jccode/partsms
 def __init__(self, request, *args):
     self.url_status = statusUrl.get_url_status(request)
     super(PartsRecycleChangeList, self).__init__(request, *args)
コード例 #8
0
ファイル: admin.py プロジェクト: jccode/partsms
 def _populate_status_to_extra_context(self, request, extra_context=None):
     if extra_context == None:
         extra_context = {}
     extra_context['status'] = statusUrl.get_url_status(request)
     extra_context['STATUS'] = Status
     return extra_context
コード例 #9
0
ファイル: admin.py プロジェクト: jccode/partsms
 def get_list_display(self, request):
     fields = ('request_no', 'parts', 'pn', 'sn', 'tool', 'stn', 'employee', 'shift',
                 'return_date', 'state')
     if statusUrl.get_url_status(request) == statusUrl.STATUS_QUERY:
         return fields + ('status_after_repaired',)
     return fields
コード例 #10
0
ファイル: admin.py プロジェクト: jccode/partsms
 def get_search_fields(self, request):
     if statusUrl.get_url_status(request) == statusUrl.STATUS_QUERY:
         return ['request_no__request_no', ]
     return None
コード例 #11
0
ファイル: admin.py プロジェクト: jccode/partsms
 def get_list_filter(self, request):
     if statusUrl.get_url_status(request) == statusUrl.STATUS_QUERY:
         return ('state', 'return_date', )
     return None