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


Python MessageManager.set_success方法代码示例

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


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

示例1: edit_code_package

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def edit_code_package(request, id):
    """edit a code package"""
    # prepare messages
    mm = MessageManager(request)
    cp = get_object_or_404(CodePackage, pk=id)
    if request.user.is_authenticated() and request.user.username == cp.user.username:
        if request.POST:
            form = EditCodePackageForm(request.POST, user=request.user)
            if form.is_valid():
                form.save(request, cp)
                mm.set_success("Your code package has been updated")
                return redirect(cp.get_absolute_url())
            else:
                # form had errors
                return render(request, 'main/code_package/edit.html', mm.messages(), {'form':form, 'code_package':cp})
        else:
            # prepare new form for user
            cpk = None
            if cp.group():
                cpk = cp.group().pk
            term_str = delim_list(object_taxon(cp), ',')
            form = EditCodePackageForm(user=request.user, initial={'group': cpk, 'title':cp.title, 'description':cp.description, 'terms':term_str})
            
            return render(request, 'main/code_package/edit.html', mm.messages(), {'form':form, 'code_package':cp})
    else:
        return redirect(request.META.get('HTTP_REFERER','/'))
开发者ID:neutrinog,项目名称:Comperio,代码行数:28,代码来源:views.py

示例2: edit_account

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def edit_account(request, username):
    """edit a user's account details"""
    # prepare messages
    mm = MessageManager(request)
    try:
        u = cUser.objects.get(username=username)
    except cUser.DoesNotExist:
        u = get_object_or_404(User, username=username)
    
    # must be an authenticated user and own the profile in order to get the form.
    if request.user.is_authenticated() and request.user == u:
        if request.POST:
            # collect form
            form = EditAccountForm(request.POST)
            
            if form.is_valid():
                form.update(request, u)
                mm.set_success("Your account has been updated")
                return redirect(request.user.get_absolute_url())
            else:
                return render(request, 'accounts/user/edit.html', {'form':form}, mm.messages())
        else:
            # prepare form
            form = EditAccountForm(initial={'username':u.username, 'email':u.email})
            return render(request, 'accounts/user/edit.html', {'form':form}, mm.messages())
    else:
        return redirect(u.get_absolute_url())
开发者ID:neutrinog,项目名称:Comperio,代码行数:29,代码来源:views.py

示例3: user_account

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def user_account(request, username):
    """display user account details page"""
    mm = MessageManager(request)
    # must be an authenticated user and own the profile in order to get the form.
    if request.user.is_authenticated() and request.user.username == username:
        # must also be of type cUser. since the super is default to a User.
        if request.user.__class__ == cUser:
            if request.POST:
                # collect form
                form = SettingsForm(request.POST)
                if form.is_valid():
                    s = request.user.settings
                    s.public_comments = form.cleaned_data['public_comments']
                    s.code_pkg_updates = form.cleaned_data['code_pkg_updates']
                    s.save()
                    mm.set_success("Your settings have been saved")
                    return render(request, 'accounts/user/account.html', {'form':form}, mm.messages())
                else:
                    mm.set_error("Sorry! We encountered an error and were unable to save your settings")
                    form = SettingsForm(instance=request.user.settings)
                    return render(request, 'accounts/user/account.html', {'form':form}, mm.messages())
            else:
                # prepare form
                form = SettingsForm(instance=request.user.settings)
                return render(request, 'accounts/user/account.html', {'form':form}, mm.messages())
    return render(request, 'accounts/user/account.html', mm.messages())
开发者ID:neutrinog,项目名称:Comperio,代码行数:28,代码来源:views.py

示例4: edit_link

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def edit_link(request, id):
    """edit a link"""
    # prepare messages
    mm = MessageManager(request)
    link = get_object_or_404(Link, pk=id)
    if request.user.is_authenticated() and request.user.username == link.user.username:
        if request.POST:
            form = CreateLinkForm(request.POST, request.FILES, user=request.user)
            if form.is_valid():
                form.update(request, link)
                mm.set_success("Your link has been updated")
                return redirect(link.get_absolute_url())
            else:
                # form had errors
                return render(request, 'main/link/edit.html', mm.messages(), {'form':form, 'link':link})
        else:
            # prepare new form for user
            lpk = None
            if link.group():
                lpk = link.group().pk
            term_str = delim_list(object_taxon(link), ',')
            form = CreateLinkForm(user=request.user, initial={'group': lpk, 'title':link.title, 'url':link.url, 'terms':term_str})
            
            return render(request, 'main/link/edit.html', mm.messages(), {'form':form, 'link':link})
    else:
        return redirect(request.META.get('HTTP_REFERER','/'))
开发者ID:neutrinog,项目名称:Comperio,代码行数:28,代码来源:views.py

示例5: edit_discussion

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def edit_discussion(request, id):
    """edit a discussion"""
    # prepare messages
    mm = MessageManager(request)
    d = get_object_or_404(Discussion, pk=id)
    if request.user.is_authenticated() and request.user.username == d.user.username:
        if request.POST:
            form = CreateDiscussionForm(request.POST, request.FILES, user=request.user)
            if form.is_valid():
                form.update(request, d)
                mm.set_success("Your discussion has been updated")
                return redirect(d.get_absolute_url())
            else:
                # form had errors
                return render(request, 'main/discussion/edit.html', mm.messages(), {'form':form, 'discussion':d})
        else:
            # prepare new form for user
            dpk = None
            if d.group():
                dpk = d.group().pk
            term_str = delim_list(object_taxon(d), ',')
            form = CreateDiscussionForm(user=request.user, initial={'group': dpk, 'title':d.title, 'body':d.body, 'type':d.type, 'terms':term_str})
            
            return render(request, 'main/discussion/edit.html', mm.messages(), {'form':form, 'discussion':d})
    else:
        return redirect(request.META.get('HTTP_REFERER','/'))
开发者ID:neutrinog,项目名称:Comperio,代码行数:28,代码来源:views.py

示例6: contact

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def contact(request):
    """contact page"""
    # prepare messages
    mm = MessageManager(request)
    if request.POST:
        form = ContactForm(request.POST)
        if form.is_valid():
            data = request.POST.copy()
            
            # make sure we have a human
            if not form.isValidHuman(data):
                mm.set_error('Sorry only humans can contact us. Try reloading the page.')
                return render(request, 'main/contact.html', mm.messages(), {'form':form})
            
            # prepare email
            email_subject = 'Comperio Form Submission'
            email_body =\
"Form submission from %s\n\nName: %s\nEmail: %s\n\n%s" % (
            SITE_URL,
            data['name'],
            data['email'],
            data['message'])
            emails = [x[1] for x in ADMINS]
            send_mail(email_subject,
                  email_body,
                  '[email protected]',
                  emails)
            mm.set_success("Thank you! We received your message.")
            return redirect('/')
        
        else:
            return render(request, 'main/contact.html', {'form':form}, mm.messages())
    else:
        form = ContactForm()
    return render(request, 'main/contact.html', {'form':form}, mm.messages())
开发者ID:neutrinog,项目名称:Comperio,代码行数:37,代码来源:views.py

示例7: delete

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def delete(request, username):
    """delete a user account"""
    # prepare messages
    mm = MessageManager(request)
    
    if request.user.is_active and request.user.username == username:
        if request.user.is_superuser:
            mm.set_error("um... you can't delete a super user silly.")
            return redirect(request.META.get('HTTP_REFERER','/'))
        
        # Build the removal key for account                                                                                                                    
        salt = sha.new(str(random.random())).hexdigest()[:5]
        removal_key = sha.new(salt+username).hexdigest()
        key_expires = datetime.datetime.today() + datetime.timedelta(2)
        
        request.user.removal_key = removal_key
        request.user.key_expires = key_expires
        request.user.save()
        
        # prepare email
        email_subject = 'Confirm account deletion'
        email_body =\
"We just received a request to delete your Comperio account.\
\n\nTo delete your account, click this link within 48 hours:\
\n%s/users/delete/confirm/%s" % (
            SITE_URL,
            request.user.removal_key)
        send_mail(email_subject,
                  email_body,
                  '[email protected]',
                  [request.user.email])
        mm.set_success("We just sent you an email to verify your account removal.")
        return redirect(request.META.get('HTTP_REFERER','/')) 
开发者ID:neutrinog,项目名称:Comperio,代码行数:35,代码来源:views.py

示例8: upload

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def upload(request):
    """upload a code package to a user profile"""
    mm = MessageManager(request)
    if request.POST:
        form = UploadCodePackageForm(request.POST, request.FILES)
        if form.is_valid():
            e = form.cleaned_data['username']
            p = form.cleaned_data['password']
            try:
                user = authenticate(username=e, password=p)
            except NameError:
                user = None
                
            if user is not None:
                if user.is_active:
                    if form.save(request, user):
                        mm.set_success("package uploaded")
                        form = UploadCodePackageForm()
                    else:
                        mm.set_error("package could not be uploaded")
                else:
                    # account is disabled
                    mm.set_error('This account has been disabled, or has not been activated.')
            else:
                # invalid login
                mm.set_error('Invalid credentials.')
                
            return render(request, 'api/upload.html', {'form':form}, mm.messages())
        else:
            # return form errors to user
            return render(request, 'api/upload.html', {'form':form}, mm.messages())
    else:
        form = UploadCodePackageForm()
        return render(request, 'api/upload.html', {'form':form}, mm.messages())
开发者ID:neutrinog,项目名称:Comperio,代码行数:36,代码来源:views.py

示例9: edit_task

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def edit_task(request, id):
    """edit and existing task"""
    mm = MessageManager(request)
    t = get_object_or_404(Task, pk=id)
    if request.user.is_authenticated() and request.user.username == t.user.username:
        if request.POST:
    #        receive sent form
            form = NewTaskForm(request.POST)
            if form.is_valid():
                mm.set_success("task updated")
                t.due_date = form.cleaned_data['due_date']
                t.description = form.cleaned_data['description']
                notify = form.cleaned_data['notify']
                if notify is False:
                    t.notify = False
                else:
                    t.notify = True
                t.save()
                return redirect(t.get_absolute_url())
            else:
                mm.set_error("error")
    #            error
                pass
        else:
    #        setup new form
            form = NewTaskForm(initial={'due_date':t.due_date, 'description':t.description, 'notify':t.notify})
        return render(request, 'tasks/edit.html', {'form':form, 'task':t}, mm.messages())
    else:
        mm.set_notice("you are not authorized to edit that task.")
        return redirect(request.META.get('HTTP_REFERER','/'))
开发者ID:neutrinog,项目名称:Comperio,代码行数:32,代码来源:views.py

示例10: _survey_redirect

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def _survey_redirect(
    request,
    survey,
    group_slug=None,
    group_slug_field=None,
    group_qs=None,
    template_name="survey/thankyou.html",
    extra_context=None,
    *args,
    **kw
):
    """
    Conditionally redirect to the appropriate page;
    if there is a "next" value in the GET URL parameter,
    go to the URL specified under Next.

    If there is no "next" URL specified, then go to
    the survey results page...but only if it is viewable
    by the user.

    Otherwise, only direct the user to a page showing
    their own survey answers...assuming they have answered
    any questions.

    If all else fails, go to the Thank You page.
    """
    if (
        "next" in request.REQUEST
        and request.REQUEST["next"].startswith("http:")
        and request.REQUEST["next"] != request.path
    ):
        return HttpResponseRedirect(request.REQUEST["next"])
    if survey.answers_viewable_by(request.user):
        return HttpResponseRedirect(reverse("survey-results", None, (), {"survey_slug": survey.__dict__["slug"]}))

    # For this survey, have they answered any questions?
    # if (hasattr(request, 'session') and Answer.objects.filter(
    #        session_key=request.session.session_key.lower(),
    #        question__survey__visible=True,
    #        question__survey__slug=survey.__dict__['slug']).count()):
    #    print "ytest4"
    #    return HttpResponseRedirect(
    #        reverse('answers-detail', None, (),
    #                {'survey_slug': survey.__dict__['slug'],
    #                 'key': request.session.session_key.lower()}))

    # go to thank you page
    # return render()
    mm = MessageManager(request)
    mm.set_success("Thank You For Participating In The Survey!")
    return HttpResponseRedirect(request.user.get_absolute_url())
    # return render_to_response(template_name,
    #                          {'survey': survey, 'title': 'Thank You'},
    #                          context_instance=RequestContext(request))
    return render(request, template_name, {"survey": survey, "title": "Thank You"})
开发者ID:neutrinog,项目名称:Comperio,代码行数:57,代码来源:views.py

示例11: delete_task

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def delete_task(request, id):
    """delete a task"""
    mm = MessageManager(request)
    t = get_object_or_404(Task, pk=id)
    if request.user.is_authenticated() and request.user.username == t.user.username:
        t.delete()
        mm.set_success("task removed")
        return redirect(request.user.get_absolute_url())
    else:
        mm.set_notice("you are not authorized to delete that task.")
        return redirect(request.META.get('HTTP_REFERER','/')) 
开发者ID:neutrinog,项目名称:Comperio,代码行数:13,代码来源:views.py

示例12: delete_lesson

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def delete_lesson(request, c_id, l_id):
    """delete an existing lesson"""
    mm = MessageManager(request)
    l = get_object_or_404(Lesson, pk=l_id)
    c = get_object_or_404(Curriculum, pk=c_id)
    if request.user.is_authenticated() and request.user.username == l.user.username:
        name = l.title
        l.delete()
        mm.set_success('"%s" has been deleted' % name)
    else:
        mm.set_notice('you are not authorized to delete this lesson')
    return redirect(c.get_absolute_url())
开发者ID:neutrinog,项目名称:Comperio,代码行数:14,代码来源:views.py

示例13: reject_from_group

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def reject_from_group(request, gid, uid):
    """reject a pending membership request"""
    mm = MessageManager(request)
    g = get_object_or_404(cGroup, pk=gid)
    u = get_object_or_404(cUser, pk=uid)
    if request.user.is_authenticated() and request.user.is_group_manager(g):
        if u in g.pending_users.all():
            mm.set_success("membership refused for %s" % u.username)
            g.pending_users.remove(u)
            g.save()
        else:
            mm.set_error("you can't just reject whomever you want!")
        return redirect(reverse('manage-group', None, (), {'gid':g.pk}))
    return redirect(g.get_absolute_url())
开发者ID:neutrinog,项目名称:Comperio,代码行数:16,代码来源:views.py

示例14: create_curriculum

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def create_curriculum(request):
    """create a new curriculum container"""
    mm = MessageManager(request)
    if request.POST:
        form = CreateCurriculumForm(request.POST)
        if form.is_valid():
            # save it
            c = form.save(request)
            mm.set_success("the curriculum was saved")
            return redirect(c.get_absolute_url())
        else:
            mm.set_error("the form has errors")
            pass
    else:
        form = CreateCurriculumForm()
    return render(request, 'curricula/create_curriculum.html', {'form':form}, mm.messages())
开发者ID:neutrinog,项目名称:Comperio,代码行数:18,代码来源:views.py

示例15: login_view

# 需要导入模块: from comperio.main.tools import MessageManager [as 别名]
# 或者: from comperio.main.tools.MessageManager import set_success [as 别名]
def login_view(request):
    """Login to a user account and redirect to profile"""
    # TODO: put link on profile page to return to original page
    # prepare messages
    mm = MessageManager(request)
    if request.user.is_authenticated():
        return redirect(request.user.get_absolute_url())
        
    if request.POST:
        if request.session.test_cookie_worked():
            request.session.delete_test_cookie()
            # cookies are enabled
            form = LoginForm(request.POST)
            if not form == None and form.is_valid():
                # log the user in. we extended to backend to allow using email
                # instead of just username
                e = form.cleaned_data['username']
                p = form.cleaned_data['password']
                
                try:
                    user = authenticate(username=e, password=p)
                except NameError:
                    user = None
                    
                if user is not None:
                    if user.is_active:
                        #request.user = user
                        login(request, user)
                        mm.set_success('you are logged in!')
                        return redirect(request.user.get_absolute_url())
                    else:
                        # account is disabled
                        mm.set_error('This account has been disabled, or has not been activated.')
                else:
                    # invalid login
                    mm.set_error('Invalid credentials.')
            else:
                #mm.set_error('The form is invalid')
                pass
        else:
            # cookies are not enabled
            mm.set_error('Please enable cookies and try again.')
    else:
        
        form = LoginForm()
    request.session.set_test_cookie()
    return render(request, 'accounts/login.html', {'form':form}, mm.messages())
开发者ID:neutrinog,项目名称:Comperio,代码行数:49,代码来源:views.py


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