本文整理汇总了Python中assetapp.t函数的典型用法代码示例。如果您正苦于以下问题:Python t函数的具体用法?Python t怎么用?Python t使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了t函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.authenticate(form.login.data.lower().strip(),
form.password.data,
)
if user is None:
form.login.errors = [t('.invalid_name_or_password')]
elif not user.is_active:
form.login.errors = [t('.not_activated')]
else:
session['user_id'] = user.id
session['lang'] = user.lang
url = session.pop('next_url', None)
if not url:
if user.is_root:
url = url_for('users.index')
elif user.is_store_user:
url = url_for('iohistory.index')
elif user.is_project_leader:
url = url_for('spareparts.index')
elif user.is_asset_user:
url = url_for('equipment.index')
elif user.is_asset_leader:
url = url_for('users.index')
else:
url = url_for('.index')
return redirect(url)
return render_template('home/login.html', form=form)
示例2: edit2
def edit2(id):
set_referrer()
e = Equipment.find_one(id)
if e is None:
flash(t('record_not_found'), 'error')
return redirect(get_referrer())
if not g.user.can_update_location(e):
flash(t('permission_denied'), 'error')
return redirect(get_referrer())
form = LocationForm(request.form,
location=e.location,
is_good='good' if e.is_good else 'bad'
)
form.is_good.choices = [('good', t('good')), ('bad', t('bad'))]
if form.validate_on_submit():
e.location = form.location.data
if not e.is_good:
e.is_good = form.is_good.data == 'good'
e.save(skip=True)
if e.is_valid:
flash(t('updated_successfully'), 'success')
return redirect(get_referrer())
return render_template('equipment/edit2.html',
form=form,
equipment=e,
)
示例3: equipment_out
def equipment_out():
form = EquipmentOutForm()
if form.validate_on_submit():
flex_id = form.flex_id.data.strip().upper()
spec = dict(flex_id=flex_id,
is_live=True,
)
e = Equipment.find_one(spec=spec)
if not e:
form.flex_id.errors = ['not_found']
elif not e.is_instore:
form.flex_id.errors = ['iohistory.not_in_store']
elif not g.user.can_transfer_equipment(e):
form.flex_id.errors = ['permission_denied']
else:
tf = create_tf(form)
tf.name = e.name
tf.model = e.model
tf.update(is_in=False,
kind='0',
asset=dict(flex_id=flex_id,
sn=e.sn,
fixed_id=e.fixed_id,
prod_date=e.prod_date,
cn=e.cn,
tn=e.tn,
department=e.department,
project=e.project,
is_good=e.is_good,
from_where=e.location,
to_where=form.where.data,
done=True,
),
)
tf.save()
if tf.is_valid:
doc = dict(status=e.status + ['transfer'],
is_live=False,
is_instore=False,
)
e.save(doc=doc, update_ts=False, skip=True)
flash(t('.equipment_transfer_out_successfully'))
dp = form.department.data
pj = form.project.data
asset_users = User.get_emails('asset_user', dp, pj, 'tf')
store_users = User.get_emails('store_user', dp, pj, 'tf')
asset_leaders = User.get_emails('asset_leader', dp, pj, 'tf')
send_mail(subject=t('notifications.equipment_transfer_out'),
to=User.get_emails('project_leader', dp, pj, 'tf'),
cc=asset_users + store_users + asset_leaders,
template='transfer_out.html',
values=dict(tf=tf, asset=e),
)
return redirect(url_for('.index'))
fill_form_error(form, tf)
return render_template('transfers/equipment_out.html',
form=form,
)
示例4: import_equipment
def import_equipment():
checked = False
form = ImportForm()
if request.method == 'POST':
if request.form.get('if-update'):
checked = True
excel = request.files.get('attachment')
if not excel:
flash(t('please_select_a_file'), 'error')
elif os.path.splitext(excel.filename)[-1].lower() != '.xls':
flash(t('only_excel_is_allowed'), 'error')
else:
fn = '{}_{}_{}'.format(strftime('%Y%m%d%H%M%S'),
g.user.id,
secure_filename(excel.filename),
)
file_path = os.path.join(tempfile.gettempdir(), fn)
excel.save(file_path)
return do_import(file_path, update=checked)
return render_template('equipment/import.html',
checked=checked,
form=form,
)
示例5: new
def new():
if not g.user.can_create_user:
flash(t('permission_denied'), 'error')
return redirect(url_for('.index'))
form = NewUserForm()
fill_form_choices(form)
form.is_active.choices = bool_choices('.active', '.disabled')
if form.validate_on_submit():
user = User(login=form.login.data.strip().lower(),
nick_name=form.nick_name.data.strip(),
password=form.password.data,
email=form.email.data.strip(),
badge_id=str(form.badge_id.data),
lang=form.lang.data,
is_active=bool(form.is_active.data),
gsm=form.gsm.data.strip(),
phone=form.phone.data.strip(),
short_no=form.short_no.data.strip(),
)
user.can_send = update_send(form)
user.save()
if user.is_valid:
flash(t('created_successfully'), 'success')
return redirect(url_for('.index'))
fill_form_error(form, user)
return render_template('users/new.html',
form=form,
)
示例6: edit
def edit(id):
set_referrer()
e = Equipment.find_one(id)
if e is None:
flash(t('record_not_found'), 'error')
return redirect(get_referrer())
if not g.user.can_edit_equipment(e):
flash(t('permission_denied'), 'error')
return redirect(get_referrer())
data = e.dict
data.update(is_good='good' if data['is_good'] else 'bad',
is_instore='in' if data['is_instore'] else 'out',
)
form = EquipmentForm(request.form, **data)
fill_choices(form)
if form.validate_on_submit():
update_equipment(e, form)
if not e.source:
form.source.errors = ['This field is required.']
else:
e.save()
if e.is_valid:
handle_uploads(str(e.id))
flash(t('updated_successfully'), 'success')
return redirect(get_referrer())
fill_form_error(form, e)
return render_template('equipment/edit.html',
form=form,
equipment=e,
)
示例7: authorize
def authorize(id):
user = User.find_one(id)
if user is None:
flash(t('record_not_found'), 'error')
return redirect(url_for('.index'))
# user can not modify his/her own permission
if g.user.id == user.id:
flash(t('permission_denied'), 'error')
return redirect(url_for('.index'))
groups = [p.group for p in user.permissions]
form = AuthorizeForm(request.form, groups=groups)
spec = dict(is_active=True)
if not g.user.is_root:
spec.update(role={'$ne': 'asset_leader'})
form.groups.choices = sorted((p.group, p.group)
for p in Permission.find(spec=spec)
)
if form.validate_on_submit():
user.groups = sorted(request.form.getlist('groups'))
if sorted(groups) != user.groups:
user.save()
flash(t('updated_successfully'), 'success')
return redirect(url_for('.index'))
return render_template('users/authorize.html',
form=form,
user=user,
)
示例8: edit
def edit(id):
sp = Sparepart.find_one(id)
if sp is None:
flash(t('record_not_found'), 'error')
return redirect(request.referrer)
if not g.user.can_edit_sparepart(sp):
flash(t('permission_denied'), 'error')
return redirect(request.referrer)
doc = sp.dict
can_edit_qty = sp.can_edit_qty
form = SparepartForm(request.form, **doc)
form.department.choices = department_choices()
form.project.choices = project_choices(with_all=g.user.is_root)
if form.validate_on_submit():
update_part(sp, form, can_edit_qty)
sp.save()
if sp.is_valid:
handle_uploads(str(sp.id))
flash(t('updated_successfully'), 'success')
return redirect(url_for('.index'))
fill_form_error(form, sp)
return render_template('spareparts/edit.html',
form=form,
can_edit_qty=can_edit_qty,
sp=sp,
)
示例9: signup
def signup():
form = SignupForm()
fill_form_choices(form)
if form.validate_on_submit():
user = User(login=form.login.data.strip().lower(),
password=form.password.data,
nick_name=form.nick_name.data.strip(),
badge_id=str(form.badge_id.data),
email=form.email.data.strip(),
phone=form.phone.data.strip(),
gsm=form.gsm.data.strip(),
short_no=form.short_no.data.strip(),
lang=form.lang.data,
)
can_send = []
for k in ('buy', 'io', 'tf', 'idle', 'scrap', 'alarm', 'notify'):
if getattr(form, 'send_{}'.format(k)).data == 'yes':
can_send.append(k)
user.can_send = can_send
user.save()
if user.is_valid:
flash(t('signup_successfully', 'success'))
return redirect(url_for('.login'))
# show the error message
for k, v in user._errors.items():
flash('{}: {}'.format(k, t(v)), 'error')
return render_template('home/signup.html', form=form)
示例10: fill_choices
def fill_choices(form):
form.department.choices = department_choices()
form.project.choices = project_choices()
form.source.choices = source_choices()
form.is_good.choices = [('good', t('good')), ('bad', t('bad'))]
form.is_instore.choices = [('in', t('.instore')),
('out', t('.outstore'))
]
示例11: edit
def edit(id):
user = User.find_one(id)
if user is None:
flash(t('record_not_found'), 'error')
return redirect(url_for('.index'))
if not g.user.can_edit_user(user):
flash(t('permission_denied'), 'error')
return redirect(url_for('.index'))
data = user.dict
for k in ('buy', 'io', 'tf', 'idle', 'scrap', 'alarm', 'notify'):
data['send_{}'.format(k)] = 'yes' if k in data['can_send'] else 'no'
form = EditUserForm(request.form, **data)
fill_form_choices(form)
form.is_active.choices = bool_choices('.active', '.disabled')
if form.validate_on_submit():
user.update(nick_name=form.nick_name.data.strip(),
email=form.email.data.strip(),
badge_id=str(form.badge_id.data),
lang=form.lang.data,
gsm=form.gsm.data.strip(),
phone=form.phone.data.strip(),
short_no=form.short_no.data.strip(),
)
user.can_send = update_send(form)
if not user.is_root:
user.update(login=form.login.data.strip().lower())
if g.user.id != user.id:
user.is_active = bool(form.is_active.data)
if form.password_again.data:
user.password = form.password.data
user.save()
if user.is_valid:
session['lang'] = user.lang
flash(t('updated_successfully'), 'success')
# password reset?
if user.email and form.password.data:
if user.is_active and user.id != g.user.id:
send_mail(subject=t('users.your_password_was_reset'),
to=[user.email],
template='password_reset.html',
values=dict(password=form.password.data,
login=user.login,
),
)
return redirect(url_for('.index'))
fill_form_error(form, user)
return render_template('users/edit.html',
user=user,
form=form,
)
示例12: fill_form_choices
def fill_form_choices(form):
radio_choice = [('yes', t('yes')), ('no', t('no'))]
form.send_buy.choices = radio_choice
form.send_io.choices = radio_choice
form.send_tf.choices = radio_choice
form.send_idle.choices = radio_choice
form.send_scrap.choices = radio_choice
form.send_alarm.choices = radio_choice
form.send_notify.choices = radio_choice
示例13: fill_choices
def fill_choices(form, kind='equipment'):
form.department.choices = limited_department_choices(g.user)
form.project.choices = project_choices()
form.source.choices = source_choices()
if kind == 'equipment':
form.is_good.choices = [('good', t('good')), ('bad', t('bad'))]
else:
dept = form.department.data
project = form.project.data
form.code.choices = code_choices(dept, project)
示例14: role_choices
def role_choices(asset_leader=False):
s = 'permissions'
lst = [('asset_user', t('{}.asset_user'.format(s))),
('store_user', t('users.store_user')),
('project_leader', t('{}.project_leader'.format(s))),
# ('cal_user', t('{}.cal_user'.format(s))),
]
if asset_leader is True:
lst.insert(0, ('asset_leader', t('{}.asset_leader'.format(s))))
return blank_choices() + lst
示例15: export
def export():
spec = session.get('spspec')
form = ExportForm()
if request.method == 'POST':
dbkeys = request.values.getlist('dbkey')
session['spchecked'] = dbkeys
if not dbkeys:
flash(t('no_field_was_selected'), 'error')
return render_template('spareparts/export.html',
fields=get_fields(),
form=form,
checked=session['spchecked'] or [None],
)
wb = Workbook()
ws = wb.add_sheet('Part List')
fill_header(ws, dbkeys)
objs = Sparepart.find(spec=spec, sort='department, project, code')
row = 1
for sp in objs:
for i, k in enumerate(dbkeys):
if k == 'total_price':
ws.write(row, i, sp.unit_price * sp.store_good)
elif k == 'is_local':
if sp.is_local:
txt = t('spareparts.local')
else:
txt = t('spareparts.oversea')
ws.write(row, i, txt)
else:
ws.write(row, i, getattr(sp, k))
row += 1
file_name = 'Part List {}.xls'.format(str(g.user.id))
file_dir = tempfile.gettempdir()
file_path = os.path.join(file_dir, file_name)
if os.path.isfile(file_path):
os.remove(file_path)
session.pop('spspec', None)
wb.save(file_path)
return send_from_directory(file_dir,
file_name,
as_attachment=True,
attachment_filename=file_name,
)
return render_template('spareparts/export.html',
fields=get_fields(),
form=form,
checked=session.get('spchecked', []),
)