예제 #1
0
class PriceAmountForm(Form):
	price = StringField(lazy_gettext('price'), validators=[DataRequired(),
														  Length(1, 64),
														  Regexp('^[0-9]+$', 0,
																 'only numbers please')])

	amount = StringField(lazy_gettext('amount'), validators=[DataRequired(),
														   Length(1, 64),
														   Regexp('^[0-9]+$', 0,
																  'only numbers please')])
예제 #2
0
 def test_lazy_gettext(self):
     app = flask.Flask(__name__)
     b = babel.Babel(app, default_locale='de_DE')
     yes = lazy_gettext(u'Yes')
     with app.test_request_context():
         assert unicode(yes) == 'Ja'
     app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
     with app.test_request_context():
         assert unicode(yes) == 'Yes'
예제 #3
0
 def test_lazy_gettext(self):
     app = flask.Flask(__name__)
     b = babel.Babel(app, default_locale='de_DE')
     yes = lazy_gettext(u'Yes')
     with app.test_request_context():
         assert unicode(yes) == 'Ja'
     app.config['BABEL_DEFAULT_LOCALE'] = 'en_US'
     with app.test_request_context():
         assert unicode(yes) == 'Yes'
예제 #4
0
    def scaffold_form(self):

        # Start with the standard form as provided by Flask-Admin.
        # We've already told Flask-Admin to exclude the
        # password field from this form.
        form_class = super(UserAdmin, self).scaffold_form()

        # Add a password field, naming it "password2" and labeling it "New
        # Password".
        form_class.password2 = PasswordField(
            label=u'密码',
            description=lazy_gettext('如果不修改密码请留空'))
        return form_class
예제 #5
0
class EditProfileAdminForm(Form):
    nickname = StringField(lazy_gettext('Nickname (login)'),
                           validators=[
                               DataRequired(),
                               Length(1, 64),
                               Regexp(
                                   '^^[a-zA-Z0-9_-]+$', 0,
                                   'Usernames must have only letters,'
                                   'numbers, dots or underscores')
                           ])
    email = StringField(lazy_gettext('Email'),
                        validators=[DataRequired(),
                                    Length(1, 64),
                                    Email()])
    fullname = StringField(lazy_gettext('Fullname'),
                           validators=[Length(6, 64)])
    group = SelectField(lazy_gettext('Group'), coerce=int)
    submit = SubmitField(lazy_gettext('Submit'))

    def __init__(self, user, *args, **kwargs):
        super(EditProfileAdminForm, self).__init__(*args, **kwargs)
        self.group.choices = [
            (group.id, group.name)
            for group in Group.query.order_by(Group.name).all()
        ]
        self.user = user

    def validate_email(self, field):
        if field.data != self.user.email and \
          User.query.filter_by(email=field.data).first():
            raise ValidationError(lazy_gettext('Email is already registered.'))

    def validate_nickname(self, field):
        if field.data != self.user.nickname and \
          User.query.filter_by(nickname=field.data).first():
            raise ValidationError(
                lazy_gettext('Nickname is already registered.'))
예제 #6
0
class SelectProductsForm(Form):
    products = SelectMultipleField(u'Tags', coerce=int)

    number = StringField(lazy_gettext('Number of'),
                         validators=[
                             DataRequired(),
                             Regexp('^[0-9 ]+$', 0, 'only numbers please')
                         ])
    submit = SubmitField()

    def __init__(self, *args, **kwargs):
        super(SelectProductsForm, self).__init__(*args, **kwargs)
        print(self.products.choices)
        self.products.choices = [
            (thing.id, thing.name)
            for thing in Thing.query.join(TypeOfThing).filter_by(
                assembled=1).all()
        ]
예제 #7
0
class TaskForm(Form):
    title = StringField(lazy_gettext('Title'), validators=[DataRequired()])
    description = PageDownField(lazy_gettext('Description'))
    worker = SelectField(lazy_gettext('Worker'), coerce=int)
    price = DecimalField(lazy_gettext('Price'))
    timelimit = DateTimeField(lazy_gettext('Timelimit'),
                              display_format='%d.%m.%Y %H:%M')
    submit = SubmitField(lazy_gettext('Submit'))

    def __init__(self, *args, **kwargs):
        super(TaskForm, self).__init__(*args, **kwargs)
        self.worker.choices = [
            (user.id, user.fullname)
            for user in User.query.order_by(User.fullname).all()
        ]
예제 #8
0
def init_admin_views(app, db):
    db_session = db.session
    admin_views = Admin(app, lazy_gettext(u'Visual\'s Best 管理后台'),
                        index_view=AdminMainView(),
                        base_template='layout/admin_layout.html',
                        template_mode='bootstrap3')
    admin_views.add_view(RequestAdmin(Request, db_session, name=u'拍摄请求', menu_icon_type=ICON_TYPE_GLYPH,
                                      category=u'订单相关', menu_icon_value='glyphicon-inbox'))
    admin_views.add_view(OrderAdmin(Order, db_session, name=u'订单', menu_icon_type=ICON_TYPE_GLYPH,
                                    category=u'订单相关', menu_icon_value='glyphicon-shopping-cart'))
    admin_views.add_view(OmnibusTemplateAdmin(OmnibusTemplate, db_session, name=u'推荐模板', menu_icon_type=ICON_TYPE_GLYPH,
                                              category=u'推荐', menu_icon_value='glyphicon-th'))
    admin_views.add_view(PhotoOmnibusAdmin(PhotoOmnibus, db_session, name=u'推荐作品', menu_icon_type=ICON_TYPE_GLYPH,
                                           category=u'推荐', menu_icon_value='glyphicon-star'))
    admin_views.add_view(UserAdmin(User, db_session, name=u'用户', menu_icon_type=ICON_TYPE_GLYPH,
                                   category=u'用户相关', menu_icon_value='glyphicon-user'))
    admin_views.add_view(RoleAdmin(Role, db_session, name=u'角色', menu_icon_type=ICON_TYPE_GLYPH,
                                   category=u'用户相关', menu_icon_value='glyphicon-eye-close'))
    admin_views.add_view(EnumValuesAdmin(EnumValues, db_session, name=u'列表设定', menu_icon_type=ICON_TYPE_GLYPH,
                                         category=u'系统设定', menu_icon_value='glyphicon-tasks'))
    return admin_views
예제 #9
0
 def validate_email(self, field):
     if AdminUser.query.filter_by(email=field.data).first():
         raise ValidationError(lazy_gettext('Email already registered.'))
예제 #10
0
class ThingForm(Form):
    name = StringField(lazy_gettext('Title'), validators=[DataRequired()])
예제 #11
0
 def validate_nickname(self, field):
     if field.data != self.user.nickname and \
       User.query.filter_by(nickname=field.data).first():
         raise ValidationError(
             lazy_gettext('Nickname is already registered.'))
예제 #12
0
 def validate_email(self, field):
     if field.data != self.user.email and \
       User.query.filter_by(email=field.data).first():
         raise ValidationError(lazy_gettext('Email is already registered.'))
예제 #13
0
 def on_model_change(self, form, model, is_created):
     if form.f_email.data != model.email and \
       User.query.filter_by(email=form.f_email.data).first():
         raise ValidationError(lazy_gettext('Email is already registered.'))
     model.email = form.f_email.data
예제 #14
0
파일: i18n.py 프로젝트: aip/phics
def label(function, message):
    message = make_label(function.__module__, function.__qualname__, message)
    return lazy_gettext(message)
예제 #15
0
파일: utils.py 프로젝트: leiyue/seed
def _l(*args, **kwargs):
    return lazy_gettext(*args, **kwargs)