def mark_same_as(self, request, queryset): """ Mark selected requests as same as the one we are choosing now. """ opts = self.model._meta # Check that the user has change permission for the actual model if not self.has_change_permission(request): raise PermissionDenied # User has already chosen the other req if request.POST.get('req_id'): try: req = self.model.objects.get( id=int(request.POST.get('req_id'))) except ( ValueError, self.model.DoesNotExist, ): raise PermissionDenied queryset.update(same_as=req) count_same_foirequests.delay(req.id) self.message_user(request, _("Successfully marked requests as identical.")) # Return None to display the change list page again. return None db = router.db_for_write(self.model) context = { 'opts': opts, 'queryset': queryset, 'media': self.media, 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, 'req_widget': mark_safe( admin.widgets.ForeignKeyRawIdWidget( self.model._meta.get_field('same_as').rel, self.admin_site, using=db).render('req_id', None, { 'id': 'id_req_id' }).replace('../../..', '../..')), 'applabel': opts.app_label } # Display the confirmation page return TemplateResponse(request, 'foirequest/admin_mark_same_as.html', context, current_app=self.admin_site.name)
def mark_same_as(self, request, queryset): """ Mark selected requests as same as the one we are choosing now. """ opts = self.model._meta # Check that the user has change permission for the actual model if not self.has_change_permission(request): raise PermissionDenied # User has already chosen the other req if request.POST.get('req_id'): try: req = self.model.objects.get(id=int(request.POST.get('req_id'))) except (ValueError, self.model.DoesNotExist,): raise PermissionDenied queryset.update(same_as=req) count_same_foirequests.delay(req.id) self.message_user(request, _("Successfully marked requests as identical.")) # Return None to display the change list page again. return None db = router.db_for_write(self.model) context = { 'opts': opts, 'queryset': queryset, 'media': self.media, 'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME, 'req_widget': mark_safe(admin.widgets.ForeignKeyRawIdWidget( self.model._meta.get_field( 'same_as').rel, self.admin_site, using=db).render( 'req_id', None, {'id': 'id_req_id'}) .replace('../../..', '../..')), 'applabel': opts.app_label } # Display the confirmation page return TemplateResponse(request, 'foirequest/admin_mark_same_as.html', context, current_app=self.admin_site.name)
def foirequest_add_same_as_count(instance=None, created=False, **kwargs): if created and kwargs.get('raw', False): return if instance.same_as: count_same_foirequests.delay(instance.same_as.id)