本文整理汇总了Python中mig_main.utility.Permissions.can_post_web_article方法的典型用法代码示例。如果您正苦于以下问题:Python Permissions.can_post_web_article方法的具体用法?Python Permissions.can_post_web_article怎么用?Python Permissions.can_post_web_article使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig_main.utility.Permissions
的用法示例。
在下文中一共展示了Permissions.can_post_web_article方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_permissions
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_post_web_article [as 别名]
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
示例2: get_article_view
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_post_web_article [as 别名]
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))
示例3: get_article_view
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_post_web_article [as 别名]
def get_article_view(request,article_id):
request.session['current_page']=request.path
today = date.today()
web_articles = WebsiteArticle.objects.order_by('-date_posted').exclude(date_posted__gt=today)
if Permissions.can_post_web_article(request.user):
if request.method == 'POST':
form = WebArticleForm(request.POST)
if form.is_valid():
a=form.save()
if hasattr(request.user,'userprofile') and request.user.userprofile.is_member():
a.created_by = request.user.userprofile.memberprofile
a.save()
request.session['success_message']='Your webstory was posted successfully'
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 = WebArticleForm(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',
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
context = RequestContext(request, context_dict)
return HttpResponse(template.render(context))
示例4: get_article_view
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_post_web_article [as 别名]
def get_article_view(request, article_id):
""" The helper view method for the index and the article view.
This is not a url-findable method. To find article urls, use article_view.
This also serves a form to submit new articles, provided that the user
has the permissions to submit such a story.
"""
request.session['current_page'] = request.path
today = date.today()
web_articles = WebsiteArticle.get_stories()
if (hasattr(request.user, 'userprofile') and
request.user.userprofile.is_member()):
profile = request.user.userprofile.memberprofile
else:
profile = None
can_post = Permissions.can_post_web_article(request.user)
NewArticleForm = modelform_factory(WebsiteArticle, form=WebArticleForm)
form = NewArticleForm(request.POST or None,
initial={'date_posted': today})
if can_post and request.method == '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')
else:
request.session['success_message'] = ('Your webstory has '
'been submitted and '
'is awaiting '
'approval')
if profile:
a.created_by = profile
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'] = messages.GENERIC_SUBMIT_ERROR
elif not can_post:
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),
'needs_social_media': True,
}
context_dict.update(get_common_context(request))
context_dict.update(get_permissions(request.user))
return HttpResponse(template.render(context_dict, request))
示例5: get_permissions
# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_post_web_article [as 别名]
def get_permissions(user):
permission_dict={
'can_post':Permissions.can_post_web_article(user),
'post_button':Permissions.can_upload_articles(user),
}
return permission_dict