当前位置: 首页>>代码示例>>Python>>正文


Python Permissions.can_approve_web_article方法代码示例

本文整理汇总了Python中mig_main.utility.Permissions.can_approve_web_article方法的典型用法代码示例。如果您正苦于以下问题:Python Permissions.can_approve_web_article方法的具体用法?Python Permissions.can_approve_web_article怎么用?Python Permissions.can_approve_web_article使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mig_main.utility.Permissions的用法示例。


在下文中一共展示了Permissions.can_approve_web_article方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit_articles

# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_approve_web_article [as 别名]
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,代码行数:34,代码来源:views.py

示例2: get_permissions

# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_approve_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
开发者ID:pritpaul,项目名称:mig-website,代码行数:11,代码来源:views.py

示例3: get_article_view

# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_approve_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))
开发者ID:pritpaul,项目名称:mig-website,代码行数:50,代码来源:views.py

示例4: edit_articles

# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_approve_web_article [as 别名]
def edit_articles(request):
    """ Allows editing and approving articles."""
    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,
                                           exclude=[])
    formset = WebStoryFormset(
                request.POST or None,
                prefix=prefix,
                queryset=WebsiteArticle.objects.order_by(
                                            'approved',
                                            '-date_posted'
                )
    )
    if request.method == 'POST':
        if formset.is_valid():
            formset.save()
            request.session['success_message'] = ('Web stories updated '
                                                  'successfully')
            return redirect('history:index')
        else:
            request.session['error_message'] = messages.GENERIC_SUBMIT_ERROR
    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))
    return HttpResponse(template.render(context_dict, request))
开发者ID:tbpmig,项目名称:mig-website,代码行数:48,代码来源:views.py

示例5: get_article_view

# 需要导入模块: from mig_main.utility import Permissions [as 别名]
# 或者: from mig_main.utility.Permissions import can_approve_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))
开发者ID:tbpmig,项目名称:mig-website,代码行数:64,代码来源:views.py


注:本文中的mig_main.utility.Permissions.can_approve_web_article方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。