Esempio n. 1
0
    def __init__(self, *args, **kwargs):
        partner = kwargs.pop('partner')
        super(ContactRecordForm, self).__init__(*args, **kwargs)

        instance = kwargs.get('instance')
        self.fields["contact"].queryset = Contact.objects.filter(
            partner=partner, archived_on__isnull=True)

        if not instance or instance.contact_type != 'pssemail':
            # Remove Partner Saved Search from the list of valid
            # contact type choices.
            contact_type_choices = self.fields["contact_type"].choices
            pssemail = ('pssemail', 'Partner Saved Search Email')
            if pssemail in contact_type_choices:
                contact_type_choices.remove(pssemail)
                self.fields["contact_type"].choices = contact_type_choices

        # If there are attachments create a checkbox option to delete them.
        if instance:
            attachments = PRMAttachment.objects.filter(contact_record=instance)
            if attachments:
                choices = [(a.pk, get_attachment_link(partner.id, a.id,
                            a.attachment.name.split("/")[-1]))
                           for a in attachments]
                self.fields["attach_delete"] = forms.MultipleChoiceField(
                    required=False, choices=choices, label="Delete Files",
                    widget=forms.CheckboxSelectMultiple)
        init_tags(self)

        # mark contact type specific fields as required
        for field in ['contact_email', 'contact_phone', 'location', 'job_id']:
            self.fields[field].label += " *"
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        partner = None
        if 'partner' in kwargs:
            partner = kwargs.pop('partner')
        super(ContactRecordForm, self).__init__(*args, **kwargs)
        self.fields['contact'].required = True
        if not hasattr(self.instance, 'contact'):
            self.fields['contact'].required = False

        instance = kwargs.get('instance')
        if partner:
            self.fields["contact"].queryset = Contact.objects.filter(
                partner=partner, archived_on__isnull=True)

        if not instance or instance.contact_type != 'pssemail':
            # Remove Partner Saved Search from the list of valid
            # contact type choices.
            contact_type_choices = self.fields["contact_type"].choices
            pssemail = ('pssemail', 'Partner Saved Search Email')
            if pssemail in contact_type_choices:
                contact_type_choices.remove(pssemail)
                self.fields["contact_type"].choices = contact_type_choices

        # If there are attachments create a checkbox option to delete them.
        if instance and partner:
            attachments = PRMAttachment.objects.filter(contact_record=instance)
            if attachments:
                choices = [
                    (a.pk,
                     get_attachment_link(partner.id, a.id,
                                         a.attachment.name.split("/")[-1]))
                    for a in attachments
                ]
                self.fields["attach_delete"] = forms.MultipleChoiceField(
                    required=False,
                    choices=choices,
                    label="Delete Files",
                    widget=forms.CheckboxSelectMultiple)
        init_tags(self)

        # mark contact type specific fields as required
        for field in ['contact_email', 'contact_phone', 'location', 'job_id']:
            self.fields[field].label += " *"
        autofocus_input(self, "notes" if self.instance.pk else "contact_type")
Esempio n. 3
0
def attachment_link(attachment, partner):
    name = attachment.attachment.name.split("/")[-1]
    return get_attachment_link(partner.id, attachment.id, name)
Esempio n. 4
0
def attachment_link(attachment, partner):
    name = attachment.attachment.name.split("/")[-1]
    return get_attachment_link(partner.id, attachment.id, name)