本文整理汇总了Python中mig_main.utility.Permissions类的典型用法代码示例。如果您正苦于以下问题:Python Permissions类的具体用法?Python Permissions怎么用?Python Permissions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Permissions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_permissions
def get_permissions(user):
permission_dict = {
'can_edit_mindset': Permissions.can_update_mindset_materials(user),
'can_edit_outreach': user.is_superuser,
'can_edit_profiles': Permissions.can_manage_officers(user),
}
return permission_dict
开发者ID:dadrian,项目名称:mig-website,代码行数:7,代码来源:views.py
示例2: get_permissions
def get_permissions(user):
permission_dict = get_member_permissions(user)
permission_dict.update(
{
"can_create_groups": Permissions.can_manage_electee_progress(user),
"can_edit_resources": Permissions.can_manage_electee_progress(user),
}
)
return permission_dict
开发者ID:kylelady,项目名称:mig-website,代码行数:9,代码来源:views.py
示例3: get_permissions
def get_permissions(user):
permission_dict={
'can_post':Permissions.can_post_web_article(user),
'can_edit':Permissions.can_approve_web_article(user),
'post_button':Permissions.can_upload_articles(user),
'is_member':hasattr(user,'userprofile') and user.userprofile.is_member(),
'can_process_project_reports': Permissions.can_process_project_reports(user),
}
return permission_dict
开发者ID:pritpaul,项目名称:mig-website,代码行数:9,代码来源:views.py
示例4: get_permissions
def get_permissions(user):
permission_dict=get_member_permissions(user)
is_member=False
if hasattr(user,'userprofile') and user.userprofile.is_member():
is_member=True
permission_dict.update({'can_create_thread':Permissions.can_create_thread(user),
'can_create_forum':Permissions.can_create_forum(user),
'can_comment':hasattr(user,'userprofile') and user.userprofile.is_member(),
'can_moderate':Permissions.can_create_forum(user),
'can_downvote':get_user_points(user.userprofile.memberprofile)>0 if is_member else False})
return permission_dict
开发者ID:mrealm,项目名称:mig-website,代码行数:12,代码来源:views.py
示例5: get_permissions
def get_permissions(user):
"""
Standardized way of querying user permissions across the website.
Permissions for the entire (or most of it) module are loaded into
a dictionary that gets merged with the template context to provide
the template with a list of permissions so as to generate the page
correctly.
"""
permission_dict = {
'can_edit_about_photos': Permissions.can_manage_website(user),
'can_edit_bylaws': Permissions.can_manage_bylaws(user),
}
return permission_dict
开发者ID:tbpmig,项目名称:mig-website,代码行数:13,代码来源:views.py
示例6: get_article_view
def get_article_view(request,article_id):
request.session['current_page']=request.path
today = date.today()
web_articles = WebsiteArticle.get_stories()
if Permissions.can_post_web_article(request.user):
NewArticleForm = modelform_factory(WebsiteArticle,form=WebArticleForm)
if request.method == 'POST':
form = NewArticleForm(request.POST)
if form.is_valid():
a=form.save()
if Permissions.can_approve_web_article(request.user):
a.approved=True
a.save()
request.session['success_message']='Your webstory was posted successfully'
else:
request.session['success_message']='Your webstory has been submitted and is awaiting approval'
if hasattr(request.user,'userprofile') and request.user.userprofile.is_member():
a.created_by = request.user.userprofile.memberprofile
a.save()
tweet_option = form.cleaned_data.pop('tweet_option','N')
if tweet_option=='T':
a.tweet_story(False)
elif tweet_option=='H':
a.tweet_story(True)
return get_previous_page(request, 'history:index')
else:
request.session['error_message']='There were errors in your submission. Please correct the noted errors.'
else:
form = NewArticleForm(initial={'date_posted':today})
else:
form = None
template = loader.get_template('history/publications.html')
if not article_id:
if web_articles:
article_id=web_articles[0].id
else:
article_id=0
context_dict = {
'web_articles':web_articles,
'main_id':int(article_id),
'form':form,
'subnav':'news',
'event_photos': (EventPhoto.objects.all() if form else None),
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:pritpaul,项目名称:mig-website,代码行数:48,代码来源:views.py
示例7: manually_edit_electee_group_membership
def manually_edit_electee_group_membership(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit electee teams'
return redirect('electees:view_electee_groups')
e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
prefix = 'manual_groups'
term =AcademicTerm.get_current_term()
formset=ManualElecteeGroupMembersFormSet(request.POST or None,prefix=prefix,queryset=ElecteeGroup.objects.filter(term=term))
if request.method=='POST':
if formset.is_valid():
formset.save()
request.session['success_message']='Electee team membership updated successfully'
return redirect('electees:view_electee_groups')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'prefix':prefix,
'subsubnav':'members',
'has_files':False,
'submit_name':'Update Electee Team Membership',
'form_title':'Add Electee Team Members',
'help_text':'Add members to electee teams. This is for initial addition only, for edits use the drag-and-drop interface.',
'can_add_row':False,
'base':'electees/base_electees.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:dadrian,项目名称:mig-website,代码行数:31,代码来源:views.py
示例8: edit_electee_group_membership
def edit_electee_group_membership(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit electee teams'
return redirect('electees:view_electee_groups')
if request.method =='POST':
electee_groups_json=request.POST['electee_groups']
electee_groups = json.loads(electee_groups_json)
for group_id in electee_groups:
members = electee_groups[group_id]
group = ElecteeGroup.objects.get(id=group_id)
group.members.clear()
for member in members:
group.members.add(MemberProfile.objects.get(uniqname=member))
request.session['success_message']='Your changes have been saved'
e_groups = ElecteeGroup.objects.filter(term=AcademicTerm.get_current_term())
template = loader.get_template('electees/edit_electee_group_membership.html')
context_dict = {
'electee_groups':e_groups,
'unassigned_electees':get_unassigned_electees(),
'subsubnav':'members',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:dadrian,项目名称:mig-website,代码行数:26,代码来源:views.py
示例9: accept_or_decline_nomination
def accept_or_decline_nomination(request, nomination_id):
""" 'View' that gets visited when an individual accepts/declines a
nomination.
"""
if not Permissions.can_nominate(request.user):
request.session['error_message'] = messages.ELECTION_NO_ACCEPT_PERM
return redirect('elections:index')
nom = get_object_or_404(Nomination, id=nomination_id)
if not nom.nominee == request.user.userprofile.memberprofile:
request.session['error_message'] = ('You can only accept or decline '
'your own nominations.')
return redirect('elections:index')
if request.method == 'POST':
request_body = request.POST
else:
request_body = request.GET
if request_body.__contains__('accept'):
accepted = (request_body.__getitem__('accept') == 'YES')
nom.accepted = accepted
nom.save()
return HttpResponseRedirect(
reverse('elections:my_nominations',
args=(nom.election.id,))
)
开发者ID:tbpmig,项目名称:mig-website,代码行数:26,代码来源:views.py
示例10: upload_article
def upload_article(request):
""" Upload a printed article """
if not Permissions.can_upload_articles(request.user):
raise PermissionDenied()
form = ArticleForm(request.POST or None, request.FILES or None)
if request.method == 'POST':
if form.is_valid():
form.save()
request.session['success_message'] = ('Article uploaded '
'successfully')
return get_previous_page(request, 'history:cornerstone_view')
else:
request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
template = loader.get_template('generic_form.html')
context_dict = {
'form': form,
'subnav': 'cornerstone',
'has_files': True,
'submit_name': 'Upload Printed Publication',
'form_title': 'Upload Article',
'help_text': 'Make sure to specify the type of publication.',
'base': 'history/base_history.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
return HttpResponse(template.render(context_dict, request))
开发者ID:tbpmig,项目名称:mig-website,代码行数:26,代码来源:views.py
示例11: update_corporate_page
def update_corporate_page(request):
if not Permissions.can_edit_corporate_page(request.user):
request.session['error_message'] = 'You are not authorized to edit the corporate page'
return redirect('corporate:index')
prefix = 'corporate_page'
CorporateTextForm = modelformset_factory(CorporateTextField,
extra=1, exclude=[])
formset = CorporateTextForm(request.POST or None,prefix=prefix)
if request.method == 'POST':
if formset.is_valid():
instances = formset.save()
request.session['success_message'] = 'Corporate page successfully updated.'
return redirect('corporate:index')
else:
request.session['error_message'] = FORM_ERROR
context_dict = {
'formset': formset,
'subnav': 'index',
'prefix': prefix,
'has_files': False,
'submit_name': 'Update Corporate Page',
'back_button': {'link': reverse('corporate:index'),
'text': 'To Corporate Page'},
'form_title': 'Edit Corporate Page Text',
'help_text': ('The text shown on the corporate main page. This text '
'uses markdown syntax.'),
'can_add_row': False,
'base': 'corporate/base_corporate.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
template = loader.get_template('generic_formset.html')
return HttpResponse(template.render(context))
开发者ID:dadrian,项目名称:mig-website,代码行数:34,代码来源:views.py
示例12: edit_electee_resources
def edit_electee_resources(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit electee resources.'
return redirect('electees:view_electee_groups')
ResourceFormSet = modelformset_factory(ElecteeResource,exclude=('term',),can_delete=True)
term =AcademicTerm.get_current_term()
if request.method =='POST':
formset = ResourceFormSet(request.POST,request.FILES,prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
if formset.is_valid():
instances=formset.save(commit=False)
for obj in formset.deleted_objects:
obj.delete()
for instance in instances:
instance.term=term
instance.save()
request.session['success_message']='Electee resources updated successfully'
return redirect('electees:view_electee_groups')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
else:
formset = ResourceFormSet(prefix='resources',queryset=ElecteeResource.objects.filter(term=term))
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'prefix':'resources',
'has_files':True,
'submit_name':'Update Electee Resources',
'form_title':'Update/Add/Remove Electee Resources for %s'%(unicode(term)),
'help_text':'These are the full packets and their constituent parts. If you need a part that isn\'t listed here, contact the web chair.',
'can_add_row':True,
'base':'electees/base_electees.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
return HttpResponse(template.render(context_dict, request))
开发者ID:tbpmig,项目名称:mig-website,代码行数:35,代码来源:views.py
示例13: edit_electee_process_visibility
def edit_electee_process_visibility(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit the electee process visibility settings.'
return redirect('electees:view_electee_groups')
current_vis = ElecteeProcessVisibility.objects.get_or_create(term=AcademicTerm.get_current_term())
VisibilityForm = modelform_factory(ElecteeProcessVisibility,exclude=['term'])
prefix='visibility'
form = VisibilityForm(request.POST or None ,prefix=prefix,instance=current_vis[0])
if request.method =='POST':
if form.is_valid():
form.save()
request.session['success_message']='Electee settings updated successfully'
return redirect('electees:manage_survey')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
template = loader.get_template('generic_form.html')
context_dict = {
'form':form,
'prefix':prefix,
'has_files':False,
'submit_name':'Update Visibility Settings',
'form_title':'Update Electee Visibility Settings for %s'%(unicode(AcademicTerm.get_current_term())),
'help_text':'Change whether certain electee items are visible to all actives.',
'base':'electees/base_electees.html',
'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:dadrian,项目名称:mig-website,代码行数:31,代码来源:views.py
示例14: edit_survey_parts
def edit_survey_parts(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit the electee survey.'
return redirect('electees:view_electee_groups')
SurveyPartFormSet = modelformset_factory(SurveyPart, exclude=[])
prefix='surveyparts'
if request.method =='POST':
formset = SurveyPartFormSet(request.POST,prefix=prefix,queryset=SurveyPart.objects.all())
if formset.is_valid():
formset.save()
request.session['success_message']='Electee interview survey parts updated successfully'
return redirect('electees:manage_survey')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
else:
formset = SurveyPartFormSet(prefix=prefix,queryset=SurveyPart.objects.all())
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'prefix':prefix,
'has_files':False,
'can_add_row':True,
'submit_name':'Update Electee Survey Parts',
'form_title':'Update Electee Interview Survey Parts',
'help_text':'Add or edit the different parts of the survey. Questions will be associated with a particular part. Only those parts that have questions which appear in a given survey will be included in that survey. There should be no need to remove survey parts. If all questions in a part are required, leave that field blank.',
'base':'electees/base_electees.html',
'back_button':{'link':reverse('electees:manage_survey'),'text':'To Survey Manager'},
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
return HttpResponse(template.render(context_dict, request))
开发者ID:tbpmig,项目名称:mig-website,代码行数:32,代码来源:views.py
示例15: update_mindset_photos
def update_mindset_photos(request):
if not Permissions.can_update_mindset_materials(request.user):
request.session['error_message']='You are not authorized to update MindSET Materials'
return redirect('outreach:mindset')
MindSETPhotoForm = modelformset_factory(OutreachPhoto,can_delete=True)
if request.method=='POST':
formset = MindSETPhotoForm(request.POST,request.FILES,prefix='mindset')
if formset.is_valid():
instances = formset.save()
request.session['success_message']='Photos successfully updated.'
return redirect('outreach:mindset')
else:
request.session['error_message']='Your submission contained errors, please correct and resubmit.'
else:
formset=MindSETPhotoForm(prefix='mindset')
context_dict = {
'formset':formset,
'prefix':'mindset',
'subnav':'mindset',
'has_files':True,
'submit_name':'Update MindSET Photos',
'back_button':{'link':reverse('outreach:mindset'),'text':'To MindSET Page'},
'form_title':'Edit MindSET Photos',
'help_text':'You can update the photos for the MindSET section of the website here.',
'can_add_row':True,
'base':'outreach/base_outreach.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
template = loader.get_template('generic_formset.html')
return HttpResponse(template.render(context))
开发者ID:pritpaul,项目名称:mig-website,代码行数:32,代码来源:views.py
示例16: eligibility
def eligibility(request):
"""
The joining page. The name eligibility is a backwards compatibility to the
old name of the page. Unfortunately changing the view names is a big hassle
as all the links throughout the website are kind of based on those. Shows
text determined by the JoiningTextField table and a static photo that
desperately needs updating.
"""
template = loader.get_template('about/eligibility.html')
eligibility_text = JoiningTextField.objects.filter(section='EL')
ugrad_reqs_text = JoiningTextField.objects.filter(section='UG')
grad_reqs_text = JoiningTextField.objects.filter(section='GR')
why_join_text = JoiningTextField.objects.filter(section='Y')
context_dict = {
'eligibility_text': eligibility_text,
'ugrad_text': ugrad_reqs_text,
'grad_text': grad_reqs_text,
'why_join_text': why_join_text,
'can_edit_page': Permissions.can_manage_electee_progress(request.user),
'subnav': 'joining',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:dadrian,项目名称:mig-website,代码行数:25,代码来源:views.py
示例17: edit_electee_group_membership
def edit_electee_group_membership(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session["error_message"] = "You are not authorized to edit electee groups"
return redirect("electees:view_electee_groups")
if request.method == "POST":
electee_groups_json = request.POST["electee_groups"]
electee_groups = json.loads(electee_groups_json)
for group_id in electee_groups:
members = electee_groups[group_id]
group = ElecteeGroup.objects.get(id=group_id)
group.members.clear()
for member in members:
group.members.add(MemberProfile.objects.get(uniqname=member))
request.session["success_message"] = "Your changes have been saved"
e_groups = ElecteeGroup.objects.filter(term=get_current_term())
template = loader.get_template("electees/edit_electee_group_membership.html")
context_dict = {
"electee_groups": e_groups,
"unassigned_electees": get_unassigned_electees(),
"subsubnav": "members",
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:kylelady,项目名称:mig-website,代码行数:26,代码来源:views.py
示例18: edit_articles
def edit_articles(request):
if not Permissions.can_approve_web_article(request.user):
request.session['error_message']='You are not authorized to edit web articles.'
return redirect('history:index')
prefix='webstories'
WebStoryFormset = modelformset_factory(WebsiteArticle,can_delete=True)
if request.method =='POST':
formset = WebStoryFormset(request.POST,prefix=prefix,queryset = WebsiteArticle.objects.order_by('approved','-date_posted'))
if formset.is_valid():
formset.save()
request.session['success_message']='Web stories updated successfully'
return redirect('history:index')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
else:
formset = WebStoryFormset(prefix=prefix,queryset = WebsiteArticle.objects.order_by('approved','-date_posted'))
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'prefix':prefix,
'has_files':False,
'can_add_row':False,
'submit_name':'Update Website Stories',
'form_title':'Edit Website Stories',
'help_text':'Use this to edit or approve website stories submitted by others, for long stories, make sure to add the <fold> attribute.',
'base':'history/base_history.html',
'back_button':{'link':reverse('history:index'),'text':'To Website Stories'},
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:pritpaul,项目名称:mig-website,代码行数:32,代码来源:views.py
示例19: edit_electee_group_points
def edit_electee_group_points(request):
if not Permissions.can_manage_electee_progress(request.user):
request.session['error_message']='You are not authorized to edit electee team points.'
return redirect('electees:view_electee_groups')
term =AcademicTerm.get_current_term()
GroupPointsFormSet = modelformset_factory(ElecteeGroupEvent,exclude=('related_event_id',),can_delete=True)
GroupPointsFormSet.form.base_fields['electee_group'].queryset=ElecteeGroup.objects.filter(term=term)
if request.method =='POST':
formset = GroupPointsFormSet(request.POST,prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
if formset.is_valid():
formset.save()
request.session['success_message']='Electee team points updated successfully'
return redirect('electees:view_electee_groups')
else:
request.session['error_message']='Form is invalid. Please correct the noted errors.'
else:
formset = GroupPointsFormSet(prefix='group_points',queryset=ElecteeGroupEvent.objects.filter(related_event_id=None,electee_group__term=term))
template = loader.get_template('generic_formset.html')
context_dict = {
'formset':formset,
'prefix':'group_points',
'subsubnav':'points',
'has_files':False,
'submit_name':'Update Electee Team Points',
'form_title':'Update/Add Remove Electee Team Points',
'help_text':'Track the electee team points. You should not note any points from threshold participation at service or social events here. Those are tabulated automatically.',
'can_add_row':True,
'base':'electees/base_electees.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
开发者ID:dadrian,项目名称:mig-website,代码行数:33,代码来源:views.py
示例20: update_bylaws
def update_bylaws(request):
denied_message = 'You are not authorized to update bylaws.'
if not Permissions.can_manage_bylaws(request.user):
request.session['error_message'] = denied_message
return redirect('about:bylaws')
form = GoverningDocumentForm(request.POST or None, request.FILES or None)
if request.method == 'POST':
if form.is_valid():
form.save()
request.session['success_message'] = ('Document uploaded '
'successfully')
return get_previous_page(request, 'about:bylaws')
else:
request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
template = loader.get_template('generic_form.html')
context_dict = {
'form': form,
'subnav': 'bylaws',
'has_files': True,
'submit_name': 'Update Governing Document',
'form_title': 'Upload New Version of Governing Document',
'help_text': 'This will replace the existing document of this type.',
'base': 'about/base_about.html',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
return HttpResponse(template.render(context_dict, request))
开发者ID:tbpmig,项目名称:mig-website,代码行数:27,代码来源:views.py
注:本文中的mig_main.utility.Permissions类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论