Пример #1
0
    def __init__(self, *args, **kwargs):
        super(UpdateEmailingForm, self).__init__(*args, **kwargs)

        subscription_choices = [
            (subs_type.id, subs_type.name)
            for subs_type in SubscriptionType.objects.all()
        ]
        self.fields["subscription_type"].widget = forms.Select(
            choices=subscription_choices)

        newsletter_choices = [(newsletter.id, newsletter.subject)
                              for newsletter in Newsletter.objects.all()]
        self.fields["newsletter"].widget = forms.Select(
            choices=newsletter_choices, attrs={'class': 'form-control'})

        if not getattr(settings, 'BALAFON_EMAILING_SENDER_CHOICES', None):
            self.fields["from_email"].widget = forms.HiddenInput()
        else:
            self.fields["from_email"].widget = forms.Select(
                choices=settings.BALAFON_EMAILING_SENDER_CHOICES)

        if not getattr(settings, 'LANGUAGES',
                       None) or len(settings.LANGUAGES) < 2:
            self.fields["lang"].widget = forms.HiddenInput()
        else:
            language_choices = crm_settings.get_language_choices(
                _("Favorite language of the contact"))
            self.fields["lang"].widget = forms.Select(
                choices=language_choices, attrs={'class': 'form-control'})
Пример #2
0
 def __init__(self, *args, **kwargs):
     super(ContactLanguageSearchForm, self).__init__(*args, **kwargs)
     field = forms.ChoiceField(
         label=self.label,
         choices=get_language_choices()
     )
     self._add_field(field)
     field.required = False
Пример #3
0
 def save(self, *args, **kwargs):
     """save"""
     if self.lang and self.lang not in [
             value for (value, label) in get_language_choices()
     ]:
         self.lang = ''
     if self.status == Emailing.STATUS_SENT and self.sending_dt is None:
         self.sending_dt = datetime.now()
     return super(Emailing, self).save(*args, **kwargs)
Пример #4
0
    def __init__(self, *args, **kwargs):
        super(UpdateEmailingForm, self).__init__(*args, **kwargs)

        subscription_choices = [(subs_type.id, subs_type.name) for subs_type in SubscriptionType.objects.all()]
        self.fields["subscription_type"].widget = forms.Select(choices=subscription_choices)

        newsletter_choices = [(newsletter.id, newsletter.subject) for newsletter in Newsletter.objects.all()]
        self.fields["newsletter"].widget = forms.Select(choices=newsletter_choices)

        if not getattr(settings, 'BALAFON_EMAILING_SENDER_CHOICES', None):
            self.fields["from_email"].widget = forms.HiddenInput()
        else:
            self.fields["from_email"].widget = forms.Select(choices=settings.BALAFON_EMAILING_SENDER_CHOICES)

        if not getattr(settings, 'LANGUAGES', None) or len(settings.LANGUAGES) < 2:
            self.fields["lang"].widget = forms.HiddenInput()
        else:
            language_choices = crm_settings.get_language_choices(_(u"Favorite language of the contact"))
            self.fields["lang"].widget = forms.Select(choices=language_choices)
Пример #5
0
    def __init__(self, *args, **kwargs):
        initial = kwargs.get('initial')
        initial_contacts = ''
        if initial and 'contacts' in initial:
            initial_contacts = ';'.join(
                ['{0}'.format(contact.id) for contact in initial['contacts']])
            initial.pop('contacts')
        super(NewEmailingForm, self).__init__(*args, **kwargs)
        if initial_contacts:
            self.fields['contacts'].initial = initial_contacts

        newsletter_choices = [(0, ugettext('-- New --'))] + [
            (newsletter.id, newsletter.subject)
            for newsletter in Newsletter.objects.all().order_by('-id')
        ]
        self.fields["newsletter"].widget = forms.Select(
            choices=newsletter_choices, attrs={'class': 'form-control'})

        subscription_choices = [
            (subscription.id, subscription.name)
            for subscription in SubscriptionType.objects.all()
        ]
        self.fields["subscription_type"].widget = forms.Select(
            choices=subscription_choices, attrs={'class': 'form-control'})

        if not getattr(settings, 'LANGUAGES',
                       None) or len(settings.LANGUAGES) < 2:
            self.fields["lang"].widget = forms.HiddenInput()
        else:
            language_choices = crm_settings.get_language_choices(
                _("Favorite language of the contact"))
            self.fields["lang"].widget = forms.Select(
                choices=language_choices, attrs={'class': 'form-control'})

        if getattr(settings, 'BALAFON_EMAILING_SENDER_CHOICES', None):
            self.fields['from_email'].widget = forms.Select(
                choices=settings.BALAFON_EMAILING_SENDER_CHOICES,
                attrs={'class': 'form-control'})
        else:
            self.fields['from_email'].widget = forms.HiddenInput()
Пример #6
0
    def __init__(self, *args, **kwargs):
        # Configure the fieldset with dynamic fields
        fieldset_fields = self.Meta.fieldsets[-2][1]["fields"]
        for subscription_type in models.SubscriptionType.objects.all():
            field_name = "subscription_{0}".format(subscription_type.id)
            if field_name not in fieldset_fields:
                fieldset_fields.append(field_name)

        has_data = len(args) > 0
        super(ContactForm, self).__init__(*args, **kwargs)

        try:
            if self.instance and self.instance.entity and self.instance.entity.is_single_contact:
                self.fields['has_left'].widget = forms.HiddenInput()
        except models.Entity.DoesNotExist:
            pass

        self.fields["role"].help_text = _(
            "Select the roles played by the contact in his entity")

        if 'balafon.Profile' not in settings.INSTALLED_APPS:
            self.fields["accept_notifications"].widget = forms.HiddenInput()

        if has_data:
            self.fields.pop("email_verified")
        else:
            self.fields["email_verified"].widget.attrs['disabled'] = "disabled"

        # define the allowed gender
        gender_choices = [
            (models.Contact.GENDER_NOT_SET, '-------'),
            (models.Contact.GENDER_MALE, ugettext('Mr')),
            (models.Contact.GENDER_FEMALE, ugettext('Mrs')),
        ]
        if ALLOW_COUPLE_GENDER:
            gender_choices += [(models.Contact.GENDER_COUPLE,
                                ugettext('Mrs and Mr'))]
        self.fields['gender'].choices = gender_choices

        # create the dynamic fields
        for subscription_type in models.SubscriptionType.objects.all():
            field_name = "subscription_{0}".format(subscription_type.id)
            field = self.fields[field_name] = forms.BooleanField(
                label=subscription_type.name, required=False)
            if self.instance and self.instance.id:
                try:
                    subscription = models.Subscription.objects.get(
                        subscription_type=subscription_type,
                        contact=self.instance)
                    field.initial = subscription.accept_subscription
                except models.Subscription.DoesNotExist:
                    field.initial = False
            else:
                field.initial = get_subscription_default_value()

        if has_language_choices():
            self.fields['favorite_language'].widget = forms.Select(
                choices=get_language_choices(),
                attrs={'class': 'form-control'})
        else:
            self.fields['favorite_language'].widget = forms.HiddenInput()

        if not self.instance or not any([
                self.instance.lastname, self.instance.firstname,
                self.instance.email
        ]):
            # If the contact has not been created of not filled
            pass
            # keep the widget
            if len(args):
                # The form has been posted; we must initialize the list with allowed values
                contact_id = self.instance.id if self.instance else None
                post_data = args[0]
                lastname = post_data.get('lastname', '')
                firstname = post_data.get('firstname', '')
                email = post_data.get('email', '')
                same_as_contacts = get_suggested_same_as_contacts(
                    contact_id=contact_id,
                    lastname=lastname,
                    firstname=firstname,
                    email=email)
                self.fields['same_as_suggestions'].choices = [
                    (contact.id, '{0}'.format(contact))
                    for contact in same_as_contacts
                ]
        else:
            # hide the field
            self.fields['same_as_suggestions'].widget = forms.HiddenInput()
Пример #7
0
 def __init__(self, *args, **kwargs):
     super(custom_form_class, self).__init__(*args, **kwargs)
     self.fields['favorite_language'].widget = forms.Select(
         choices=get_language_choices())
Пример #8
0
    def __init__(self, *args, **kwargs):
        # Configure the fieldset with dynamic fields
        fieldset_fields = self.Meta.fieldsets[-2][1]["fields"]
        for subscription_type in models.SubscriptionType.objects.all():
            field_name = "subscription_{0}".format(subscription_type.id)
            if field_name not in fieldset_fields:
                fieldset_fields.append(field_name)

        super(ContactForm, self).__init__(*args, **kwargs)

        try:
            if self.instance and self.instance.entity and self.instance.entity.is_single_contact:
                self.fields['has_left'].widget = forms.HiddenInput()
        except models.Entity.DoesNotExist:
            pass

        self.fields["role"].help_text = _(u"Select the roles played by the contact in his entity")

        if 'balafon.Profile' not in settings.INSTALLED_APPS:
            self.fields["accept_notifications"].widget = forms.HiddenInput()

        self.fields["email_verified"].widget.attrs['disabled'] = "disabled"

        # define the allowed gender
        gender_choices = [
            (0, u'-------'),
            (models.Contact.GENDER_MALE, ugettext(u'Mr')),
            (models.Contact.GENDER_FEMALE, ugettext(u'Mrs')),
        ]
        if ALLOW_COUPLE_GENDER:
            gender_choices += [
                (models.Contact.GENDER_COUPLE, ugettext(u'Mrs and Mr'))
            ]
        self.fields['gender'].choices = gender_choices

        # create the dynamic fields
        for subscription_type in models.SubscriptionType.objects.all():
            field_name = "subscription_{0}".format(subscription_type.id)
            field = self.fields[field_name] = forms.BooleanField(
                label=subscription_type.name, required=False
            )
            if self.instance:
                try:
                    subscription = models.Subscription.objects.get(
                        subscription_type=subscription_type, contact=self.instance
                    )
                    field.initial = subscription.accept_subscription
                except models.Subscription.DoesNotExist:
                    field.initial = get_subscription_default_value()
            else:

                field.initial = get_subscription_default_value()

        if has_language_choices():
            self.fields['favorite_language'].widget = forms.Select(
                choices=get_language_choices(), attrs={'class': 'form-control'}
            )
        else:
            self.fields['favorite_language'].widget = forms.HiddenInput()

        if not self.instance or not any([self.instance.lastname, self.instance.firstname, self.instance.email]):
            # If the contact has not been created of not filled
            pass
            # keep the widget
            if len(args):
                # The form has been posted; we must initialize the list with allowed values
                contact_id = self.instance.id if self.instance else None
                post_data = args[0]
                lastname = post_data.get('lastname', '')
                firstname = post_data.get('firstname', '')
                email = post_data.get('email', '')
                same_as_contacts = get_suggested_same_as_contacts(
                    contact_id=contact_id, lastname=lastname, firstname=firstname, email=email
                )
                self.fields['same_as_suggestions'].choices = [
                    (contact.id, unicode(contact)) for contact in same_as_contacts
                ]
        else:
            # hide the field
            self.fields['same_as_suggestions'].widget = forms.HiddenInput()
Пример #9
0
 def __init__(self, *args, **kwargs):
     super(custom_form_class, self).__init__(*args, **kwargs)
     self.fields['lang'].widget = forms.Select(
         choices=crm_settings.get_language_choices())