예제 #1
0
 def obligee_set_details_live(self, obligee_pks):
     obligee_pks = obligee_pks.split(u',') if obligee_pks else []
     obligees = [
         try_except(lambda: Obligee.objects.get(pk=pk), None)
         for pk in obligee_pks
     ]
     return admin_obj_format_join(u'\n', obligees, u'{tag} {obj.name}')
예제 #2
0
 def has_delete_permission(self, request, obj=None):
     if obj:
         # Only messages that are not a part of an action may be deleted.
         action = try_except(lambda: obj.action, None)
         if action is not None:
             return False
     return super(MessageAdminMixin, self).has_delete_permission(request, obj)
예제 #3
0
    def clean(self):
        cleaned_data = super(ActionAdminChangeForm, self).clean()

        if u'email' in cleaned_data:
            if cleaned_data[u'email']:
                action = try_except(lambda: cleaned_data[u'email'].action, None, Action.DoesNotExist)
                if action is not None and action.pk != self.instance.pk:
                    self.add_error(u'email', u'This e-mail is already used with another action.')

        return cleaned_data
예제 #4
0
    def render_change_form(self, request, context, **kwargs):
        inforequestemail = kwargs.get(u'obj', None)

        # Decide button
        if inforequestemail and inforequestemail.type == InforequestEmail.TYPES.UNDECIDED:
            message = inforequestemail.email
            action = try_except(lambda: message.action, None)
            if message.type == Message.TYPES.INBOUND and message.processed and action is None:
                context[u'decide_url'] = reverse(u'admin:inforequests_inforequestemail_decide', args=[inforequestemail.pk])

        return super(InforequestEmailAdmin, self).render_change_form(request, context, **kwargs)
예제 #5
0
    def clean(self):
        cleaned_data = super(ActionAdminChangeForm, self).clean()

        if u'email' in cleaned_data:
            if cleaned_data[u'email']:
                action = try_except(lambda: cleaned_data[u'email'].action,
                                    None, Action.DoesNotExist)
                if action is not None and action.pk != self.instance.pk:
                    self.add_error(
                        u'email',
                        u'This e-mail is already used with another action.')

        return cleaned_data
예제 #6
0
    def render_change_form(self, request, context, **kwargs):
        inforequestemail = kwargs.get(u'obj', None)

        # Decide button
        if inforequestemail and inforequestemail.type == InforequestEmail.TYPES.UNDECIDED:
            message = inforequestemail.email
            action = try_except(lambda: message.action, None)
            if message.type == Message.TYPES.INBOUND and message.processed and action is None:
                context[u'decide_url'] = reverse(
                    u'admin:inforequests_inforequestemail_decide',
                    args=[inforequestemail.pk])

        return super(InforequestEmailAdmin,
                     self).render_change_form(request, context, **kwargs)
예제 #7
0
    def decide_view(self, request, inforequestemail_pk):
        inforequestemail = self.get_object(request, inforequestemail_pk)
        message = inforequestemail.email if inforequestemail else None
        action = try_except(lambda: message.action, None)

        if (inforequestemail is None
                or inforequestemail.type != InforequestEmail.TYPES.UNDECIDED
                or message.type != Message.TYPES.INBOUND
                or not message.processed or action is not None):
            return HttpResponseNotFound()

        session = Session.objects.get(session_key=request.session.session_key)
        if request.method == u'POST':
            form = InforequestEmailAdminDecideForm(request.POST,
                                                   instance=inforequestemail,
                                                   attached_to=session)
            if form.is_valid():
                new_action = form.save(commit=False)
                new_action.save()
                inforequestemail.type = InforequestEmail.TYPES.OBLIGEE_ACTION
                inforequestemail.save(update_fields=[u'type'])
                info = new_action._meta.app_label, new_action._meta.model_name
                return HttpResponseRedirect(
                    reverse(u'admin:%s_%s_change' % info,
                            args=[new_action.pk]))
        else:
            form = InforequestEmailAdminDecideForm(instance=inforequestemail,
                                                   attached_to=session)

        opts = self.model._meta
        template = u'admin/%s/%s/decide_form.html' % (opts.app_label,
                                                      opts.model_name)
        adminForm = admin.helpers.AdminForm(
            form,
            fieldsets=self.fieldsets_decide,
            prepopulated_fields={},
            readonly_fields=self.readonly_fields,
            model_admin=self,
        )

        return render(
            request, template, {
                u'object': inforequestemail,
                u'title': 'Decide %s' % force_text(opts.verbose_name),
                u'opts': opts,
                u'adminform': adminForm,
                u'media': self.media + adminForm.media,
            })
예제 #8
0
    def decide_view(self, request, inforequestemail_pk):
        inforequestemail = self.get_object(request, inforequestemail_pk)
        message = inforequestemail.email if inforequestemail else None
        action = try_except(lambda: message.action, None)

        if (inforequestemail is None or inforequestemail.type != InforequestEmail.TYPES.UNDECIDED or
                message.type != Message.TYPES.INBOUND or not message.processed or action is not None):
            return HttpResponseNotFound()

        session = Session.objects.get(session_key=request.session.session_key)
        if request.method == u'POST':
            form = InforequestEmailAdminDecideForm(request.POST, instance=inforequestemail, attached_to=session)
            if form.is_valid():
                new_action = form.save(commit=False)
                new_action.save()
                inforequestemail.type = InforequestEmail.TYPES.OBLIGEE_ACTION
                inforequestemail.save(update_fields=[u'type'])
                info = new_action._meta.app_label, new_action._meta.model_name
                return HttpResponseRedirect(reverse(u'admin:%s_%s_change' % info, args=[new_action.pk]))
        else:
            form = InforequestEmailAdminDecideForm(instance=inforequestemail, attached_to=session)

        opts = self.model._meta
        template = u'admin/%s/%s/decide_form.html' % (opts.app_label, opts.model_name)
        adminForm = admin.helpers.AdminForm(form,
                fieldsets=self.fieldsets_decide,
                prepopulated_fields={},
                readonly_fields=self.readonly_fields,
                model_admin=self,
                )

        return render(request, template, {
            u'object': inforequestemail,
            u'title': 'Decide %s' % force_text(opts.verbose_name),
            u'opts': opts,
            u'adminform': adminForm,
            u'media': self.media + adminForm.media,
            })
예제 #9
0
 def test_uncatched_exception(self):
     a = dict(moo=4)
     with self.assertRaises(KeyError):
         try_except(lambda: a[u'foo'], 7, ValueError)
예제 #10
0
 def branch_details_live(self, branch_pk):
     branch = try_except(lambda: Branch.objects.get(pk=branch_pk), None)
     return admin_obj_format(branch)
예제 #11
0
 def branch_inforequest_live(self, branch_pk):
     branch = try_except(lambda: Branch.objects.get(pk=branch_pk), None)
     inforequest = branch.inforequest if branch else None
     return admin_obj_format(inforequest)
예제 #12
0
 def test_with_callable_failture(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], lambda: a[u'moo'])
     self.assertEqual(b, 4)
예제 #13
0
 def test_with_multiple_exception_classes(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7, ValueError, KeyError, IndexError)
     self.assertEqual(b, 7)
예제 #14
0
 def test_uncatched_exception(self):
     a = dict(moo=4)
     with self.assertRaises(KeyError):
         try_except(lambda: a[u'foo'], 7, ValueError)
예제 #15
0
 def has_delete_permission(self, request, obj=None):
     if not obj:
         return True
     # Only messages that are not a part of an action may be unassigned.
     action = try_except(lambda: obj.email.action, None)
     return action is None
예제 #16
0
 def email_action_field(self, inforequestemail):
     email = inforequestemail.email if inforequestemail else None
     action = try_except(lambda: email.action, None)
     return admin_obj_format(action)
예제 #17
0
 def test_catched_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7, KeyError)
     self.assertEqual(b, 7)
예제 #18
0
 def obligee_details_live(self, obligee_pk):
     obligee = try_except(lambda: Obligee.objects.get(pk=obligee_pk), None)
     return admin_obj_format(obligee, u'{tag}\n{obj.name}')
예제 #19
0
 def has_delete_permission(self, request, obj=None):
     if not obj:
         return True
     # Only messages that are not a part of an action may be unassigned.
     action = try_except(lambda: obj.email.action, None)
     return action is None
예제 #20
0
 def branch_obligee_live(self, branch_pk):
     branch = try_except(lambda: Branch.objects.get(pk=branch_pk), None)
     obligee = branch.obligee if branch else None
     return admin_obj_format(obligee, u'{tag}\n{obj.name}')
예제 #21
0
 def branch_obligee_live(self, branch_pk):
     branch = try_except(lambda: Branch.objects.get(pk=branch_pk), None)
     obligee = branch.obligee if branch else None
     return admin_obj_format(obligee, u'{tag}\n{obj.name}')
예제 #22
0
 def test_without_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'moo'], 7, KeyError)
     self.assertEqual(b, 4)
예제 #23
0
 def test_with_multiple_exception_classes(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7, ValueError, KeyError, IndexError)
     self.assertEqual(b, 7)
예제 #24
0
 def test_with_no_exception_classes(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7)
     self.assertEqual(b, 7)
예제 #25
0
 def test_catched_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7, KeyError)
     self.assertEqual(b, 7)
예제 #26
0
 def test_with_callable_failture(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], lambda: a[u'moo'])
     self.assertEqual(b, 4)
예제 #27
0
 def test_without_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'moo'], 7, KeyError)
     self.assertEqual(b, 4)
예제 #28
0
 def action_column(self, inforequestemail):
     action = try_except(lambda: inforequestemail.email.action, None)
     return admin_obj_format(action)
예제 #29
0
 def test_with_no_exception_classes(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7)
     self.assertEqual(b, 7)
예제 #30
0
 def generic_object_live(self, generic_type, generic_id):
     generic = try_except(
         lambda: generic_type.get_object_for_this_type(pk=generic_id), None)
     return admin_obj_format(generic)
예제 #31
0
 def obligee_details_live(self, obligee_pk):
     obligee = try_except(lambda: Obligee.objects.get(pk=obligee_pk), None)
     return admin_obj_format(obligee, u'{tag}\n{obj.name}')
예제 #32
0
 def action_field(self, message):
     action = try_except(lambda: message.action, None)
     return admin_obj_format(action)
예제 #33
0
 def email_action_field(self, inforequestemail):
     email = inforequestemail.email if inforequestemail else None
     action = try_except(lambda: email.action, None)
     return admin_obj_format(action)
예제 #34
0
 def email_action_live(self, email):
     action = try_except(lambda: email.action, None)
     return admin_obj_format(action)
예제 #35
0
 def generic_object_live(self, generic_type, generic_id):
     generic = try_except(lambda: generic_type.get_object_for_this_type(pk=generic_id), None)
     return admin_obj_format(generic)
예제 #36
0
 def email_action_live(self, email):
     action = try_except(lambda: email.action, None)
     return admin_obj_format(action)
예제 #37
0
 def branch_details_live(self, branch_pk):
     branch = try_except(lambda: Branch.objects.get(pk=branch_pk), None)
     return admin_obj_format(branch)
예제 #38
0
 def branch_inforequest_live(self, branch_pk):
     branch = try_except(lambda: Branch.objects.get(pk=branch_pk), None)
     inforequest = branch.inforequest if branch else None
     return admin_obj_format(inforequest)
예제 #39
0
 def obligee_set_details_live(self, obligee_pks):
     obligee_pks = obligee_pks.split(u',') if obligee_pks else []
     obligees = [try_except(lambda: Obligee.objects.get(pk=pk), None) for pk in obligee_pks]
     return admin_obj_format_join(u'\n', obligees, u'{tag} {obj.name}')
예제 #40
0
 def action_column(self, inforequestemail):
     action = try_except(lambda: inforequestemail.email.action, None)
     return admin_obj_format(action)