本文整理汇总了Python中viaduct.api.group.GroupPermissionAPI.can_read方法的典型用法代码示例。如果您正苦于以下问题:Python GroupPermissionAPI.can_read方法的具体用法?Python GroupPermissionAPI.can_read怎么用?Python GroupPermissionAPI.can_read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类viaduct.api.group.GroupPermissionAPI
的用法示例。
在下文中一共展示了GroupPermissionAPI.can_read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def edit(company_id=None):
'''
FRONTEND
Create, view or edit a company.
'''
if not GroupPermissionAPI.can_read('company'):
return abort(403)
# Select company.
if company_id:
company = Company.query.get(company_id)
else:
company = Company()
form = CompanyForm(request.form, company)
# Add locations.
locations = Location.query.order_by('address').order_by('city')
form.location_id.choices = \
[(l.id, l.address + ', ' + l.city) for l in locations]
# Add contacts.
# form.contact_id.choices = \
# [(c.id, c.name) for c in Contact.query\
# .filter_by(location=location).order_by('name')]
form.contact_id.choices = \
[(c.id, c.name) for c in Contact.query.filter_by().order_by('name')]
return render_template('company/edit.htm', company=company, form=form)
示例2: get_navigation_menu
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def get_navigation_menu(group_id, personal, type):
if not GroupPermissionAPI.can_read('pimpy'):
abort(403)
if not current_user:
flash('Huidige gebruiker niet gevonden!', 'danger')
return redirect(url_for('pimpy.view_minutes'))
groups = current_user.groups\
.filter(Group.name != 'all').order_by(Group.name.asc()).all()
if not type:
type = 'minutes'
endpoint = 'pimpy.view_' + type
endpoints = {'view_chosentype': endpoint,
'view_chosentype_personal': endpoint + '_personal',
'view_chosentype_chosenpersonal': endpoint +
('_personal' if personal and type != 'minutes' else ''),
'view_tasks': 'pimpy.view_tasks',
'view_tasks_personal': 'pimpy.view_tasks_personal',
'view_tasks_chosenpersonal': 'pimpy.view_tasks',
'view_minutes': 'pimpy.view_minutes'}
if personal:
endpoints['view_tasks_chosenpersonal'] += '_personal'
if not group_id:
group_id = 'all'
if group_id != 'all':
group_id = int(group_id)
return Markup(render_template('pimpy/api/side_menu.htm', groups=groups,
group_id=group_id, personal=personal,
type=type, endpoints=endpoints,
title='PimPy'))
示例3: view_single
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def view_single(user_id=None):
if not GroupPermissionAPI.can_read('user') and\
(not current_user or current_user.id != user_id):
return abort(403)
if not user_id:
return abort(404)
user = User.query.get(user_id)
if not user:
return abort(404)
user.avatar = UserAPI.avatar(user)
user.groups = UserAPI.get_groups_for_user_id(user)
user.groups_amount = user.groups.count()
# Get all activity entrees from these forms, order by start_time of
# activity.
activities = Activity.query.join(CustomForm).join(CustomFormResult).\
filter(CustomFormResult.owner_id == user_id and
CustomForm.id == CustomFormResult.form_id and
Activity.form_id == CustomForm.id)
user.activities_amount = activities.count()
new_activities = activities\
.filter(Activity.end_time > datetime.datetime.today()).distinct()\
.order_by(Activity.start_time)
old_activities = activities\
.filter(Activity.end_time < datetime.datetime.today()).distinct()\
.order_by(Activity.start_time.desc())
return render_template('user/view_single.htm', user=user,
new_activities=new_activities,
old_activities=old_activities)
示例4: view
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def view():
if not GroupPermissionAPI.can_read('navigation'):
return abort(403)
entries = NavigationAPI.get_entries()
return render_template('navigation/view.htm', nav_entries=entries)
示例5: get_minutes
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def get_minutes(group_id):
"""
Load all minutes in the given group
"""
if not GroupPermissionAPI.can_read('pimpy'):
abort(403)
if not current_user:
flash('Huidige gebruiker niet gevonden', 'danger')
return redirect(url_for('pimpy.view_minutes'))
list_items = {}
if group_id != 'all':
query = Minute.query.filter(Minute.group_id == group_id).\
order_by(Minute.minute_date.desc())
list_items[Group.query.filter(Group.id == group_id).first().name]\
= query.all()
# this should be done with a sql in statement, or something, but meh
else:
for group in current_user.groups:
query = Minute.query.filter(Minute.group_id == group.id)
query = query.order_by(Minute.minute_date.desc())
list_items[group.name] = query.all()
return Markup(render_template('pimpy/api/minutes.htm',
list_items=list_items, type='minutes',
group_id=group_id, line_number=-1,
title='PimPy'))
示例6: new_submission
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def new_submission(challenge_id=None):
if not GroupPermissionAPI.can_read('challenge'):
abort(403)
if request.args.get('challenge_id'):
challenge_id = request.args.get('challenge_id')
else:
return "Error, no 'challenge_id' given"
if request.args.get('submission'):
submission = request.args.get('submission')
else:
return "Error, no 'submission' given"
new_submission = ChallengeAPI.create_submission(challenge_id=challenge_id,
user_id=current_user.id,
submission=submission,
image_path=None)
if new_submission is False:
return "Question is already submitted"
challenge = ChallengeAPI.fetch_challenge(challenge_id)
return ChallengeAPI.validate_question(new_submission, challenge)
示例7: can_view
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def can_view(entry):
'''
Check whether the current user can view the entry, so if not it can be
removed from the navigation.
'''
blueprints = [(name, b.url_prefix) for name, b in
application.blueprints.iteritems()]
if entry.external or entry.activity_list:
return True
url = entry.url
if not url[-1:] == '/':
path = url
url += '/'
else:
path = url[:-1]
for blueprint, url_prefix in blueprints:
if not url_prefix:
continue
if url_prefix == url:
return GroupPermissionAPI.can_read(blueprint)
page = Page.query.filter_by(path=path).first()
if not page:
return True
return UserAPI.can_read(page)
示例8: get_ranking
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def get_ranking():
if not GroupPermissionAPI.can_read('challenge'):
abort(403)
ranking = ChallengeAPI.get_ranking()
return jsonify(ranking=[user.serialize for user in ranking])
示例9: get_list_of_users_from_string
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def get_list_of_users_from_string(group_id, comma_sep):
"""
Parses a string which is a list of comma separated user names
to a list of users, searching only within the group given
Returns users, message. Users is false if there is something wrong,
in which case the message is stated in message, otherwise message
equals "" and users is the list of matched users
usage:
get_list_of_users_from_string(group_id, comma_sep)
where group_id is the group's id
and comma_sep is a string with comma seperated users.
"""
if not GroupPermissionAPI.can_read('pimpy'):
abort(403)
group = Group.query.filter(Group.id == group_id).first()
if group is None:
return False, "Kan groep niet vinden."
if comma_sep is None:
return False,
"Geen komma gescheiden lijst met gebruikers gevonden."
if not comma_sep:
return group.users.all(), ''
comma_sep = map(lambda x: x.lower().strip(), comma_sep.split(','))
found_users = []
users = group.users.all()
user_names = map(lambda x: "%s %s" % (x.first_name.lower().strip(),
x.last_name.lower().strip()),
users)
user_names = [unidecode(x) for x in user_names]
for comma_sep_user in comma_sep:
match = extractOne(comma_sep_user, user_names)
found = False
if not match:
return False, \
'Kon geen gebruiker vinden voor: %s' % (comma_sep_user)
for i in range(len(users)):
# could use a filter here, but meh
if user_names[i] == match[0]:
found_users.append(users[i])
found = True
break
if not found:
return False, \
'Kon geen gebruiker vinden voor %s' % (comma_sep_user)
return found_users, ""
示例10: search
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def search(query):
'''
Fuzzy search files.
'''
if not GroupPermissionAPI.can_read('file'):
return jsonify(error='Geen toestemming')
return jsonify(filenames=FileAPI.search(query))
示例11: get_activity
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def get_activity(activity_id=0):
if not GroupPermissionAPI.can_read('activity'):
return abort(403)
activity = Activity.query.get(activity_id)
if not activity:
return abort(404)
form = ActivityForm(request.form, current_user)
# Add education for activity form
educations = Education.query.all()
form.education_id.choices = \
[(e.id, e.name) for e in educations]
# Check if there is a custom_form for this activity
if activity.form_id:
# Add the form
activity.form = CustomForm.query.get(activity.form_id)
# Count current attendants for "reserved" message
entries = CustomFormResult.query.filter(CustomFormResult.form_id ==
activity.form_id)
activity.num_attendants = entries.count()
# Check if the current user has already entered data in this custom
# form
if current_user and current_user.id > 0:
form_result = CustomFormResult.query \
.filter(CustomFormResult.form_id == activity.form_id) \
.filter(CustomFormResult.owner_id == current_user.id).first()
if form_result:
activity.form_data = form_result.data.replace('"', "'")
if not form_result.has_payed:
if form_result.form.price > 1.20:
activity.form.show_pay_button = True
activity.form.id = form_result.id
if form_result.has_payed:
activity.info = "Je hebt je al ingeschreven en betaald!"\
" je kunt wel je inschrijving aanpassen door opniew "\
"het formulier in te vullen en te verzenden."
else:
activity.info = "Je hebt je al ingeschreven! Je moet nog "\
"wel betalen!"
else:
if activity.num_attendants >= activity.form.max_attendants:
activity.info = "De activiteit zit vol qua "\
"inschrijvingen, als je je nu inschrijft kom je op "\
"de reserve lijst!"
else:
activity.info = "Er zijn op het moment %s "\
"inschrijvingen" % activity.num_attendants
return render_template('activity/view_single.htm', activity=activity,
form=form, login_form=get_login_form())
示例12: list
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def list(page=1):
'''
Show a paginated list of contacts.
'''
if not GroupPermissionAPI.can_read('contact'):
return abort(403)
contacts = Contact.query.paginate(page, 15, False)
return render_template('contact/list.htm', contacts=contacts)
示例13: view_task_archive
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def view_task_archive(group_id='all'):
"""
Shows all tasks ever made.
Can specify specific group.
No internal permission system made yet.
Do not make routes to this module yet.
"""
if not GroupPermissionAPI.can_read('pimpy'):
return abort(403)
return PimpyAPI.get_all_tasks(group_id)
示例14: user_export
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def user_export():
if not GroupPermissionAPI.can_read('user'):
return abort(403)
users = User.query.all()
si = StringIO()
cw = writer(si)
cw.writerow([c.name for c in User.__mapper__.columns])
for user in users:
cw.writerow([getattr(user, c.name) for c in User.__mapper__.columns])
return si.getvalue().strip('\r\n')
示例15: list
# 需要导入模块: from viaduct.api.group import GroupPermissionAPI [as 别名]
# 或者: from viaduct.api.group.GroupPermissionAPI import can_read [as 别名]
def list(page_nr=1):
'''
List all files that are not assigned to a page.
'''
if not GroupPermissionAPI.can_read('file'):
return abort(403)
files = File.query.filter_by(page=None).order_by(File.name)\
.paginate(page_nr, 30, False)
form = FileForm()
return render_template('files/list.htm', files=files, form=form)