本文整理汇总了Python中assetapp.t函数的典型用法代码示例。如果您正苦于以下问题:Python t函数的具体用法?Python t怎么用?Python t使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了t函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:31,代码来源:home.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:30,代码来源:equipment.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:60,代码来源:transfers.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:26,代码来源:equipment.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:31,代码来源:users.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:34,代码来源:equipment.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:32,代码来源:users.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:30,代码来源:spareparts.py
示例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)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:30,代码来源:home.py
示例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'))
]
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:8,代码来源:equipment.py
示例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,
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:58,代码来源:users.py
示例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
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:9,代码来源:users.py
示例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)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:10,代码来源:buys.py
示例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
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:11,代码来源:select.py
示例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', []),
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:54,代码来源:spareparts.py
示例16: equipment_out
def equipment_out():
form = OutEquipmentForm()
form.to_project.choices = project_choices(True)
e = None
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 = [".not_in_store"]
elif not g.user.can_io_asset(e):
form.flex_id.errors = ["permission_denied"]
else:
io = create_io(form)
io.update(
kind="0",
is_out=True,
department=e.department,
project=e.project,
name=e.name,
asset=dict(
flex_id=flex_id,
sn=e.sn,
fixed_id=e.fixed_id,
model=e.model,
to_project=form.to_project.data,
to_where=form.to_where.data,
to_line=form.line.data,
iogood=e.is_good,
),
)
io.save()
if io.is_valid:
doc = dict(location=form.to_where.data, line=form.line.data, is_instore=False)
e.save(doc=doc, skip=True, update_ts=False)
flash(t(".equipment_out_successfully"), "success")
dp = e.department
pj = e.project
send_mail(
subject=t("notifications.equipment_was_out"),
to=User.get_emails("project_leader", dp, pj, "io"),
cc=User.get_emails("store_user", dp, pj, "io"),
template="asset_out.html",
values=dict(asset=e, io=io),
)
return redirect(url_for(".index", kind="out"))
fill_form_error(form, io)
return render_template("iorecords/equipment_out.html", form=form, equipment=e)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:52,代码来源:iorecords.py
示例17: sparepart_in
def sparepart_in():
form = BackSparepartForm()
fill_sp_choices(form, "in")
if form.validate_on_submit():
code = form.code_text.data.strip().upper() or form.code.data
sp = Sparepart.find_one(spec=dict(code=code))
if not sp:
form.code_text.errors = ["not_found"]
else:
good_qty = form.good.data
bad_qty = form.bad.data
io = create_io(form)
io.update(
kind="1",
is_out=False,
department=sp.department,
project=sp.project,
name=sp.name,
asset=dict(code=code, pn=sp.pn, iogood=good_qty, iobad=bad_qty),
)
io.save()
if io.is_valid:
good_out = sp.out_good - good_qty
bad_out = sp.out_bad - bad_qty
if good_out < 0:
good_out = 0
if bad_out < 0:
bad_out = 0
doc = dict(
store_good=sp.store_good + good_qty,
store_bad=sp.store_bad + bad_qty,
out_good=good_out,
out_bad=bad_out,
)
sp.save(doc=doc, skip=True, update_ts=False)
flash(t(".sparepart_in_successfully"), "success")
dp = sp.department
pj = sp.project
send_mail(
subject=t("notifications.sparepart_was_in"),
to=User.get_emails("project_leader", dp, pj, "io"),
cc=User.get_emails("store_user", dp, pj, "io"),
template="asset_in.html",
values=dict(asset=sp, io=io),
)
return redirect(url_for(".index", kind="in"))
fill_form_error(form, io)
return render_template("iorecords/sparepart_in.html", form=form, code_desc=get_sp_desc(form.code.data))
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:52,代码来源:iorecords.py
示例18: destroy
def destroy(id):
user = User.find_one(id)
if user is None:
flash(t('record_not_found'), 'error')
elif g.user.can_remove_user(user):
if user.canbe_removed:
user.destroy()
flash(t('destroyed_successfully'), 'success')
else:
flash(t('cannot_be_removed'), 'error')
else:
flash(t('permission_denied'), 'error')
return redirect(url_for('.index'))
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:14,代码来源:users.py
示例19: equipment_in
def equipment_in():
form = BackEquipmentForm()
form.is_good.choices = [("good", t("good")), ("bad", t("bad"))]
e = None
if form.validate_on_submit():
flex_id = form.flex_id.data.strip().upper()
spec = dict(flex_id=flex_id)
e = Equipment.find_one(spec=spec)
if e is None:
form.flex_id.errors = ["not_found"]
elif e.is_instore:
form.flex_id.errors = [".already_in_store"]
elif not g.user.can_io_asset(e):
form.flex_id.errors = ["permission_denied"]
else:
io = create_io(form)
io.update(
is_out=False,
kind="0",
department=e.department,
project=e.project,
name=e.name,
asset=dict(
back_to=form.location.data,
iogood=form.is_good.data == "good",
flex_id=flex_id,
sn=e.sn,
fixed_id=e.fixed_id,
model=e.model,
),
)
io.save()
if io.is_valid:
doc = dict(is_instore=True, location=form.location.data, line="")
e.save(doc=doc, skip=True, update_ts=False)
flash(t(".equipment_in_successfully"), "success")
dp = e.department
pj = e.project
send_mail(
subject=t("notifications.equipment_was_in"),
to=User.get_emails("project_leader", dp, pj, "io"),
cc=User.get_emails("store_user", dp, pj, "io"),
template="asset_in.html",
values=dict(asset=e, io=io),
)
return redirect(url_for(".index", kind="in"))
fill_form_error(form, io)
return render_template("iorecords/equipment_in.html", form=form, equipment=e)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:50,代码来源:iorecords.py
示例20: export
def export():
spec = session.get('espec')
form = ExportForm()
if request.method == 'POST':
dbkeys = request.values.getlist('dbkey')
session['echecked'] = dbkeys
if not dbkeys:
flash(t('no_field_was_selected'), 'error')
return render_template('equipment/export.html',
fields=get_fields(),
form=form,
checked=session['echecked'] or [None],
)
wb = Workbook()
ws = wb.add_sheet('Equipment List')
fill_header(ws, dbkeys)
objs = Equipment.find(spec=spec, sort='department, project, flex_id')
row = 1
for e in objs:
for i, k in enumerate(dbkeys):
if k == 'is_good':
ws.write(row, i, t('good' if e.is_good else 'bad'))
elif k == 'is_instore':
ws.write(row, i, t('yes' if e.is_instore else 'no'))
else:
ws.write(row, i, getattr(e, k))
row += 1
file_name = 'Equipment 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('espec', None)
wb.save(file_path)
return send_from_directory(file_dir,
file_name,
as_attachment=True,
attachment_filename=file_name,
)
return render_template('equipment/export.html',
fields=get_fields(),
form=form,
checked=session.get('echecked', []),
)
开发者ID:hlzz23,项目名称:AssetSystem,代码行数:49,代码来源:equipment.py
注:本文中的assetapp.t函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论