コード例 #1
0
ファイル: forms.py プロジェクト: divya-basant/django-gstudio
    def __init__(self, *args, **kwargs):
        super(AttributetypeAdminForm, self).__init__(*args, **kwargs)
        prior = ManyToManyRel(Nodetype, 'id')
        post = ManyToManyRel(Nodetype, 'id')

        self.fields['priornodes'].widget = RelatedFieldWidgetWrapper(
            self.fields['priornodes'].widget, prior, self.admin_site)
        self.fields['posteriornodes'].widget = RelatedFieldWidgetWrapper(
            self.fields['posteriornodes'].widget, post, self.admin_site)
コード例 #2
0
ファイル: forms.py プロジェクト: divya-basant/django-gstudio
    def __init__(self, *args, **kwargs):
        super(ObjecttypeAdminForm, self).__init__(*args, **kwargs)
        meta = ManyToManyRel(Metatype, 'id')
        prior = ManyToManyRel(Nodetype, 'id')
        post = ManyToManyRel(Nodetype, 'id')
        self.fields['metatypes'].widget = RelatedFieldWidgetWrapper(
            self.fields['metatypes'].widget, meta, self.admin_site)
        self.fields['priornodes'].widget = RelatedFieldWidgetWrapper(
            self.fields['priornodes'].widget, prior, self.admin_site)
        self.fields['posteriornodes'].widget = RelatedFieldWidgetWrapper(
            self.fields['posteriornodes'].widget, post, self.admin_site)

        self.fields['sites'].initial = [Site.objects.get_current()]
コード例 #3
0
ファイル: forms.py プロジェクト: divya-basant/django-gstudio
    def __init__(self, *args, **kwargs):
        super(ProcesstypeAdminForm, self).__init__(*args, **kwargs)
        prior = ManyToManyRel(Nodetype, 'id')
        post = ManyToManyRel(Nodetype, 'id')
        atype = ManyToManyRel(Attributetype, 'id')
        rtype = ManyToManyRel(Relationtype, 'id')

        self.fields['priornodes'].widget = RelatedFieldWidgetWrapper(
            self.fields['priornodes'].widget, prior, self.admin_site)
        self.fields['posteriornodes'].widget = RelatedFieldWidgetWrapper(
            self.fields['posteriornodes'].widget, post, self.admin_site)
        self.fields['attributetype_set'].widget = RelatedFieldWidgetWrapper(
            self.fields['attributetype_set'].widget, atype, self.admin_site)
        self.fields['relationtype_set'].widget = RelatedFieldWidgetWrapper(
            self.fields['relationtype_set'].widget, rtype, self.admin_site)
コード例 #4
0
    def __init__(self, *args, **kwargs):
        super(GbobjectAdminForm, self).__init__(*args, **kwargs)
        rel = ManyToManyRel(Objecttype, 'id')

        self.fields['objecttypes'].widget = RelatedFieldWidgetWrapper(
            self.fields['objecttypes'].widget, rel, self.admin_site)

        self.fields['sites'].initial = [Site.objects.get_current()]
コード例 #5
0
ファイル: forms.py プロジェクト: yaronsamuel/morsite
 def __init__(self, *args, **kwargs):
     super(EntryAdminForm, self).__init__(*args, **kwargs)
     rel = ManyToManyRel(Category, Entry, 'id')
     self.fields['categories'].widget = RelatedFieldWidgetWrapper(
         self.fields['categories'].widget, rel, self.admin_site)
     self.fields['sites'].initial = [Site.objects.get_current()]
コード例 #6
0
 def __init__(self, *args, **kwargs):
     super(EntryAdminForm, self).__init__(*args, **kwargs)
     rel = ManyToManyRel(Category, 'id')
     self.fields['categories'].widget = RelatedFieldWidgetWrapper(
         self.fields['categories'].widget, rel, self.admin_site)
コード例 #7
0
class ActionAdminAddForm(forms.ModelForm):
    attachments = AttachmentsField(
        required=False,
        upload_url_func=(
            lambda: reverse(u'admin:attachments_attachment_upload')),
        download_url_func=(lambda a: reverse(
            u'admin:attachments_attachment_download', args=(a.pk, ))),
    )
    obligee_set = forms.ModelMultipleChoiceField(
        queryset=Obligee.objects,
        required=False,
        help_text=
        u'May be empty for advancement actions. Must be empty for all other actions.',
        widget=admin.widgets.ManyToManyRawIdWidget(ManyToManyRel(Obligee),
                                                   admin.site),
    )
    send_email = forms.BooleanField(
        required=False,
        help_text=squeeze(u"""
                Check to send an e-mail with the created action to the obligee. Leave the checkbox
                empty if do not want to send any e-mail. Applicable for applicant actions only.
                """),
    )

    def __init__(self, *args, **kwargs):
        attached_to = kwargs.pop(u'attached_to')
        super(ActionAdminAddForm, self).__init__(*args, **kwargs)

        self.fields[u'attachments'].attached_to = attached_to

    def clean(self):
        cleaned_data = super(ActionAdminAddForm, self).clean()

        if u'send_email' in cleaned_data and u'type' in cleaned_data:
            if cleaned_data[u'send_email'] and cleaned_data[
                    u'type'] not in Action.APPLICANT_ACTION_TYPES:
                self.add_error(
                    u'send_email',
                    u'Ony applicant actions may be send by e-mail.')

        return cleaned_data

    def save(self, commit=True):
        assert self.is_valid()

        action = Action(
            branch=self.cleaned_data[u'branch'],
            type=self.cleaned_data[u'type'],
            subject=self.cleaned_data[u'subject'],
            content=self.cleaned_data[u'content'],
            effective_date=self.cleaned_data[u'effective_date'],
            deadline=self.cleaned_data[u'deadline'],
            extension=self.cleaned_data[u'extension'],
            disclosure_level=self.cleaned_data[u'disclosure_level'],
            refusal_reason=self.cleaned_data[u'refusal_reason'],
        )

        @after_saved(action)
        def deferred(action):
            action.attachment_set = self.cleaned_data[u'attachments']

            for obligee in self.cleaned_data[u'obligee_set']:
                sub_branch = Branch(
                    inforequest=action.branch.inforequest,
                    obligee=obligee,
                    advanced_by=action,
                )
                sub_branch.save()

                sub_action = Action(
                    branch=sub_branch,
                    type=Action.TYPES.ADVANCED_REQUEST,
                    effective_date=action.effective_date,
                )
                sub_action.save()

            if self.cleaned_data[u'send_email']:
                action.send_by_email()

        if commit:
            action.save()
        return action

    def save_m2m(self):
        pass
コード例 #8
0
class InforequestEmailAdminDecideForm(forms.Form):
    branch = Action._meta.get_field(u'branch').formfield(
        widget=ForeignKeyRawIdWidgetWithUrlParams(
            Action._meta.get_field(u'branch').rel, admin.site), )
    type = Action._meta.get_field(u'type').formfield(
        choices=[(u'', u'')] + [(c, l) for c, l in Action.TYPES._choices
                                if c in Action.OBLIGEE_ACTION_TYPES])
    subject = Action._meta.get_field(u'subject').formfield(
        widget=admin.widgets.AdminTextInputWidget(), )
    content = Action._meta.get_field(u'content').formfield(
        widget=admin.widgets.AdminTextareaWidget(), )
    attachments = AttachmentsField(
        required=False,
        upload_url_func=(
            lambda: reverse(u'admin:attachments_attachment_upload')),
        download_url_func=(lambda a: reverse(
            u'admin:attachments_attachment_download', args=(a.pk, ))),
    )
    effective_date = Action._meta.get_field(u'effective_date').formfield(
        widget=admin.widgets.AdminDateWidget(), )
    deadline = Action._meta.get_field(u'deadline').formfield(
        widget=admin.widgets.AdminIntegerFieldWidget(), )
    extension = Action._meta.get_field(u'extension').formfield(
        widget=admin.widgets.AdminIntegerFieldWidget(), )
    disclosure_level = Action._meta.get_field(u'disclosure_level').formfield()
    refusal_reason = Action._meta.get_field(u'refusal_reason').formfield()
    obligee_set = forms.ModelMultipleChoiceField(
        queryset=Obligee.objects,
        required=False,
        help_text=
        u'May be empty for advancement actions. Must be empty for all other actions.',
        widget=admin.widgets.ManyToManyRawIdWidget(ManyToManyRel(Obligee),
                                                   admin.site),
    )

    class _meta:
        model = InforequestEmail
        labels = None
        help_texts = None

    def __init__(self, *args, **kwargs):
        self.instance = kwargs.pop(u'instance')
        attached_to = kwargs.pop(u'attached_to')
        super(InforequestEmailAdminDecideForm, self).__init__(*args, **kwargs)
        self.fields[u'branch'].queryset = Branch.objects.filter(
            inforequest=self.instance.inforequest).order_by_pk()
        self.fields[u'branch'].widget.url_params = dict(
            inforequest=self.instance.inforequest)
        self.fields[u'subject'].initial = self.instance.email.subject
        self.fields[u'content'].initial = self.instance.email.text
        self.fields[
            u'attachments'].initial = self.instance.email.attachment_set.order_by_pk(
            )
        self.fields[u'attachments'].attached_to = [
            self.instance.email, attached_to
        ]
        self.fields[u'effective_date'].initial = local_date(
            self.instance.email.processed)

    def save(self, commit=True):
        assert self.is_valid()

        action = Action(
            branch=self.cleaned_data[u'branch'],
            email=self.instance.email,
            type=self.cleaned_data[u'type'],
            subject=self.cleaned_data[u'subject'],
            content=self.cleaned_data[u'content'],
            effective_date=self.cleaned_data[u'effective_date'],
            deadline=self.cleaned_data[u'deadline'],
            extension=self.cleaned_data[u'extension'],
            disclosure_level=self.cleaned_data[u'disclosure_level'],
            refusal_reason=self.cleaned_data[u'refusal_reason'],
        )

        @after_saved(action)
        def deferred(action):
            session_type = ContentType.objects.get_for_model(Session)
            for attachment in self.cleaned_data[u'attachments']:
                # We don't want to steal attachments owned by the email, so we clone them.
                if attachment.generic_type_id != session_type.pk:
                    attachment = attachment.clone(action)
                else:
                    attachment.generic_object = action
                attachment.save()

            for obligee in self.cleaned_data[u'obligee_set']:
                sub_branch = Branch(
                    inforequest=action.branch.inforequest,
                    obligee=obligee,
                    advanced_by=action,
                )
                sub_branch.save()

                sub_action = Action(
                    branch=sub_branch,
                    type=Action.TYPES.ADVANCED_REQUEST,
                    effective_date=action.effective_date,
                )
                sub_action.save()

        if commit:
            action.save()
        return action