示例#1
0
class book_edit_form(Form):
    title = TextField("Title")
    imprint = TextField("Imprint")
    eisbn = TextField("eISBN", validators=[Optional()])
    pisbn = TextField("pISBN", validators=[Optional()])
    language = TextField("Language")
    list_price = DecimalField("List Price", places=2, validators=[Optional()])
    currency = SelectField(
        "Currency",
        choices=[(g, g)
                 for g in ['none', 'USD', 'EUR', 'GBP', 'CAD', 'CNY', 'JPY']])
    release_date = DateField("Release Date",
                             validators=[Optional()],
                             format='%m/%d/%Y')
    publishing_date = DateField("Publishing Date",
                                validators=[Optional()],
                                format='%m/%d/%Y')
    description = TextAreaField("Description")
    bisac = TextField("BISAC")
    bic = TextField("BIC")
    #TODO: Fix this, this needs to be a list.
    territory = SelectField("Countries to sell in",
                            choices=[('none', 'none'), ('US', 'US'),
                                     ('GB', 'GB'), ('FR', 'FR'), ('IT', 'IT'),
                                     ('CN', 'CN'), ('JP', 'JP'), ('ES', 'ES'),
                                     ('IE', 'IE'), ('DE', 'DE')],
                            validators=[Optional()])
    adult = BooleanField("Is this an adult book?")
    edition = TextField("Edition")
    series = SelectField("Series", coerce=int)
    volume = TextField("Volume")
    authors = SelectMultipleField("Authors", coerce=int)
    editors = SelectMultipleField("Editors", coerce=int)
    illustrators = SelectMultipleField("Illustrators", coerce=int)
    contributors = SelectMultipleField("Contributors", coerce=int)
    translators = SelectMultipleField("Translators", coerce=int)

    def validate_publishing_date(self, field):
        if field.data > self.release_date.data:
            raise ValidationError(
                "The publishing date must be before or equal to the release date."
            )

    def is_isbn_valid(self, isbn):
        if not isValid(isbn):
            raise ValidationError("The ISBN entered is not valid.")

    def validate_eisbn(self, field):
        self.is_isbn_valid(field.data)

    def validate_pisbn(self, field):
        self.is_isbn_valid(field.data)
示例#2
0
class EditTaskForm(Form):
    name = TextField(
        _(u"任务名称"),
        validators=[required(message=_(u"任务名称不为空")), is_legal_taskname])
    description = TextAreaField(_(u"描述"))
    access = RadioField(_(u"状态"),
                        default=Task.PUBLIC,
                        coerce=int,
                        choices=((Task.PUBLIC, _(u"公开")), (Task.PRIVATE,
                                                           _(u"私有"))))

    moduletype_id = SelectField(_(u"选择模块"), coerce=int)

    case_list = SelectMultipleField(
        _(u"选择用例"),
        coerce=int,
        option_widget=widgets.CheckboxInput(),
        widget=widgets.ListWidget(prefix_label=False))

    code_list = SelectMultipleField(
        _(u"选择代码"),
        coerce=int,
        option_widget=widgets.CheckboxInput(),
        widget=widgets.ListWidget(prefix_label=False))

    command = TextAreaField(_(u"执行命令"))

    runtime = TextAreaField(_(u"运行时间"))

    svn = TextAreaField(_(u"svn地址"), validators=[is_legal_svn])

    email = TextAreaField(_(u"邮箱地址"))

    email_topic = TextAreaField(_(u"邮件主题"))
    other = TextAreaField(_(u"其他"))

    submit = SubmitField(_(u"保存"))

    def __init__(self, task, *args, **kwargs):
        self.task = task
        kwargs['obj'] = self.task
        super(EditTaskForm, self).__init__(*args, **kwargs)

    def validate_name(self, field):
        task = Task.query.filter(
            db.and_(Task.name.like(field.data),
                    db.not_(Task.id == self.task.id))).first()
        if task:
            raise ValidationError(gettext(u"名称已经被使用"))
示例#3
0
class AddTaskForm(Form):

    name = TextField(
        _(u"任务名称"),
        validators=[required(message=_(u"任务名称不为空")), is_legal_taskname])
    description = TextAreaField(_(u"描述"))
    access = RadioField(_(u"状态"),
                        default=Task.PUBLIC,
                        coerce=int,
                        choices=((Task.PUBLIC, _(u"公开")), (Task.PRIVATE,
                                                           _(u"私有"))))

    moduletype_id = SelectField(_(u"选择模块"), coerce=int)

    case_list = SelectMultipleField(
        _(u"选择用例"),
        coerce=int,
        option_widget=widgets.CheckboxInput(),
        widget=widgets.ListWidget(prefix_label=False))

    code_list = SelectMultipleField(
        _(u"选择代码"),
        coerce=int,
        option_widget=widgets.CheckboxInput(),
        widget=widgets.ListWidget(prefix_label=False))

    command = TextAreaField(
        _(u"执行命令"),
        default=
        u"hg clone http://10.0.2.205:9090/hg/test.cgi/script/\n./script/command.sh"
    )

    runtime = TextAreaField(_(u"运行时间"))

    svn = TextAreaField(_(u"svn地址"), validators=[is_legal_svn])

    email = TextAreaField(_(u"邮箱地址"))

    email_topic = TextAreaField(_(u"邮件主题"))

    other = TextAreaField(_(u"其他"))

    submit = SubmitField(_(u"添加"))

    def validate_name(self, field):
        task = Task.query.filter(Task.name.like(field.data)).first()
        if task:
            raise ValidationError(gettext(u"该名称已经被使用"))
示例#4
0
class BillForm(Form):
    date = DateField(_("Date"), validators=[Required()], default=datetime.now)
    what = TextField(_("What?"), validators=[Required()])
    payer = SelectField(_("Payer"), validators=[Required()], coerce=int)
    amount = CommaDecimalField(_("Amount paid"), validators=[Required()])
    payed_for = SelectMultipleField(_("For whom?"),
            validators=[Required()], widget=select_multi_checkbox, coerce=int)
    submit = SubmitField(_("Submit"))
    submit2 = SubmitField(_("Submit and add a new one"))

    def save(self, bill, project):
        bill.payer_id = self.payer.data
        bill.amount = self.amount.data
        bill.what = self.what.data
        bill.date = self.date.data
        bill.owers = [Person.query.get(ower, project)
            for ower in self.payed_for.data]

        return bill

    def fill(self, bill):
        self.payer.data = bill.payer_id
        self.amount.data = bill.amount
        self.what.data = bill.what
        self.date.data = bill.date
        self.payed_for.data = [int(ower.id) for ower in bill.owers]

    def set_default(self):
        self.payed_for.data = self.payed_for.default

    def validate_amount(self, field):
        if field.data < 0:
            field.data = abs(field.data)
        elif field.data == 0:
            raise ValidationError(_("Bills can't be null"))
示例#5
0
class ThreadCrudForm(Form):
    question_id = HiddenField(validators=[Required(),valid_question])
    
    author_id = SelectMultipleField("Author", 
        validators=[check_if_user_does_not_exist])
     
    yesno = SelectField("Yes or No?", 
        validators=[AnyOf(["1","0"]), Required()],
        choices=[("1",'Yes'),("0",'No')])
    
    text = TextAreaField("Opinion", 
        validators=[
            Length(min=1, max=140, 
                message="Post must be between 2 and 140 characters"), 
            Required(), 
            does_not_have_bad_words])
    
    likes = IntegerField("Likes", validators=[Optional()])
    
    def __init__(self, question_id=None, *args, **kwargs):
        super(ThreadCrudForm, self).__init__(*args, **kwargs)
        if question_id:
            self.question_id.data = question_id
        self.author_id.choices = [(str(u.id),'%s (%s)' % (u.username, u.origin)) \
                                  for u in cdw.users.with_fields(isAdmin=True).order_by("+username")]
示例#6
0
class PostForm(Form):
    title = TextField('title', validators=[Required()])
    body = TextField('body', validators=[Required()])
    tags = SelectMultipleField(
        'tags',
        validators=[Required()],
        choices=[(str(tag.id), tag.name)
                 for tag in db.session.query(models.Tag).all()])
示例#7
0
class BookmarkForm(Form):
    url = TextField("URL", [Required(), URL(require_tld=True)])
    title = TextField("Title", [Required()])
    description = TextAreaField('Description')
    tags = SelectMultipleField('Tags')
    public = BooleanField('Public?')

    def __init__(self, *args, **kwargs):
        super(BookmarkForm, self).__init__(*args, **kwargs)
        self.tags.choices = [(t.name, t.name) for t in Tag.query.all()]
示例#8
0
class PostForm(Form):
    title = TextField("Title", [validators.Required("Please enter the title")])
    text = TextAreaField(
        "Text",
        [validators.Required("Please provide the content for the title")])
    tag = SelectMultipleField("Tag")
    submit = SubmitField("Create Post")

    def __init__(self, *args, **kwargs):
        kwargs['csrf_enabled'] = False
        Form.__init__(self, *args, **kwargs)
示例#9
0
class RegisterContForm(Form):
	fitness = SelectField('Fitness Level', [validators.Required()], 
						  choices=[ ('1', 'low'), ('2', 'medium'), ('3', 'high')], 
						  description=u'Fitness Level')
	# need to convert fitness value to int
	
	experience = SelectField('Years Played?', [validators.Required()], 
							 choices=[(str(i),i) for i in range(50)], 
							 description=u'Years Played?')
	# need to covert experience value to int
	
	willing_teamLeader = BooleanField('Team Leader?')
	
	positions = SelectMultipleField(u'Positions', [validators.Required()],
									choices=[ ('none', 'none'),('offense', 'offense'), ('defense', 'defense'), 
											 ('midfield', 'midfield'), ('goalie','goalie')],
									description=u'Positions (Optional)')

	health = SelectMultipleField(u'Health Issues', [validators.Required()],
									choices=[(str(i.id), i.issue) for i in model.session.query(model.HealthType).\
																	order_by(model.HealthType.id).all()],
									description=u'Health Issues')
示例#10
0
class BookForm(Form):
    title = TextField(u'title', [Required()])
    authors = SelectMultipleField(u'Authors', coerce=int)
    save = SubmitField(u'Save')

    def __init__(self, *args, **kwargs):
        super(BookForm, self).__init__(*args, **kwargs)
        obj = kwargs.get('obj')
        self.authors.choices = \
            [(author.id, author.name) for author in Author.query.all()]
        if obj:
            selected_authors_ids = [author.id for author in obj.authors]
            self.title.data = obj.title
            self.authors.data = selected_authors_ids

    def populate_obj(self, obj):
        obj.title = self.title.data
        author_ids = self.authors.data
        obj.authors = Author.query.filter(Author.id.in_(author_ids)).all()
示例#11
0
class PasteForm(Form):

    title = TextField('Title', validators=[required(message="Title required")])
    slug = TextField('Slug')
    body = TextAreaField('Body',
                         validators=[required(message="Code required")])
    language = SelectField('Language',
                           choices=LANG_CHOICES,
                           validators=[required(message="Language required")])
    explanation = TextField(
        'Explain', validators=[required(message="Explanation required")])
    labels = SelectMultipleField(
        'Labels',
        choices=LABEL_CHOICES,
        validators=[required(message="Label(s) required")])
    source = TextField('Source')
    deleted = BooleanField('Delete?')

    submit = SubmitField('Save')
示例#12
0
class PostCrudForm(Form):   
    yesno = SelectField("Yes or No?", 
        validators=[AnyOf(["1","0"]), Required()],
        choices=[("1",'Yes'),("0",'No')])
    
    debate_id = HiddenField(validators=[check_if_thread_exists])
    
    text = TextAreaField(validators=[
        Length(min=1, max=140, 
               message="Post must be between 2 and 140 characters"), 
        Required(), does_not_have_bad_words])
    
    author_id = SelectMultipleField("Author", 
        validators=[check_if_user_does_not_exist])
    
    origin = SelectField(validators=[Required(), 
                                     AnyOf(["web","kiosk","cell"]),],
                                     choices=[("web",'Web'),("kiosk",'Kiosk'), ("cel", "Cell")])
    
    likes = IntegerField("Likes", validators=[Optional()])
    
    def __init__(self, debate_id=None, *args, **kwargs):
        super(PostCrudForm, self).__init__(*args, **kwargs)
        if debate_id:
            self.debate_id.data = debate_id
            
        self.author_id.choices = [(str(u.id),'%s (%s)' % (u.username, u.origin)) \
                                  for u in cdw.users.with_fields(isAdmin=True).order_by("+username")]
    
    def to_post(self):
        try:
            responseTo = cdw.posts.with_id(self.responseto.data)
        except:
            responseTo = None
            
        return Post(yesNo=int(self.yesno.data), 
                    text=self.text.data, 
                    author=User.objects.with_id(self.author_id.data[0]),
                    origin=self.origin.data,
                    likes=self.likes.data,
                    responseTo=responseTo) 
示例#13
0
 def __init__(self, *args, **kwargs):
     SelectMultipleField.__init__(self, *args, **kwargs)
     self.label = LoneLabel(self.id, self.label.text)
     self.status = kwargs.get("status", {})
示例#14
0
class InstallCourse(Form):
    defaults = [('None', '---')]
    site = SelectField('Site', choices=defaults)
    course = SelectMultipleField('Course', choices=defaults)
    filter = SelectField('Filter', choices=defaults)
示例#15
0
class EditBlogPostForm(Form):
    next = HiddenField()
    headline = TextField(u'Headline', [Required()])
    tags = SelectMultipleField(u'Tags', coerce=int)
    body = TextAreaField(u'Content', [Required(), Length(0, 10000)])
    submit = SubmitField('Save')