コード例 #1
0
ファイル: forms.py プロジェクト: praveenscience/hasjob
class CampaignForm(forms.Form):
    title = forms.StringField(
        __("Title"),
        description=__("A reference name for looking up this campaign again"),
        validators=[
            forms.validators.DataRequired(__("A title is required")),
            forms.validators.StripWhitespace()
        ])
    start_at = forms.DateTimeField(__("Start at"),
                                   timezone=lambda: g.user.timezone
                                   if g.user else None)
    end_at = forms.DateTimeField(__("End at"),
                                 timezone=lambda: g.user.timezone
                                 if g.user else None)
    public = forms.BooleanField(__("This campaign is live"))
    position = forms.RadioField(__("Display position"),
                                choices=CAMPAIGN_POSITION.items(),
                                coerce=int)
    priority = forms.IntegerField(
        __("Priority"),
        default=0,
        description=__(
            "A larger number is higher priority when multiple campaigns are running on the "
            "same dates. 0 implies lowest priority"))
    boards = QuerySelectMultipleField(
        __("Boards"),
        widget=ListWidget(),
        option_widget=CheckboxInput(),
        query_factory=lambda: Board.query.order_by('title'),
        get_label='title',
        validators=[forms.validators.Optional()],
        description=__(u"Select the boards this campaign is active on"))
    geonameids = forms.GeonameSelectMultiField(
        "Locations",
        description=__(
            "This campaign will be targetted at users and jobs with matching locations"
        ))
    user_required = forms.RadioField(__("User is required"),
                                     coerce=getbool,
                                     choices=[(None, __("N/A")),
                                              (True, __("Yes")),
                                              (False, __("No"))])
    flags = forms.RadioMatrixField(
        "Flags",
        coerce=getbool,
        fields=Campaign.flag_choices,
        description=__(
            "All selected flags must match the logged in user for the campaign to be shown"
        ),
        choices=[('None', __("N/A")), ('True', __("True")),
                 ('False', __("False"))])
    content = forms.FormField(CampaignContentForm, __("Campaign content"))

    def validate_geonameids(self, field):
        field.data = [int(x) for x in field.data if x.isdigit()]

    def validate_end_at(self, field):
        if field.data <= self.start_at.data:
            raise forms.ValidationError(
                __(u"The campaign can’t end before it starts"))
コード例 #2
0
ファイル: campaign.py プロジェクト: saurabh17a/hasjob
class CampaignForm(forms.Form):
    title = forms.StringField(
        __("Title"),
        description=__("A reference name for looking up this campaign again"),
        validators=[forms.validators.DataRequired(__("A title is required"))],
        filters=[forms.filters.strip()],
    )
    start_at = forms.DateTimeField(__("Start at"), naive=False)
    end_at = forms.DateTimeField(
        __("End at"),
        validators=[
            forms.validators.GreaterThan(
                'start_at', __("The campaign can’t end before it starts")
            )
        ],
        naive=False,
    )
    public = forms.BooleanField(__("This campaign is live"))
    position = forms.RadioField(
        __("Display position"), choices=list(CAMPAIGN_POSITION.items()), coerce=int
    )
    priority = forms.IntegerField(
        __("Priority"),
        default=0,
        description=__(
            "A larger number is higher priority when multiple campaigns are running on the "
            "same dates. 0 implies lowest priority"
        ),
    )
    boards = QuerySelectMultipleField(
        __("Boards"),
        widget=ListWidget(),
        option_widget=CheckboxInput(),
        query_factory=lambda: Board.query.order_by(Board.featured.desc(), Board.title),
        get_label='title_and_name',
        validators=[forms.validators.Optional()],
        description=__("Select the boards this campaign is active on"),
    )
    geonameids = forms.GeonameSelectMultiField(
        "Locations",
        description=__(
            "This campaign will be targetted at users and jobs with matching locations"
        ),
    )
    user_required = forms.RadioField(
        __("User is required"),
        coerce=getbool,
        choices=[
            (None, __("N/A – Don’t target by login status")),
            (True, __("Yes – Show to logged in users only")),
            (False, __("No – Show to anonymous users only")),
        ],
    )
    flags = forms.RadioMatrixField(
        "Flags",
        coerce=getbool,
        fields=Campaign.flag_choices,
        description=__(
            "All selected flags must match the logged in user for the campaign to be shown"
        ),
        choices=[('None', __("N/A")), ('True', __("True")), ('False', __("False"))],
    )
    content = forms.FormField(CampaignContentForm, __("Campaign content"))

    def validate_geonameids(self, field):
        field.data = [int(x) for x in field.data if x.isdigit()]