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


Python messages.ERROR属性代码示例

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


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

示例1: draw_prize_internal

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def draw_prize_internal(self, request, queryset, limit):
        numDrawn = 0
        for prize in queryset:
            if prize.key_code:
                drawn, msg = prizeutil.draw_keys(prize)
                if drawn:
                    numDrawn += len(msg['winners'])
                else:
                    messages.error(request, msg['error'])
            else:
                if limit is None:
                    limit = prize.maxwinners
                numToDraw = min(limit, prize.maxwinners - prize.current_win_count())
                drawingError = False
                while not drawingError and numDrawn < numToDraw:
                    drawn, msg = prizeutil.draw_prize(prize)
                    if not drawn:
                        self.message_user(request, msg['error'], level=messages.ERROR)
                        drawingError = True
                    else:
                        numDrawn += 1
        if numDrawn > 0:
            self.message_user(request, '%d prizes drawn.' % numDrawn) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:25,代码来源:prize.py

示例2: version_delete

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def version_delete(request: HttpRequest, course_slug: str, activity_slug: str, question_id: str, version_id: str) -> HttpResponse:
    if request.method in ['POST', 'DELETE']:
        quiz = get_object_or_404(Quiz, activity__slug=activity_slug, activity__offering__slug=course_slug)
        if quiz.completed():
            return ForbiddenResponse(request, 'Quiz is completed. You cannot modify questions after the end of the quiz time')
        question = get_object_or_404(Question, quiz=quiz, id=question_id)
        version = get_object_or_404(QuestionVersion, question=question, id=version_id)
        other_versions = QuestionVersion.objects.filter(question=question).exclude(id=version_id)
        if not other_versions.exists():
            messages.add_message(request, messages.ERROR, 'Cannot delete the only version of a question.')
            return redirect('offering:quiz:question_edit', course_slug=course_slug, activity_slug=activity_slug, question_id=question_id, version_id=version_id)
        version.status = 'D'
        version.save()
        messages.add_message(request, messages.SUCCESS, 'Question version deleted.')
        LogEntry(userid=request.user.username, description='deleted quiz question version id=%i' % (question.id,),
                 related_object=question).save()
        return redirect('offering:quiz:index', course_slug=course_slug, activity_slug=activity_slug)
    else:
        return HttpError(request, status=405, title="Method Not Allowed", error='POST or DELETE requests only.') 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:views.py

示例3: save_search

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def save_search(request):
    current_user = Person.objects.get(userid=request.user.username)
    saveform = SaveSearchForm(request.POST)
    
    if saveform.is_valid():
        name = saveform.cleaned_data['name']
        existing_ss = SavedSearch.objects.filter(person=saveform.data['person'])
        existing_ss = [ss for ss in existing_ss if ss.name()==name]
        for ss in existing_ss:
            ss.delete()
        
        ss = saveform.save(commit=False)
        ss.person = current_user
        ss.save()
        messages.add_message(request, messages.SUCCESS, 'Search Saved as "%s".' % (name))
        return HttpResponseRedirect(reverse('grad:index'))
    else:
        messages.add_message(request, messages.ERROR, saveform.errors.as_text())
        if True or 'query' in saveform.data:
            return HttpResponseRedirect(reverse('grad:search') + '?' + saveform.data['query'])
        else:
            return HttpResponseRedirect(reverse('grad:search')) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:save_search.py

示例4: _build_days

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def _build_days(self, data):
        "Get or Create Days based on schedule type and set of Days"
        created_days = []
        days = set([x[self.DATE_KEY] for x in data])
        for day in days:
            try:
                date = datetime.strptime(day, "%m/%d/%Y")
            except ValueError:
                [x.delete() for x in created_days]
                return messages.ERROR, "Malformed data found: %s." % day
            day, created = Day.objects.get_or_create(
                schedule=self.schedule, date=date
            )
            if created:
                created_days.append(day)
        return created_days 
开发者ID:pydata,项目名称:conf_site,代码行数:18,代码来源:forms.py

示例5: handle_merge_errors

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def handle_merge_errors(response, request, final_work, nb_merged,
                        message_user):
    if response == MergeErrors.NO_ID:
        message_user(request,
                     "Aucun ID n'a été fourni pour la fusion.",
                     level=messages.ERROR)
    if response == MergeErrors.FIELDS_MISSING:
        message_user(request,
                     """Un ou plusieurs des champs requis n'ont pas été remplis.
                          (Détails: {})""".format(", ".join(final_work)),
                     level=messages.ERROR)
    if response == MergeErrors.NOT_ENOUGH_WORKS:
        message_user(request,
                     "Veuillez sélectionner au moins 2 œuvres à fusionner.",
                     level=messages.WARNING)
    if response is None:  # Confirmed
        message_user(request,
                     format_html('La fusion de {:d} œuvres vers <a href="{:s}">{:s}</a> a bien été effectuée.'
                                 .format(nb_merged, final_work.get_absolute_url(), final_work.title))) 
开发者ID:mangaki,项目名称:mangaki,代码行数:21,代码来源:admin.py

示例6: delete_selected_groups

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def delete_selected_groups(self, request, queryset):
        if self.get_default_queryset(request, queryset).exists():
            msg = _('Cannot proceed with the delete operation because '
                    'the batch of items contains the default group, '
                    'which cannot be deleted')
            self.message_user(request, msg, messages.ERROR)
            return False
        if not self.has_delete_permission(request):
            raise PermissionDenied
        n = queryset.count()
        if n:
            queryset.delete()
            self.message_user(request, _("Successfully deleted %(count)d %(items)s.") % {
                "count": n, "items": model_ngettext(self.opts, n)
            }, messages.SUCCESS)
        return None 
开发者ID:openwisp,项目名称:django-freeradius,代码行数:18,代码来源:admin.py

示例7: get_form_kwargs

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def get_form_kwargs(self, *args, **kwargs):
        form_kwargs = super().get_form_kwargs(*args, **kwargs)
        try:
            user_id = self.request.session['password_reset_id']
            user = User.objects.get(id=user_id)
            form_kwargs['user'] = user
        except KeyError:
            message = _(
                "You must first verify your token before resetting password."
                " Click <a href='{url}'>here</a> to get the password reset"
                " verification token. ")
            message = format_html(message.format(
                url=reverse_lazy('account:account_reset_password')))
            messages.add_message(self.request, messages.ERROR, message)

        return form_kwargs 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:18,代码来源:default.py

示例8: form_valid

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def form_valid(self, form):
        login = form.cleaned_data['login']
        user = form.user

        if (login == user.username and
                not user.phone_verified and
                not user.email_verified):
            user.is_active = False
            user.save()
            messages.add_message(
                self.request, messages.ERROR, account_inactive)
            return redirect(reverse_lazy('account:resend_token'))

        if(login == user.email and not user.email_verified or
                login == user.phone and not user.phone_verified):
            messages.add_message(
                self.request, messages.ERROR, unverified_identifier)
            return redirect(reverse_lazy('account:resend_token'))
        else:
            return super().form_valid(form) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:22,代码来源:default.py

示例9: judge

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def judge(self, request, queryset):
        if not request.user.has_perm('judge.rejudge_submission') or not request.user.has_perm('judge.edit_own_problem'):
            self.message_user(request, gettext('You do not have the permission to rejudge submissions.'),
                              level=messages.ERROR)
            return
        queryset = queryset.order_by('id')
        if not request.user.has_perm('judge.rejudge_submission_lot') and \
                queryset.count() > settings.DMOJ_SUBMISSIONS_REJUDGE_LIMIT:
            self.message_user(request, gettext('You do not have the permission to rejudge THAT many submissions.'),
                              level=messages.ERROR)
            return
        if not request.user.has_perm('judge.edit_all_problem'):
            id = request.profile.id
            queryset = queryset.filter(Q(problem__authors__id=id) | Q(problem__curators__id=id))
        judged = len(queryset)
        for model in queryset:
            model.judge(rejudge=True, batch_rejudge=True)
        self.message_user(request, ungettext('%d submission was successfully scheduled for rejudging.',
                                             '%d submissions were successfully scheduled for rejudging.',
                                             judged) % judged) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:22,代码来源:submission.py

示例10: file_user_required

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def file_user_required(func):
    """ This decorator checks that a user has permission to view a file

    :param func: the function to callback from the decorator
    :return: either the function call or raises an Http404
    """

    def wrapper(request, *args, **kwargs):
        file_id = kwargs['file_id']

        if file_id == "None":
            return func(request, *args, **kwargs)

        file_object = get_object_or_404(core_models.File, pk=file_id)

        if can_view_file(request, request.user, file_object):
            return func(request, *args, **kwargs)
        else:
            messages.add_message(request, messages.ERROR, 'File is not accessible to this user.')
            deny_access(request)

    return wrapper 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:24,代码来源:decorators.py

示例11: file_history_user_required

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def file_history_user_required(func):
    """ This decorator checks permissions for a user to view the history of a specific article

    :param func: the function to callback from the decorator
    :return: either the function call or raises an Http404
    """

    def wrapper(request, *args, **kwargs):
        file_object = get_object_or_404(core_models.File, pk=kwargs['file_id'])

        try:
            article = models.Article.get_article(request.journal, 'id', kwargs['article_id'])
        except KeyError:
            article = models.Article.get_article(request.journal, kwargs['identifier_type'], kwargs['identifier'])

        if can_view_file_history(request, request.user, file_object, article):
            return func(request, *args, **kwargs)

        messages.add_message(request, messages.ERROR, 'File editing not accessible to this user.')
        deny_access(request)

    return wrapper 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:24,代码来源:decorators.py

示例12: file_edit_user_required

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def file_edit_user_required(func):
    """ This decorator checks permissions for a user to edit a specific article

    :param func: the function to callback from the decorator
    :return: either the function call or raises an Http404
    """

    def wrapper(request, *args, **kwargs):
        file_object = get_object_or_404(core_models.File, pk=kwargs['file_id'])

        try:
            article = models.Article.get_article(request.journal, 'id', kwargs['article_id'])
        except KeyError:
            article = models.Article.get_article(request.journal, kwargs['identifier_type'], kwargs['identifier'])

        if can_edit_file(request, request.user, file_object, article):
            return func(request, *args, **kwargs)

        messages.add_message(request, messages.ERROR, 'File editing not accessible to this user.')
        deny_access(request)

    return wrapper 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:24,代码来源:decorators.py

示例13: data_figure_file

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def data_figure_file(func):
    """ This decorator checks that a file is a data or figure file in the specified article

    :param func: the function to callback from the decorator
    :return: either the function call or raises an Http404
    """

    def wrapper(request, *args, **kwargs):
        file_object = get_object_or_404(core_models.File, pk=kwargs['file_id'])

        try:
            article = models.Article.get_article(request.journal, 'id', kwargs['article_id'])
        except KeyError:
            article = models.Article.get_article(request.journal, kwargs['identifier_type'], kwargs['identifier'])

        if is_data_figure_file(file_object, article):
            return func(request, *args, **kwargs)

        messages.add_message(request, messages.ERROR, 'File is not a data or figure file.')
        deny_access(request)

    return wrapper


# General checks to avoid "raise Http404()" logic elsewhere 
开发者ID:BirkbeckCTP,项目名称:janeway,代码行数:27,代码来源:decorators.py

示例14: delete_selected_overridden

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def delete_selected_overridden(self, request, queryset):
        if not request.user.is_superuser:
            users_pk = queryset.values_list('pk', flat=True)
            owners_list = list(
                OrganizationOwner.objects.filter(organization_user__user__in=users_pk)
                .select_related('organization_user__user')
                .values_list('organization_user__user__username', flat=True)
            )
            owners = ', '.join(owners_list)
            excluded_owners_qs = queryset.exclude(username__in=owners_list)
            # if trying to delete any owner, show an error message
            count = len(owners_list)
            if count:
                self.message_user(
                    request,
                    ngettext(
                        f"Can't delete %d organization owner: {owners}",
                        f"Can't delete %d organization owners: {owners}",
                        count,
                    )
                    % count,
                    messages.ERROR,
                )
            # if trying to delete only owners, stop here
            if queryset.exists() and not excluded_owners_qs.exists():
                redirect_url = reverse(
                    f'admin:{self.model._meta.app_label}_user_changelist'
                )
                return HttpResponseRedirect(redirect_url)
            # otherwise proceed but remove owners from the delete queryset
            else:
                queryset = excluded_owners_qs
        return delete_selected(self, request, queryset) 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:35,代码来源:admin.py

示例15: return_label

# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import ERROR [as 别名]
def return_label(request, code, return_order):

    GsxAccount.default(request.user)

    try:
        label = gsxws.Returns(return_order)
        return HttpResponse(label.returnLabelFileData, content_type="application/pdf")
    except Exception as e:
        messages.add_message(request, messages.ERROR, e)
        return redirect('products-list') 
开发者ID:fpsw,项目名称:Servo,代码行数:12,代码来源:shipments.py


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