本文整理汇总了Python中viaduct.api.group.GroupPermissionAPI.can_write方法的典型用法代码示例。如果您正苦于以下问题:Python GroupPermissionAPI.can_write方法的具体用法?Python GroupPermissionAPI.can_write怎么用?Python GroupPermissionAPI.can_write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viaduct.api.group.GroupPermissionAPI
的用法示例。
在下文中一共展示了GroupPermissionAPI.can_write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def delete(entry_id, inc_page=0):
if not GroupPermissionAPI.can_write('navigation'):
return abort(403)
if inc_page and not GroupPermissionAPI.can_write('page'):
return abort(403)
entry = db.session.query(NavigationEntry).filter_by(id=entry_id).first()
if not entry:
abort(404)
if not entry.parent:
if entry.children.count() > 0:
flash('Deze item heeft nog subitems.', 'danger')
return redirect(url_for('navigation.edit', entry_id=entry.id))
if inc_page:
if entry.external or entry.activity_list:
flash('Deze item verwijst niet naar een pagina op deze website.',
'danger')
else:
path = entry.url.lstrip('/')
if PageAPI.remove_page(path):
flash('De pagina is verwijderd.', 'success')
else:
flash('De te verwijderen pagina kon niet worden gevonden.',
'danger')
db.session.delete(entry)
db.session.commit()
flash('De navigatie-item is verwijderd.', 'success')
return redirect(url_for('navigation.view'))
示例2: view_list
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def view_list(page=1):
if not GroupPermissionAPI.can_read('company'):
return abort(403)
if request.args.get('search') is not None:
search = request.args.get('search')
companies = Company.query.join(Location)\
.filter(or_(Company.name.like('%' + search + '%'),
Location.city.like('%' + search + '%')))\
.order_by(Company.name).order_by(Company.rank)
if not GroupPermissionAPI.can_write('company'):
companies = companies\
.filter(and_(Company.contract_start_date < datetime.utcnow(),
Company.contract_end_date > datetime.utcnow()))\
.paginate(page, 15, True)
else:
for i, company in enumerate(companies):
print(i, company)
if company.contract_start_date < datetime\
.date(datetime.utcnow()) and \
company.contract_end_date < datetime\
.date(datetime.utcnow()):
companies[i].expired = True
companies = companies.paginate(page, 15, False)
return render_template('company/list.htm', companies=companies,
search=search, path=FILE_FOLDER)
if not GroupPermissionAPI.can_write('company'):
companies = Company.query\
.filter(and_(Company.contract_start_date < datetime.utcnow(),
Company.contract_end_date > datetime.utcnow()))\
.order_by(Company.name).order_by(Company.rank).paginate(page, 15,
True)
else:
companies = Company.query.filter().order_by(Company.name)\
.order_by(Company.rank)
for i, company in enumerate(companies):
print(i, company)
if company.contract_start_date < datetime.date(datetime.utcnow()) \
and company.contract_end_date < datetime.date(datetime
.utcnow()):
print(i)
companies[i].expired = True
companies = companies.paginate(page, 15, False)
# todo fix message if inactive
# companies = Company.query.paginate(page, 15, False)
return render_template('company/list.htm', companies=companies, search="",
path=FILE_FOLDER)
示例3: commit_book_to_db
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def commit_book_to_db(book_id, title, price, isbn, stock):
"""
Adds a new book to the database
Returns succes(boolean), message (string). Message is the book.id if
succes is true, otherwise it contains what exactly went wrong.
In case of succes the book is entered into the database
"""
if not GroupPermissionAPI.can_write('booksales'):
abort(403)
if book_id == -1:
book = Book(title, price, isbn, stock)
db.session.add(book)
db.session.commit()
return True, book.id
book = Book.query.filter(Book.id == book_id).first()
book.title = title
book.price = price
book.isbn = isbn
book.stock = stock
db.session.add(book)
db.session.commit()
return True, book.id
示例4: remove_avatar
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def remove_avatar(user_id=None):
user = User.query.get(user_id)
if not GroupPermissionAPI.can_write('user') and\
(not current_user or current_user.id != user_id):
return abort(403)
UserAPI.remove_avatar(user)
return redirect(url_for('user.view_single', user_id=user_id))
示例5: create
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def create():
if not(GroupPermissionAPI.can_write('group')):
return abort(403)
if request.method == 'POST':
name = request.form['name'].strip()
valid_form = True
if not name:
flash('No group name has been specified.', 'danger')
valid_form = False
elif Group.query.filter(Group.name == name).count() > 0:
flash('The group name that has been specified is in use already.',
'danger')
valid_form = False
if valid_form:
group = Group(name)
db.session.add(group)
db.session.commit()
flash('The group has been created.', 'success')
return redirect(url_for('group.view'))
return render_template('group/create.htm', title='Create group')
示例6: view
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def view():
page = request.args.get('page_nr', '')
if not page:
page = 1
else:
page = int(page)
if not GroupPermissionAPI.can_write('custom_form'):
return abort(403)
custom_forms = CustomForm.query.order_by(desc("id"))
if current_user and current_user.id > 0:
follows = CustomFormFollower.query\
.filter(CustomFormFollower.owner_id == current_user.id).all()
ids = []
for follow in follows:
ids.append(follow.form_id)
followed_forms = CustomForm.query.filter(CustomForm.id.in_(ids)).all()
else:
followed_forms = []
ids = []
# TODO Custom forms for specific groups (i.e coordinator can only see own
# forms)
return render_template('custom_form/overview.htm',
custom_forms=custom_forms.paginate(page, 20, False),
followed_forms=followed_forms, followed_ids=ids)
示例7: has_payed
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def has_payed(submit_id=None):
response = "success"
if not GroupPermissionAPI.can_write('custom_form'):
return abort(403)
# Logged in user
if not current_user or current_user.id <= 0:
# Need to be logged in
return abort(403)
# Test if user already signed up
submission = CustomFormResult.query.filter(
CustomFormResult.id == submit_id
).first()
if not submission:
response = "Error, submission could not be found"
# Adjust the "has_payed"
if submission.has_payed:
submission.has_payed = False
else:
submission.has_payed = True
db.session.add(submission)
db.session.commit()
return response
示例8: update
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def update(contact_id=None):
'''
Create or edit a contact, backend.
'''
if not GroupPermissionAPI.can_write('contact'):
return abort(403)
if contact_id:
contact = Contact.query.get(contact_id)
else:
contact = Contact()
form = ContactForm(request.form, contact)
if not validate_form(form, ['name', 'email', 'phone_nr', 'location_id']):
return redirect(url_for('contact.edit', contact_id=contact_id))
form.populate_obj(contact)
db.session.add(contact)
db.session.commit()
if contact_id:
flash('Contactpersoon opgeslagen', 'success')
else:
contact_id = contact.id
flash('Contactpersoon aangemaakt', 'success')
return redirect(url_for('contact.edit', contact_id=contact_id))
示例9: create_challenge
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def create_challenge(challenge_id=None):
if not GroupPermissionAPI.can_write('challenge'):
abort(403)
# Gather all arguments
if request.args.get('parent_id'):
parent_id = request.args.get('parent_id')
else:
return "Error, no 'parent_id' given"
if request.args.get('name'):
name = request.args.get('name')
else:
return "Error, no 'name' given"
if request.args.get('description'):
description = request.args.get('description')
else:
return "Error, no 'description' given"
if request.args.get('type'):
type = request.args.get('type')
else:
return "Error, no 'type' given"
if request.args.get('start_date'):
start_date = datetime.datetime.strptime(request.args.get('start_date'),
'%Y-%m-%d').date()
else:
return "Error, no 'start_date' given"
if request.args.get('end_date'):
end_date = datetime.datetime.strptime(request.args.get('end_date'),
'%Y-%m-%d').date()
else:
return "Error, no 'end_date' given"
if request.args.get('answer'):
answer = request.args.get('answer')
else:
return "Error, no 'answer' given"
if request.args.get('weight'):
weight = request.args.get('weight')
else:
return "Error, no 'weight' given"
if request.args.get('hint'):
hint = request.args.get('hint')
else:
return "Error, no 'hint' given"
# Check if the name of the challenge is unique
if ChallengeAPI.challenge_exists(name):
return "Error, challenge with name '" + name + "' already exists"
return ChallengeAPI.create_challenge(name, description, hint, start_date,
end_date, parent_id, weight, type,
answer)
示例10: fetch_all
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def fetch_all():
if not GroupPermissionAPI.can_write('challenge'):
abort(403)
challenges = ChallengeAPI.fetch_all_challenges()
return jsonify(challenges=[challenge.serialize for challenge in
challenges])
示例11: reorder
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def reorder():
if not GroupPermissionAPI.can_write('navigation'):
return abort(403)
entries = json.loads(request.form['entries'])
NavigationAPI.order(entries, None)
return ""
示例12: upload
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def upload(page_nr=1):
'''
Upload a file.
'''
if not GroupPermissionAPI.can_write('file'):
return abort(403)
new_file = request.files['file']
FileAPI.upload(new_file)
return redirect(url_for('file.list', page_nr=page_nr))
示例13: update_task_status
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def update_task_status():
if not GroupPermissionAPI.can_write('pimpy'):
return abort(403)
task_id = request.args.get('task_id', 0, type=int)
new_status = request.args.get('new_status', 0, type=int)
query = Task.query
query = query.filter(Task.id == task_id)
list_items = query.all()
for task in list_items:
task.update_status(new_status)
return jsonify(status=task.get_status_color())
示例14: upload_file
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def upload_file():
if not GroupPermissionAPI.can_write('examination'):
session['prev'] = 'examination.upload_file'
return abort(403)
courses = Course.query.all()
educations = Education.query.all()
if request.method == 'POST':
file = request.files['file']
answers = request.files['answers']
title = request.form.get("title", None)
course_id = request.form.get("course", None)
education_id = request.form.get("education", None)
error = False
if not title:
flash('Geen titel opgegeven', 'danger')
error = True
filename = upload_file_real(file)
if file:
if not filename:
flash('Fout formaat tentamen', 'danger')
error = True
answer_path = upload_file_real(answers)
if not answer_path:
flash('Fout formaat antwoorden', 'danger')
error = True
else:
flash('Geen tentamen opgegeven', 'danger')
error = True
if error:
return render_template('examination/upload.htm', courses=courses,
educations=educations, message='',
title='Tentamens')
exam = Examination(filename, title, course_id, education_id,
answers=answer_path)
db.session.add(exam)
db.session.commit()
flash('Het tentamen is geupload', 'success')
return render_template('examination/upload.htm', courses=courses,
educations=educations, message='',
title='Tentamens')
return render_template('examination/upload.htm', courses=courses,
educations=educations, title='Tentamens')
示例15: edit_book
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_write [as 别名]
def edit_book(book_id, title, price, isbn, stock):
if not GroupPermissionAPI.can_write('booksales'):
abort(403)
book = Book.query.filter(Book.id == book_id).first()
book.title = title
book.price = price
book.isbn = isbn
book.stock = stock
db.session.add(book)
db.session.commit()
return True, book.id