Ejemplo n.º 1
0
class DiscountCouponForm(forms.Form):
    count = forms.IntegerField(__("Number of coupons to be generated"),
                               default=1)
    usage_limit = forms.IntegerField(
        __("Number of times each coupon can be used"), default=1)
    code = forms.StringField(
        __("Discount coupon code"),
        validators=[
            forms.validators.Optional(),
            forms.validators.Length(max=100),
            validate_unique_discount_coupon_code
        ],
        filters=[forms.filters.strip(),
                 forms.filters.none_if_empty()])
Ejemplo n.º 2
0
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"))
Ejemplo n.º 3
0
class CategoryForm(forms.Form):
    title = forms.StringField(__("Category title"),
        validators=[forms.validators.DataRequired(__("Please specify a title")),
            forms.validators.Length(max=250)], filters=[forms.filters.strip()])
    seq = forms.IntegerField(__("Sequence"),
        description=__("The sequence of the category on the listing"),
        validators=[forms.validators.DataRequired(__("Please specify the sequence order")), available_seq])
Ejemplo n.º 4
0
 class Form(forms.Form):
     other = forms.IntegerField("Other")
     field = forms.StringField("Field",
                               validators=[
                                   forms.validators.RequiredIf('other'),
                                   forms.validators.Optional()
                               ])
Ejemplo n.º 5
0
class LineItemForm(forms.Form):
    quantity = forms.IntegerField(
        __("Quantity"), validators=[forms.validators.DataRequired()]
    )
    item_id = forms.StringField(
        __("Item Id"), validators=[forms.validators.DataRequired()]
    )

    @classmethod
    def process_list(cls, line_items_json):
        """
        Return a list of LineItemForm objects.

        Returns an empty array if validation fails on any object.
        """
        line_item_forms = []

        for line_item_dict in line_items_json:
            # Since some requests are cross-domain, other checks
            # have been introduced to ensure against CSRF, such as
            # a white-list of allowed origins and XHR only requests
            line_item_form = cls.from_json(line_item_dict, meta={'csrf': False})
            if not line_item_form.validate():
                return []
            line_item_forms.append(line_item_form)
        return line_item_forms
Ejemplo n.º 6
0
class DiscountPriceForm(forms.Form):
    title = forms.StringField(
        __("Discount price title"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a title for the discount price")),
            forms.validators.Length(max=250),
        ],
        filters=[forms.filters.strip()],
    )
    amount = forms.IntegerField(
        __("Amount"),
        validators=[
            forms.validators.DataRequired(__("Please specify an amount"))
        ],
    )
    currency = forms.RadioField(
        __("Currency"),
        validators=[
            forms.validators.DataRequired(__("Please select the currency"))
        ],
        choices=list(CURRENCY.items()),
        default=CURRENCY.INR,
    )
    start_at = forms.DateTimeField(
        __("Price start date"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a start date and time"))
        ],
        naive=False,
    )
    end_at = forms.DateTimeField(
        __("Price end date"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify an end date and time")),
            forms.validators.GreaterThan(
                'start_at',
                __("Please specify an end date for the price that is greater than the start date"
                   ),
            ),
        ],
        naive=False,
    )
    item = forms.QuerySelectField(
        __("Item"),
        get_label='title',
        validators=[
            forms.validators.DataRequired(
                __("Please select a item for which the discount is to be applied"
                   ))
        ],
    )

    def set_queries(self):
        self.item.query = (Item.query.join(ItemCollection).filter(
            ItemCollection.organization ==
            self.edit_parent.organization).options(db.load_only('id',
                                                                'title')))
Ejemplo n.º 7
0
class ItemForm(forms.Form):
    title = forms.StringField(__("Item title"),
        validators=[forms.validators.DataRequired(__("Please specify a title")),
            forms.validators.Length(max=250)], filters=[forms.filters.strip()])
    description = forms.TextAreaField(__("Description"), filters=[format_description],
        validators=[forms.validators.DataRequired(__("Please specify a description"))])
    restricted_entry = forms.BooleanField(__("Restrict entry?"))
    seq = forms.IntegerField(__("Sequence"),
        description=__("The sequence of the ticket on the listing"),
        validators=[forms.validators.DataRequired(__("Please specify the sequence order"))])
    category = QuerySelectField(__("Category"), get_label='title',
        validators=[forms.validators.DataRequired(__("Please select a category"))])
    quantity_total = forms.IntegerField(__("Quantity available"),
        validators=[forms.validators.DataRequired(__("Please specify the quantity available for sale"))])
    assignee_details = forms.TextAreaField(__("Assignee details"), filters=[format_json],
        validators=[validate_json], default=ASSIGNEE_DETAILS_PLACEHOLDER)
    event_date = forms.DateField(__("Event date"),
        description=__("The date on which this item will be invoiced"),
        validators=[forms.validators.DataRequired(__("Please specify a date for the event"))])
    transferable_until = forms.DateTimeField(__("Transferable until"),
        validators=[forms.validators.Optional()],
        naive=False)
    cancellable_until = forms.DateTimeField(__("Cancellable until"),
        validators=[forms.validators.Optional()],
        naive=False)
    place_supply_state_code = forms.SelectField(__("State"),
        description=__("State of supply"), coerce=int, default=indian_states_dict['KA']['short_code'],
        validators=[forms.validators.DataRequired(__("Please select a state"))])
    place_supply_country_code = forms.SelectField(__("Country"),
        description=__("Country of supply"), default='IN',
        validators=[forms.validators.DataRequired(__("Please select a country"))])

    def set_queries(self):
        self.place_supply_state_code.choices = [(0, '')] + [(state['short_code'], state['name']) for state in sorted(indian_states, key=lambda k: k['name'])]
        self.place_supply_country_code.choices = [('', '')] + localized_country_list()
        self.category.query = Category.query.join(ItemCollection).filter(
            Category.item_collection == self.edit_parent).options(db.load_only('id', 'title'))

    def validate_place_supply_state_code(self, field):
        if field.data <= 0:
            # state short codes start from 1,
            # and 0 means empty value as mentioned above in set_queries
            raise forms.ValidationError(__("Please select a state"))

    def validate_transferable_until(self, field):
        if field.data and field.data.date() > self.event_date.data:
            raise forms.ValidationError(__("Ticket transfer deadline cannot be after event date"))
Ejemplo n.º 8
0
class CouponBasedDiscountPolicyForm(DiscountPolicyForm):
    items = forms.QuerySelectMultipleField(
        __("Items"),
        get_label='title',
        validators=[
            forms.validators.DataRequired(
                __("Please select at least one item for which the discount is applicable"
                   ))
        ],
    )
    percentage = forms.IntegerField(
        __("Percentage"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a discount percentage")),
            forms.validators.NumberRange(
                min=1,
                max=100,
                message=__("Percentage should be between >= 1 and <= 100"),
            ),
        ],
    )
    discount_code_base = forms.StringField(
        __("Discount title"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a discount code base")),
            forms.validators.Length(max=20),
            forms.AvailableAttr(
                'discount_code_base',
                message=
                'This discount code base is already in use. Please pick a different code base.',
            ),
        ],
        filters=[forms.filters.strip(),
                 forms.filters.none_if_empty()],
    )
    bulk_coupon_usage_limit = forms.IntegerField(__("Bulk coupon usage limit"),
                                                 default=1)

    def set_queries(self):
        self.items.query = (Item.query.join(ItemCollection).filter(
            ItemCollection.organization == self.edit_parent).options(
                db.load_only('id', 'title')))
Ejemplo n.º 9
0
class FiltersetForm(forms.Form):
    title = forms.StringField(__("Title"),
                              description=__("A title shown to viewers"),
                              validators=[forms.validators.DataRequired()],
                              filters=[forms.filters.strip()])
    description = forms.TinyMce4Field(
        __("Description"),
        content_css=content_css,
        description=__("Description shown to viewers and search engines"),
        validators=[forms.validators.DataRequired()])
    types = QuerySelectMultipleField(__("Job types"),
                                     widget=ListWidget(),
                                     option_widget=CheckboxInput(),
                                     get_label='title',
                                     validators=[forms.validators.Optional()])
    categories = QuerySelectMultipleField(
        __("Job categories"),
        widget=ListWidget(),
        option_widget=CheckboxInput(),
        get_label='title',
        validators=[forms.validators.Optional()])
    geonameids = forms.GeonameSelectMultiField("Locations",
                                               filters=[format_geonameids])
    remote_location = forms.BooleanField(__("Match remote jobs"))
    pay_cash_currency = forms.RadioField(
        __("Currency"),
        choices=get_currency_choices(),
        default='',
        validators=[forms.validators.Optional()])
    pay_cash = forms.IntegerField(__("Pay"),
                                  description=__("Minimum pay"),
                                  validators=[forms.validators.Optional()])
    keywords = forms.StringField(__("Keywords"),
                                 validators=[forms.validators.Optional()],
                                 filters=[forms.filters.strip()])
    auto_domains = forms.AutocompleteMultipleField(
        __("Domains"),
        autocomplete_endpoint='/api/1/domain/autocomplete',
        results_key='domains')
    auto_tags = forms.AutocompleteMultipleField(
        __("Tags"),
        autocomplete_endpoint='/api/1/tag/autocomplete',
        results_key='tags')

    def set_queries(self):
        if not self.edit_parent:
            self.edit_parent = g.board
        self.types.query = JobType.query.join(board_jobtype_table).filter(
            board_jobtype_table.c.board_id == self.edit_parent.id).order_by(
                'title')
        self.categories.query = JobCategory.query.join(
            board_jobcategory_table).filter(
                board_jobcategory_table.c.board_id ==
                self.edit_parent.id).order_by('title')
Ejemplo n.º 10
0
    class Form(forms.Form):
        """Test form."""

        other = forms.IntegerField("Other")
        field = forms.StringField(
            "Field",
            validators=[
                forms.validators.OptionalIf('other'),
                forms.validators.DataRequired(),
            ],
        )
Ejemplo n.º 11
0
class AutomaticDiscountPolicyForm(DiscountPolicyForm):
    item_quantity_min = forms.IntegerField(__("Minimum number of tickets"),
                                           default=1)
    percentage = forms.IntegerField(
        __("Percentage"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a discount percentage"))
        ])
    items = QuerySelectMultipleField(
        __("Items"),
        get_label='title',
        validators=[
            forms.validators.DataRequired(
                __("Please select at least one item for which the discount is applicable"
                   ))
        ])

    def set_queries(self):
        self.items.query = Item.query.join(ItemCollection).filter(
            ItemCollection.organization == self.edit_parent).options(
                db.load_only('id', 'title'))
Ejemplo n.º 12
0
class OrderRefundForm(forms.Form):
    amount = forms.IntegerField(
        __("Amount"),
        validators=[
            forms.validators.DataRequired(__("Please specify an amount"))
        ],
    )
    internal_note = forms.StringField(
        __("Internal note"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a note for future reference")),
            forms.validators.Length(max=250),
        ],
        description=__("Add a note for future reference"),
        filters=[forms.filters.none_if_empty()],
    )
    refund_description = forms.StringField(
        __("Refund description"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a description for the invoice")),
            forms.validators.Length(max=250),
        ],
        description=__("Description for the invoice"),
        filters=[forms.filters.none_if_empty()],
    )
    note_to_user = forms.MarkdownField(
        __("Note to user"),
        validators=[
            forms.validators.DataRequired(
                __("Please specify a note for the buyer"))
        ],
        description=__("Send this note to the buyer"),
        filters=[forms.filters.none_if_empty()],
    )

    def validate_amount(self, field):
        requested_refund_amount = field.data
        order = self.edit_parent
        if not order.paid_amount:
            raise StopValidation(
                __("Refunds can only be issued for paid orders"))
        if (order.refunded_amount +
                requested_refund_amount) > order.paid_amount:
            raise StopValidation(
                __("Invalid refund amount! Must be lesser than {amount}, the net amount paid for the order"
                   .format(amount=order.net_amount)))
Ejemplo n.º 13
0
class LabelOptionForm(forms.Form):
    name = forms.StringField(
        "", widget=forms.HiddenInput(), validators=[forms.validators.Optional()]
    )
    title = forms.StringField(
        __("Option"),
        validators=[
            forms.validators.DataRequired(__("This can’t be empty")),
            forms.validators.Length(max=250),
        ],
        filters=[forms.filters.strip()],
    )
    icon_emoji = forms.StringField(
        "", validators=[forms.validators.Optional(), forms.validators.IsEmoji()]
    )
    seq = forms.IntegerField("", widget=forms.HiddenInput())
Ejemplo n.º 14
0
class RefundTransactionForm(forms.Form):
    amount = forms.IntegerField(__("Amount"),
                                validators=[
                                    forms.validators.DataRequired(
                                        __("Please specify an amount"))
                                ])
    internal_note = forms.StringField(
        __("Internal note"),
        validators=[forms.validators.Length(max=250)],
        description=__("Add a note for future reference"),
        filters=[forms.filters.none_if_empty()])
    refund_description = forms.StringField(
        __("Refund description"),
        validators=[forms.validators.Length(max=250)],
        description=__("Why is this order receiving a refund?"),
        filters=[forms.filters.none_if_empty()])
    note_to_user = forms.MarkdownField(
        __("Note to user"),
        description=__("Send this note to the buyer"),
        filters=[forms.filters.none_if_empty()])
Ejemplo n.º 15
0
class CampaignActionForm(forms.Form):
    title = forms.StringField(
        __("Title"),
        description=__("Contents of the call to action button"),
        validators=[
            forms.validators.DataRequired("You must provide some text"),
            forms.validators.StripWhitespace()
        ])
    icon = forms.NullTextField(
        __("Icon"),
        validators=[forms.validators.Optional()],
        description=__("Optional Font-Awesome icon name"))
    public = forms.BooleanField(__("This action is live"))
    type = forms.RadioField(
        __("Type"),
        choices=CAMPAIGN_ACTION.items(),
        validators=[forms.validators.DataRequired(__("This is required"))])
    group = forms.NullTextField(
        __("RSVP group"),
        validators=[forms.validators.Optional()],
        description=__(
            "If you have multiple RSVP actions, add an optional group name"))
    category = forms.RadioField(
        __("Category"),
        validators=[forms.validators.DataRequired(__("This is required"))],
        widget=forms.InlineListWidget(class_='button-bar',
                                      class_prefix='btn btn-'),
        choices=[
            (u'default', __(u"Default")),
            (u'primary', __(u"Primary")),
            (u'success', __(u"Success")),
            (u'info', __(u"Info")),
            (u'warning', __(u"Warning")),
            (u'danger', __(u"Danger")),
        ])
    message = forms.TinyMce4Field(
        __("Message"),
        description=__(
            "Message shown after the user has performed an action (for forms and RSVP type)"
        ),
        content_css=content_css,
        validators=[
            forms.validators.Optional(),
            forms.validators.AllUrlsValid()
        ])
    link = forms.URLField(
        __("Link"),
        description=__(u"URL to redirect to, if type is “follow link”"),
        validators=[
            forms.validators.StripWhitespace(), optional_url,
            forms.validators.Length(min=0,
                                    max=250,
                                    message=__("%%(max)d characters maximum")),
            forms.validators.ValidUrl()
        ])
    form = forms.TextAreaField(
        __("Form JSON"),
        description=__("Form definition (for form type)"),
        validators=[forms.validators.Optional()])
    seq = forms.IntegerField(
        __("Sequence #"),
        validators=[forms.validators.DataRequired(__("This is required"))],
        description=__(
            "Sequence number for displaying this action when multiple actions are available to the user"
        ))
Ejemplo n.º 16
0
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()]
Ejemplo n.º 17
0
class FormTest(forms.Form):
    test_field = forms.IntegerField("Test label", default=1)
Ejemplo n.º 18
0
 class Form(forms.Form):
     other = forms.IntegerField("Other")
     field = forms.StringField(
         "Field", validators=[forms.validators.AllowedIf('other')])