Esempio n. 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}')
Esempio n. 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)
Esempio n. 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
Esempio n. 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)
Esempio n. 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
    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)
    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,
            })
Esempio n. 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,
            })
Esempio n. 9
0
 def test_uncatched_exception(self):
     a = dict(moo=4)
     with self.assertRaises(KeyError):
         try_except(lambda: a[u'foo'], 7, ValueError)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 14
0
 def test_uncatched_exception(self):
     a = dict(moo=4)
     with self.assertRaises(KeyError):
         try_except(lambda: a[u'foo'], 7, ValueError)
Esempio n. 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
Esempio n. 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)
Esempio n. 17
0
 def test_catched_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7, KeyError)
     self.assertEqual(b, 7)
Esempio n. 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}')
Esempio n. 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
Esempio n. 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}')
Esempio n. 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}')
Esempio n. 22
0
 def test_without_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'moo'], 7, KeyError)
     self.assertEqual(b, 4)
Esempio n. 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)
Esempio n. 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)
Esempio n. 25
0
 def test_catched_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'foo'], 7, KeyError)
     self.assertEqual(b, 7)
Esempio n. 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)
Esempio n. 27
0
 def test_without_exception(self):
     a = dict(moo=4)
     b = try_except(lambda: a[u'moo'], 7, KeyError)
     self.assertEqual(b, 4)
Esempio n. 28
0
 def action_column(self, inforequestemail):
     action = try_except(lambda: inforequestemail.email.action, None)
     return admin_obj_format(action)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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}')
Esempio n. 32
0
 def action_field(self, message):
     action = try_except(lambda: message.action, None)
     return admin_obj_format(action)
Esempio n. 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)
Esempio n. 34
0
 def email_action_live(self, email):
     action = try_except(lambda: email.action, None)
     return admin_obj_format(action)
Esempio n. 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)
Esempio n. 36
0
 def email_action_live(self, email):
     action = try_except(lambda: email.action, None)
     return admin_obj_format(action)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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}')
Esempio n. 40
0
 def action_column(self, inforequestemail):
     action = try_except(lambda: inforequestemail.email.action, None)
     return admin_obj_format(action)