예제 #1
0
파일: forms.py 프로젝트: pavetok/the-tale
class RequestAccessForm(forms.Form):
    application_name = fields.CharField(
        max_length=models.AccessToken.APPLICATION_NAME_MAX_LENGTH,
        required=True)
    application_info = fields.CharField(
        max_length=models.AccessToken.APPLICATION_INFO_MAX_LENGTH,
        required=False)
    application_description = fields.CharField(required=True)
예제 #2
0
class CreateClan(forms.Form):
    name = fields.CharField(label='Название',
                            max_length=clan_models.Clan.MAX_NAME_LENGTH,
                            min_length=clan_models.Clan.MIN_NAME_LENGTH)
    abbr = fields.CharField(label='Аббревиатура (до %d символов)' %
                            clan_models.Clan.MAX_ABBR_LENGTH,
                            max_length=clan_models.Clan.MAX_ABBR_LENGTH,
                            min_length=clan_models.Clan.MIN_ABBR_LENGTH)

    def get_card_data(self):
        return {'name': self.c.name, 'abbr': self.c.abbr}
예제 #3
0
class ClanForm(forms.Form):

    name = fields.CharField(label='Название',
                            max_length=Clan.MAX_NAME_LENGTH,
                            min_length=Clan.MIN_NAME_LENGTH)
    abbr = fields.CharField(label='Аббревиатура (до %d символов)' %
                            Clan.MAX_ABBR_LENGTH,
                            max_length=Clan.MAX_ABBR_LENGTH,
                            min_length=Clan.MIN_ABBR_LENGTH)
    motto = fields.CharField(label='Девиз', max_length=Clan.MAX_MOTTO_LENGTH)
    description = bbcode.BBField(label='Описание',
                                 max_length=Clan.MAX_DESCRIPTION_LENGTH)
예제 #4
0
파일: forms.py 프로젝트: pavetok/the-tale
class NewAchievementForm(forms.Form):

    approved = fields.BooleanField(label=u'Одобрена', required=False)

    order = fields.IntegerField()

    group = fields.TypedChoiceField(label=u'Группа', choices=sorted(ACHIEVEMENT_GROUP.choices(), key=lambda g: g[1]), coerce=ACHIEVEMENT_GROUP.get_from_name)
    type = fields.TypedChoiceField(label=u'Тип', choices=sorted(ACHIEVEMENT_TYPE.choices(), key=lambda g: g[1]), coerce=ACHIEVEMENT_TYPE.get_from_name)

    caption = fields.CharField(label=u'Название', max_length=AchievementPrototype.CAPTION_MAX_LENGTH, min_length=1)

    description = bbcode.BBField(label=u'Описание', min_length=1, max_length=AchievementPrototype.DESCRIPTION_MAX_LENGTH)

    barrier = fields.IntegerField(label=u'Барьер')

    points = fields.IntegerField(label=u'Очки')

    item_1 = fields.ChoiceField(label=u'награда 1', choices=[], required=False)
    item_2 = fields.ChoiceField(label=u'награда 2', choices=[], required=False)
    item_3 = fields.ChoiceField(label=u'награда 3', choices=[], required=False)

    def __init__(self, *args, **kwargs):
        super(NewAchievementForm, self).__init__(*args, **kwargs)
        self.fields['item_1'].choices = [('', u'-----')] + items_storage.form_choices()
        self.fields['item_2'].choices = [('', u'-----')] + items_storage.form_choices()
        self.fields['item_3'].choices = [('', u'-----')] + items_storage.form_choices()

    clean_item_1 = create_clean_item_method(1)
    clean_item_2 = create_clean_item_method(2)
    clean_item_3 = create_clean_item_method(3)
예제 #5
0
파일: forms.py 프로젝트: serhii73/the-tale
class EditKitForm(forms.Form):

    collection = fields.ChoiceField(label='Коллекция')

    caption = fields.CharField(label='Название',
                               max_length=KitPrototype.CAPTION_MAX_LENGTH,
                               min_length=1)

    description = bbcode.BBField(
        label='Описание',
        min_length=1,
        max_length=KitPrototype.DESCRIPTION_MAX_LENGTH)

    def __init__(self, *args, **kwargs):
        super(EditKitForm, self).__init__(*args, **kwargs)
        self.fields[
            'collection'].choices = collections_storage.get_form_choices()

    def clean_collection(self):
        collection_id = self.cleaned_data['collection']
        collection = collections_storage[int(collection_id)]

        if collection is None:
            raise django_forms.ValidationError('Коллекция не найдена')

        return collection
예제 #6
0
파일: forms.py 프로젝트: angru/the-tale
def get_word_fields_dict(word_type):
    form_fields = {}

    for i, key in enumerate(utg_data.INVERTED_WORDS_CACHES[word_type]):
        form_fields['%s_%d' % (WORD_FIELD_PREFIX, i)] = fields.CharField(label='', max_length=models.Word.MAX_FORM_LENGTH, required=False)

    return form_fields
예제 #7
0
class BaseUserForm(forms.Form):
    caption = fields.CharField(label='Название записи',
                               max_length=models.Bill.CAPTION_MAX_LENGTH,
                               min_length=models.Bill.CAPTION_MIN_LENGTH)

    chronicle_on_accepted = fields.TextField(
        label='Текст летописи при принятии (от {} до {} символов)'.format(
            conf.bills_settings.CHRONICLE_MIN_LENGTH,
            conf.bills_settings.CHRONICLE_MAX_LENGTH),
        widget=Textarea(attrs={'rows': 6}),
        min_length=conf.bills_settings.CHRONICLE_MIN_LENGTH,
        max_length=conf.bills_settings.CHRONICLE_MAX_LENGTH)

    depends_on = fields.ChoiceField(label='Зависит от', required=False)

    def __init__(self, *args, **kwargs):
        original_bill_id = kwargs.pop('original_bill_id', None)

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

        voting_bills = models.Bill.objects.filter(
            state=relations.BILL_STATE.VOTING)
        self.fields['depends_on'].choices = [(None, ' — ')] + [
            (bill.id, bill.caption)
            for bill in voting_bills if bill.id != original_bill_id
        ]

    def clean_depends_on(self):
        data = self.cleaned_data.get('depends_on')

        if data == 'None':
            return None

        return data
예제 #8
0
파일: forms.py 프로젝트: he1mdallr/the-tale
class BaseUserForm(forms.Form):
    RATIONALE_MIN_LENGTH = 250 if not project_settings.TESTS_RUNNING else 0

    caption = fields.CharField(label='Название записи', max_length=Bill.CAPTION_MAX_LENGTH, min_length=Bill.CAPTION_MIN_LENGTH)
    rationale = bbcode.BBField(label='', min_length=RATIONALE_MIN_LENGTH)

    chronicle_on_accepted = fields.TextField(label='Текст летописи при принятии', widget=Textarea(attrs={'rows': 2}),
                                             min_length=bills_settings.CHRONICLE_MIN_LENGTH, max_length=bills_settings.CHRONICLE_MAX_LENGTH)
예제 #9
0
파일: forms.py 프로젝트: pavetok/the-tale
class EditThreadForm(forms.Form):

    caption = fields.CharField(label=u'Название', max_length=256, min_length=1)
    subcategory = fields.ChoiceField(label=u'Раздел', required=False)

    def __init__(self, subcategories, *args, **kwargs):
        super(EditThreadForm, self).__init__(*args, **kwargs)
        self.fields['subcategory'].choices = [(subcategory.id,
                                               subcategory.caption)
                                              for subcategory in subcategories]
예제 #10
0
파일: forms.py 프로젝트: serhii73/the-tale
class EditCollectionForm(forms.Form):

    caption = fields.CharField(
        label='Название',
        max_length=CollectionPrototype.CAPTION_MAX_LENGTH,
        min_length=1)

    description = bbcode.BBField(
        label='Описание',
        min_length=1,
        max_length=CollectionPrototype.DESCRIPTION_MAX_LENGTH)
예제 #11
0
파일: forms.py 프로젝트: serhii73/the-tale
class NewNewsForm(forms.Form):

    caption = fields.CharField(label='Заголовок')
    description = fields.TextField(label='Кратко')
    content = fields.TextField(label='Полностью')

    @classmethod
    def get_initials(cls, news):
        return {
            'caption': news.caption,
            'description': news.description,
            'content': news.content
        }
예제 #12
0
class SendMoneyForm(forms.Form):

    money = fields.IntegerField(label='Печеньки')

    comment = fields.CharField(label='Комментарий (для истории платежей)', min_length=10)

    def clean_money(self):
        money = self.cleaned_data['money']

        if money < conf.accounts_settings.MINIMUM_SEND_MONEY:
            raise ValidationError('Сумма должна быть не меньше %(min_money)s печенек' % {'min_money': conf.accounts_settings.MINIMUM_SEND_MONEY})

        return money
예제 #13
0
파일: forms.py 프로젝트: pavetok/the-tale
class PostForm(forms.Form):
    caption = fields.CharField(label=u'Название',
                               max_length=models.Post.CAPTION_MAX_LENGTH,
                               min_length=models.Post.CAPTION_MIN_LENGTH)
    text = bbcode.BBField(label=u'Текст',
                          min_length=conf.settings.MIN_TEXT_LENGTH)

    meta_objects = fields.CharField(label=u'Текст рассказывает о',
                                    required=False)

    def clean_meta_objects(self):
        data = self.cleaned_data.get('meta_objects', '')

        objects = []

        slugs = set()

        for slug in data.split():
            slug = slug.strip()

            if slug in slugs:
                raise ValidationError(u'Повторяющийся дентификатор: %s' % slug)

            slugs.add(slug)

            try:
                objects.append(meta_relations_logic.get_object_by_uid(slug))
            except (meta_relations_exceptions.WrongTypeError,
                    meta_relations_exceptions.WrongObjectError,
                    meta_relations_exceptions.WrongUIDFormatError):
                raise ValidationError(u'Неверный идентификатор: %s' % slug)

        if len(objects) > conf.settings.IS_ABOUT_MAXIMUM:
            raise ValidationError(
                u'Слишком много связей, должно быть не более %d' %
                conf.settings.IS_ABOUT_MAXIMUM)

        return objects
예제 #14
0
파일: forms.py 프로젝트: serhii73/the-tale
class EditItemForm(forms.Form):

    kit = fields.ChoiceField(label='Набор')

    caption = fields.CharField(label='Название',
                               max_length=ItemPrototype.CAPTION_MAX_LENGTH,
                               min_length=1)

    text = bbcode.BBField(label='Текст', min_length=1)

    def __init__(self, *args, **kwargs):
        super(EditItemForm, self).__init__(*args, **kwargs)
        self.fields['kit'].choices = kits_storage.get_form_choices()

    def clean_kit(self):
        kit_id = self.cleaned_data['kit']
        kit = kits_storage[int(kit_id)]

        if kit is None:
            raise django_forms.ValidationError('Колекция не найдена')

        return kit
예제 #15
0
class SayForm(forms.Form):

    text = fields.CharField(max_length=1024, required=True)
예제 #16
0
파일: forms.py 프로젝트: he1mdallr/the-tale
class ChoosePreferencesForm(forms.Form):

    preference_id = fields.CharField(max_length=32, required=False)
    preference_type = fields.TypedChoiceField(
        choices=relations.PREFERENCE_TYPE.choices(),
        coerce=relations.PREFERENCE_TYPE.get_from_name)
예제 #17
0
파일: forms.py 프로젝트: pavetok/the-tale
class NewThreadForm(NewPostForm):

    caption = fields.CharField(label=u'Название', max_length=256, min_length=1)