<commit_before># -*- coding: utf-8 -*-

from baseframe import _, __
import baseframe.forms as forms
from baseframe.forms.sqlalchemy import QuerySelectMultipleField, QuerySelectField
from coaster.utils import getbool
from baseframe.forms.validators import StopValidation
from ..models import DiscountPolicy, DISCOUNT_TYPE, CURRENCY, Item, ItemCollection, db

__all__ = ['DiscountPolicyForm', 'PriceBasedDiscountPolicyForm', 'DiscountPriceForm', 'DiscountCouponForm', 'AutomaticDiscountPolicyForm', 'CouponBasedDiscountPolicyForm']


class DiscountPolicyForm(forms.Form):
    title = forms.StringField(__("Discount title"),
        validators=[forms.validators.DataRequired(__("Please specify a discount title")),
        forms.validators.Length(max=250)], filters=[forms.filters.strip()])
    discount_type = forms.RadioField(__("Discount Type"),
        choices=DISCOUNT_TYPE.items(), coerce=int, default=DISCOUNT_TYPE.COUPON)
    is_price_based = forms.RadioField(__("Price based discount"),
        choices=[(True, __("Special price discount")),
        (False, __("Percentage based discount"))], coerce=getbool, default=True)


def validate_unique_discount_code_base(form, field):
    if DiscountPolicy.query.filter(DiscountPolicy.id != form.edit_id, DiscountPolicy.discount_code_base == field.data).notempty():
        raise StopValidation(__('This discount coupon prefix already exists. Please pick a different prefix'))


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 an item for which the discount is applicable"))])

    def __init__(self, *args, **kwargs):
        super(AutomaticDiscountPolicyForm, self).__init__(*args, **kwargs)
        self.items.query = Item.query.join(ItemCollection).filter(
            ItemCollection.organization == self.edit_parent).options(db.load_only('id', 'title'))


class CouponBasedDiscountPolicyForm(DiscountPolicyForm):
    items = QuerySelectMultipleField(__("Items"), get_label='title',
        validators=[forms.validators.DataRequired(__("Please select a item to which discount is to be applied"))])
    percentage = forms.IntegerField(__("Percentage"),
        validators=[forms.validators.DataRequired(__("Please specify a discount percentage"))])
    discount_code_base = forms.StringField(__("Discount Title"),
        validators=[forms.validators.DataRequired(__("Please specify a discount code base")),
        forms.validators.Length(max=20), validate_unique_discount_code_base],
        filters=[forms.filters.strip(), forms.filters.none_if_empty()])
    bulk_coupon_usage_limit = forms.IntegerField(__("Number of times a bulk coupon can be used"), default=1)

    def __init__(self, *args, **kwargs):
        super(CouponBasedDiscountPolicyForm, self).__init__(*args, **kwargs)
        self.items.query = Item.query.join(ItemCollection).filter(
            ItemCollection.organization == self.edit_parent).options(db.load_only('id', 'title'))


class PriceBasedDiscountPolicyForm(DiscountPolicyForm):
    discount_code_base = forms.StringField(__("Discount Title"),
        validators=[forms.validators.DataRequired(__("Please specify a discount code base")),
        forms.validators.Length(max=20), validate_unique_discount_code_base],
        filters=[forms.filters.strip(), forms.filters.none_if_empty()])


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=CURRENCY.items(), default=CURRENCY.INR)
    start_at = forms.DateTimeField(__("Price start date"),
        validators=[forms.validators.DataRequired(__("Please specify a start date and time"))])
    end_at = forms.DateTimeField(__("Price end date"),
        validators=[forms.validators.DataRequired(__("Please specify an end date and time")),<commit_msg>fixed label<commit_after># -*- coding: utf-8 -*-

from baseframe import _, __
import baseframe.forms as forms
from baseframe.forms.sqlalchemy import QuerySelectMultipleField, QuerySelectField
from coaster.utils import getbool
from baseframe.forms.validators import StopValidation
from ..models import DiscountPolicy, DISCOUNT_TYPE, CURRENCY, Item, ItemCollection, db

__all__ = ['DiscountPolicyForm', 'PriceBasedDiscountPolicyForm', 'DiscountPriceForm', 'DiscountCouponForm', 'AutomaticDiscountPolicyForm', 'CouponBasedDiscountPolicyForm']


class DiscountPolicyForm(forms.Form):
    title = forms.StringField(__("Discount title"),
        validators=[forms.validators.DataRequired(__("Please specify a discount title")),
        forms.validators.Length(max=250)], filters=[forms.filters.strip()])
    discount_type = forms.RadioField(__("Discount Type"),
        choices=DISCOUNT_TYPE.items(), coerce=int, default=DISCOUNT_TYPE.COUPON)
    is_price_based = forms.RadioField(__("Price based discount"),
        choices=[(True, __("Special price discount")),
        (False, __("Percentage based discount"))], coerce=getbool, default=True)


def validate_unique_discount_code_base(form, field):
    if DiscountPolicy.query.filter(DiscountPolicy.id != form.edit_id, DiscountPolicy.discount_code_base == field.data).notempty():
        raise StopValidation(__('This discount coupon prefix already exists. Please pick a different prefix'))


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 an item for which the discount is applicable"))])

    def __init__(self, *args, **kwargs):
        super(AutomaticDiscountPolicyForm, self).__init__(*args, **kwargs)
        self.items.query = Item.query.join(ItemCollection).filter(
            ItemCollection.organization == self.edit_parent).options(db.load_only('id', 'title'))


class CouponBasedDiscountPolicyForm(DiscountPolicyForm):
    items = 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"))])
    discount_code_base = forms.StringField(__("Discount Title"),
        validators=[forms.validators.DataRequired(__("Please specify a discount code base")),
        forms.validators.Length(max=20), validate_unique_discount_code_base],
        filters=[forms.filters.strip(), forms.filters.none_if_empty()])
    bulk_coupon_usage_limit = forms.IntegerField(__("Number of times a bulk coupon can be used"), default=1)

    def __init__(self, *args, **kwargs):
        super(CouponBasedDiscountPolicyForm, self).__init__(*args, **kwargs)
        self.items.query = Item.query.join(ItemCollection).filter(
            ItemCollection.organization == self.edit_parent).options(db.load_only('id', 'title'))


class PriceBasedDiscountPolicyForm(DiscountPolicyForm):
    discount_code_base = forms.StringField(__("Discount prefix"),
        validators=[forms.validators.DataRequired(__("Please specify a discount code base")),
        forms.validators.Length(max=20), validate_unique_discount_code_base],
        filters=[forms.filters.strip(), forms.filters.none_if_empty()])


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=CURRENCY.items(), default=CURRENCY.INR)
    start_at = forms.DateTimeField(__("Price start date"),
        validators=[forms.validators.DataRequired(__("Please specify a start date and time"))])
    end_at = forms.DateTimeField(__("Price end date"),
        validators=[forms.validators.DataRequired(__("Please specify an end date and time")),
{'fraction_non_alphanumeric': 0.12431604289778946, 'fraction_numerical': 0.0028452615451958854, 'mean_word_length': 5.333333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4862935', 'n_tokens_mistral': 2499, 'n_tokens_neox': 2468, 'n_words': 515}