Python django.contrib.messages.WARNING Examples
The following are 30
code examples of django.contrib.messages.WARNING().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.messages
, or try the search function
.
Example #1
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 6 votes |
def get_pending_update_from_post(request): """ Gets a VersionQueue object from a post value :param request: HttpRequest object :return: VersionQueue object or None """ update_id = None if 'approve' in request.POST: update_id = request.POST.get('approve') elif 'deny' in request.POST: update_id = request.POST.get('deny') if update_id: pending_update = get_object_or_404(models.VersionQueue, pk=update_id, date_decision__isnull=True) return pending_update else: messages.add_message(request, messages.WARNING, 'No valid version id provided.') return None
Example #2
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 6 votes |
def move_to_review(request, article_id, should_redirect=True): """Moves an article into the review stage""" article = get_object_or_404(submission_models.Article, pk=article_id) if article.editorassignment_set.all().count() > 0: article.stage = submission_models.STAGE_ASSIGNED article.save() review_round, created = models.ReviewRound.objects.get_or_create(article=article, round_number=1) if not created: messages.add_message(request, messages.WARNING, 'A default review round already exists for this article.') else: messages.add_message(request, messages.INFO, 'You must assign an editor before moving into reivew.') if should_redirect: if request.GET.get('return', None): return redirect(request.GET.get('return')) else: return redirect("{0}?modal_id={1}".format(reverse('kanban_home'), article_id))
Example #3
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 6 votes |
def save_galley_image(galley, request, uploaded_file, label="Galley Image", fixed=False): if fixed: filename = request.POST.get('file_name') uploaded_file_mime = files.check_in_memory_mime(uploaded_file) expected_mime = files.guess_mime(filename) if not uploaded_file_mime == expected_mime: messages.add_message(request, messages.WARNING, 'The file you uploaded does not match the mime of the ' 'file expected.') new_file = files.save_file_to_article(uploaded_file, galley.article, request.user) new_file.is_galley = False new_file.label = label if fixed: new_file.original_filename = request.POST.get('file_name') new_file.save() galley.images.add(new_file) return new_file
Example #4
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 6 votes |
def handle_updating_subject(request, preprint): """ Pulls a subject pk from POST, checks it exists and assigns the article to the subject. :param request: HttpRequest :param preprint: Preprint Object :return: Function does not return anything """ subject_pk = request.POST.get('subject') if not subject_pk: messages.add_message(request, messages.WARNING, 'No subject selected') else: subject = get_object_or_404(models.Subject, pk=subject_pk, enabled=True) preprint.set_preprint_subject(subject) messages.add_message(request, messages.INFO, ('Subject Area updated.'))
Example #5
Source File: admin.py From heltour with MIT License | 6 votes |
def verify_data(self, request, queryset): for season in queryset: # Ensure SeasonPlayer objects exist for all paired players if season.league.competitor_type == 'team': pairings = TeamPlayerPairing.objects.filter(team_pairing__round__season=season) else: pairings = LonePlayerPairing.objects.filter(round__season=season) for p in pairings: SeasonPlayer.objects.get_or_create(season=season, player=p.white) SeasonPlayer.objects.get_or_create(season=season, player=p.black) # Normalize all gamelinks bad_gamelinks = 0 for p in pairings: old = p.game_link p.game_link, ok = normalize_gamelink(old) if not ok: bad_gamelinks += 1 if p.game_link != old: p.save() if bad_gamelinks > 0: self.message_user(request, '%d bad gamelinks for %s.' % (bad_gamelinks, season.name), messages.WARNING) self.message_user(request, 'Data verified.', messages.INFO)
Example #6
Source File: admin.py From mangaki with GNU Affero General Public License v3.0 | 6 votes |
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)))
Example #7
Source File: decorators.py From janeway with GNU Affero General Public License v3.0 | 6 votes |
def article_decision_not_made(func): """ This decorator pulls a review and checks if it is accepted or declined. Raises a permission error if a decision has already been made. :param func: the function to callback from the decorator :return: either the function call or raises an PermissionDenied """ def wrapper(request, *args, **kwargs): try: article_object = models.Article.objects.get(pk=kwargs['article_id'], journal=request.journal) except KeyError: article_object = review_models.ReviewAssignment.objects.get(pk=kwargs['review_id'], article__journal=request.journal).article if article_object.stage == models.STAGE_ASSIGNED or article_object.stage == models.STAGE_UNDER_REVIEW\ or article_object.stage == models.STAGE_UNDER_REVISION: return func(request, *args, **kwargs) else: messages.add_message(request, messages.WARNING, 'This article has already been accepted or declined.') return redirect(reverse('review_in_review', kwargs={'article_id': article_object.pk})) return wrapper
Example #8
Source File: admin.py From djangoql with MIT License | 6 votes |
def get_search_results(self, request, queryset, search_term): if ( self.search_mode_toggle_enabled() and not self.djangoql_search_enabled(request) ): return super(DjangoQLSearchMixin, self).get_search_results( request=request, queryset=queryset, search_term=search_term, ) use_distinct = False if not search_term: return queryset, use_distinct try: return ( apply_search(queryset, search_term, self.djangoql_schema), use_distinct, ) except (DjangoQLError, ValueError, FieldError, ValidationError) as e: msg = self.djangoql_error_message(e) messages.add_message(request, messages.WARNING, msg) return queryset.none(), use_distinct
Example #9
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def handle_add_users_to_role(users, role, request): role = models.Role.objects.get(pk=role) users = models.Account.objects.filter(pk__in=users) if not users: messages.add_message(request, messages.WARNING, 'No users selected') if not role: messages.add_message(request, messages.WARNING, 'No role selected.') for user in users: user.add_account_role(role.slug, request.journal) messages.add_message(request, messages.INFO, '{0} added to {1}'.format(user.full_name(), role.name))
Example #10
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def use_data_file_as_galley_image(galley, request, label): file_id = request.POST.get('datafile') if file_id: try: file = core_models.File.objects.get(pk=file_id) file.original_filename = request.POST.get('file_name') file.save() galley.images.add(file) messages.add_message(request, messages.SUCCESS, 'File added.') except core_models.File.DoesNotExist: messages.add_message(request, messages.WARNING, 'No file with given ID found.')
Example #11
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def user_login_orcid(request): """ Allows a user to login with ORCiD :param request: HttpRequest object :return: HttpResponse object """ orcid_code = request.GET.get('code', None) if orcid_code and django_settings.ENABLE_ORCID: orcid_id = orcid.retrieve_tokens( orcid_code, request.site_type) if orcid_id: try: user = models.Account.objects.get(orcid=orcid_id) user.backend = 'django.contrib.auth.backends.ModelBackend' login(request, user) if request.GET.get('next'): return redirect(request.GET.get('next')) else: return redirect(reverse('core_dashboard')) except models.Account.DoesNotExist: # Set Token and Redirect models.OrcidToken.objects.filter(orcid=orcid_id).delete() new_token = models.OrcidToken.objects.create(orcid=orcid_id) return redirect(reverse('core_orcid_registration', kwargs={'token': new_token.token})) else: messages.add_message( request, messages.WARNING, 'Valid ORCiD not returned, please try again, or login with your username and password.' ) return redirect(reverse('core_login')) else: messages.add_message( request, messages.WARNING, 'No authorisation code provided, please try again or login with your username and password.') return redirect(reverse('core_login'))
Example #12
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def preprints_article(request, article_id): """ Fetches a single article and displays its metadata :param request: HttpRequest :param article_id: integer, PK of an Article object :return: HttpResponse or Http404 if object not found """ article = get_object_or_404(submission_models.Article.preprints.prefetch_related('authors'), pk=article_id, stage=submission_models.STAGE_PREPRINT_PUBLISHED, date_published__lte=timezone.now()) comments = models.Comment.objects.filter(article=article, is_public=True) form = forms.CommentForm() if request.POST: if not request.user.is_authenticated: messages.add_message(request, messages.WARNING, 'You must be logged in to comment') return redirect(reverse('core_login')) form = forms.CommentForm(request.POST) if form.is_valid(): comment = form.save(commit=False) preprint_logic.handle_comment_post(request, article, comment) return redirect(reverse('preprints_article', kwargs={'article_id': article_id})) pdf = preprint_logic.get_pdf(article) html = preprint_logic.get_html(article) store_article_access(request, article, 'view') template = 'preprints/article.html' context = { 'article': article, 'galleys': article.galley_set.all(), 'pdf': pdf, 'html': html, 'comments': comments, 'form': form, } return render(request, template, context)
Example #13
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def handle_delete_request(request, galley, typeset_task=None, article=None, page=False): if typeset_task: article = typeset_task.assignment.article file_id = request.POST.get('delete', None) if file_id: try: file_to_delete = core_models.File.objects.get(pk=file_id) if file_to_delete.pk in galley.article.all_galley_file_pks(): messages.add_message(request, messages.INFO, 'File deleted') # Check if this is a data file, and if it is remove it, # dont delete it. if file_to_delete in galley.article.data_figure_files.all(): galley.images.remove(file_to_delete) else: file_to_delete.delete() except core_models.File.DoesNotExist: messages.add_message(request, messages.WARNING, 'File not found') if page == 'edit': return redirect(reverse('edit_galley', kwargs={'typeset_id': typeset_task.pk, 'galley_id': galley.pk})) elif page == 'pm_edit': return redirect(reverse('production_article', kwargs={'article_id': article.pk})) elif page == 'typeset': return redirect(reverse('do_typeset_task', kwargs={'typeset_id': typeset_task.pk})) else: return redirect(reverse('assigned_article', kwargs={'article_id': article.pk}))
Example #14
Source File: workflow.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def remove_element(request, journal_workflow, element): """ Checks if there are any articles in the current stage and blocks its removal if there are. :param request: :param journal_workflow: :param element: :return: """ stages = ELEMENT_STAGES.get(element.element_name, None) articles = submission_models.Article.objects.filter( stage__in=stages, journal=request.journal, ) if articles: messages.add_message( request, messages.WARNING, 'Element cannot be removed as there are {0}' ' articles in this stage.'.format(articles.count()) ) else: journal_workflow.elements.remove(element) messages.add_message( request, messages.SUCCESS, 'Element removed from workflow.' )
Example #15
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def copyedit_request_decision(request, copyedit_id, decision): """ Records a user's decision on whether they will do a copyedit. :param request: HttpRequest object :param copyedit_id: a CopyeditAssignment PK :param decision: a string, either 'accept' or 'decline' :return: HttpResponse object """ copyedit = get_object_or_404(models.CopyeditAssignment, pk=copyedit_id) if decision == 'accept': copyedit.decision = 'accept' copyedit.date_decided = timezone.now() messages.add_message(request, messages.INFO, 'Copyediting request {0} accepted'.format(copyedit.pk)) elif decision == 'decline': copyedit.decision = 'decline' copyedit.date_decided = timezone.now() messages.add_message(request, messages.INFO, 'Copyediting request {0} declined'.format(copyedit.pk)) else: messages.add_message(request, messages.WARNING, 'Decision must be "accept" or "decline".') kwargs = { 'copyedit_assignment': copyedit, 'decision': decision, 'request': request, } event_logic.Events.raise_event(event_logic.Events.ON_COPYEDITOR_DECISION, **kwargs) copyedit.save() return redirect(reverse('copyedit_requests'))
Example #16
Source File: admin.py From lexpredict-contraxsuite with GNU Affero General Public License v3.0 | 5 votes |
def save_model(self, request, obj: DocumentField, form, change: bool): if self.is_clone_view is True: return typed = TypedField.by(obj) if change and \ (typed.is_choice_field and not obj.allow_values_not_specified_in_choices): # don't save here, prompt user if there are values other than in choices list return # check formula errors errors = {} # type:Dict[str, List[str]] warnings = {} # type:Dict[str, List[str]] formula_fields = ['formula'] for field in formula_fields: check_return_value = field == 'formula' rst_formula = self.check_field_formula_default_and_empty( form, check_return_value, field) errors[field] = rst_formula.errors warnings[field] = rst_formula.warnings if errors: for field in errors: if not errors[field]: continue msg = f'There were errors with field "{field}":\n\n' msg += '\n\n'.join(errors[field]) messages.add_message( request, messages.ERROR, msg) if warnings: for field in warnings: if not warnings[field]: continue msg = f'There were potential issues with field "{field}":\n\n' msg += '\n\n'.join(warnings[field]) messages.add_message( request, messages.WARNING, msg) super().save_model(request, obj, form, change) signals.document_field_changed.send(self.__class__, user=request.user, document_field=obj)
Example #17
Source File: options.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def _get_obj_does_not_exist_redirect(self, request, opts, object_id): """ Create a message informing the user that the object doesn't exist and return a redirect to the admin index page. """ msg = _("""%(name)s with ID "%(key)s" doesn't exist. Perhaps it was deleted?""") % { 'name': opts.verbose_name, 'key': unquote(object_id), } self.message_user(request, msg, messages.WARNING) url = reverse('admin:index', current_app=self.admin_site.name) return HttpResponseRedirect(url)
Example #18
Source File: options.py From python with Apache License 2.0 | 5 votes |
def _get_obj_does_not_exist_redirect(self, request, opts, object_id): """ Create a message informing the user that the object doesn't exist and return a redirect to the admin index page. """ msg = _("""%(name)s with ID "%(key)s" doesn't exist. Perhaps it was deleted?""") % { 'name': force_text(opts.verbose_name), 'key': unquote(object_id), } self.message_user(request, msg, messages.WARNING) url = reverse('admin:index', current_app=self.admin_site.name) return HttpResponseRedirect(url)
Example #19
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def proofing_assign_article(request, article_id, user_id=None): """ Assigns a Proofing Manager with a task :param request: HttpRequest object :param article_id: Article object PK :param user_id: Account object PK :return: HttpRedirect """ article = get_object_or_404(submission_models.Article, pk=article_id, journal=request.journal) user = get_object_or_404(core_models.Account, pk=user_id) if user.is_proofing_manager: proofing_assignment = models.ProofingAssignment.objects.create(article=article, proofing_manager=user, notified=True, editor=request.user) proofing_assignment.add_new_proofing_round() message = "{0} has been assigned as proofing manager to {1}".format( proofing_assignment.proofing_manager.full_name(), proofing_assignment.article.title) messages.add_message(request, messages.INFO, message) kwargs = { 'request': request, 'proofing_assignment': proofing_assignment, } event_logic.Events.raise_event(event_logic.Events.ON_PROOFING_MANAGER_ASSIGNMENT, task_object=article, **kwargs) else: messages.add_message(request, messages.WARNING, 'User is not a proofing manager.') return redirect(reverse('proofing_list'))
Example #20
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def proofing_download(request, proofing_task_id, file_id): """ Serves a galley for proofreader """ proofing_task = get_object_or_404(models.ProofingTask, pk=proofing_task_id) file = get_object_or_404(core_models.File, pk=file_id) if file in proofing_task.galley_files(): return files.serve_file(request, file, proofing_task.round.assignment.article) else: messages.add_message(request, messages.WARNING, 'Requested file is not a galley for proofing') return redirect(request.META.get('HTTP_REFERER'))
Example #21
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def assign_editor(request, article_id, editor_id, assignment_type, should_redirect=True): """ Allows a Senior Editor to assign another editor to an article. :param request: HttpRequest object :param article_id: Article PK :param editor_id: Account PK :param assignment_type: string, 'section-editor' or 'editor' :param should_redirect: if true, we redirect the user to the notification page :return: HttpResponse or HttpRedirect """ article = get_object_or_404(submission_models.Article, pk=article_id) editor = get_object_or_404(core_models.Account, pk=editor_id) if not editor.has_an_editor_role(request): messages.add_message(request, messages.WARNING, 'User is not an Editor or Section Editor') return redirect(reverse('review_unassigned_article', kwargs={'article_id': article.pk})) try: assignment = models.EditorAssignment.objects.create(article=article, editor=editor, editor_type=assignment_type) messages.add_message(request, messages.SUCCESS, '{0} added as an Editor'.format(editor.full_name())) kwargs = {'user_message_content': '', 'editor_assignment': assignment, 'request': request, 'skip': True, 'acknowledgement': False} event_logic.Events.raise_event(event_logic.Events.ON_ARTICLE_ASSIGNED, task_object=article, **kwargs) if should_redirect: return redirect('{0}?return={1}'.format( reverse('review_assignment_notification', kwargs={'article_id': article_id, 'editor_id': editor.pk}), request.GET.get('return'))) except IntegrityError: messages.add_message(request, messages.WARNING, '{0} is already an Editor on this article.'.format(editor.full_name())) if should_redirect: return redirect(reverse('review_unassigned_article', kwargs={'article_id': article_id}))
Example #22
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def review_warning(request, article_id): """ Checks if an editor user is the author of an article amd blocks their access temporarily. If overwritten, all Editors are notified. :param request: HttpRequest object :param article_id: Article PK :return: HttpResponse or HttpRedirect """ article = get_object_or_404(submission_models.Article, pk=article_id) if request.POST and request.user.is_editor(request): override = models.EditorOverride.objects.create( article=article, editor=request.user) kwargs = {'request': request, 'override': override} event_logic.Events.raise_event( event_logic.Events.ON_REVIEW_SECURITY_OVERRIDE, task_object=article, **kwargs ) return redirect(reverse('review_in_review', kwargs={'article_id': article.pk})) else: messages.add_message( request, messages.WARNING, 'This action is not allowed.') template = 'review/review_warning.html' context = { 'article': article } return render(request, template, context)
Example #23
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def handle_delete_version(request, preprint): version_id = request.POST.get('delete') if not version_id: messages.add_message(request, messages.WARNING, 'No version id supplied') else: version = get_object_or_404(models.PreprintVersion, pk=version_id, preprint=preprint) version.delete() messages.add_message(request, messages.INFO, 'Version deleted.')
Example #24
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def deny_pending_update(request): pending_update = get_pending_update_from_post(request) if pending_update: pending_update.date_decision = timezone.now() pending_update.approved = False pending_update.save() else: messages.add_message(request, messages.WARNING, 'No valid pending update found.') return redirect(reverse('version_queue'))
Example #25
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def approve_pending_update(request): """ Approves a pending versioning request and updates files/galleys. :param request: HttpRequest object :return: None """ from core import models as core_models pending_update = get_pending_update_from_post(request) if pending_update: if pending_update.update_type == 'correction': pending_update.galley.file = pending_update.file pending_update.galley.save() messages.add_message(request, messages.SUCCESS, 'Correction approved.') elif pending_update.update_type == 'version': models.PreprintVersion.objects.create( preprint=pending_update.article, galley=pending_update.galley, version=pending_update.article.next_preprint_version() ) pending_update.galley.article = None pending_update.galley.save() core_models.Galley.objects.create(article=pending_update.article, file=pending_update.file, label=pending_update.galley.label, type=pending_update.galley.type) messages.add_message(request, messages.SUCCESS, 'New version created.') pending_update.date_decision = timezone.now() pending_update.approved = True pending_update.save() else: messages.add_message(request, messages.WARNING, 'No valid pending update found.') return redirect(reverse('version_queue'))
Example #26
Source File: views.py From coursys with GNU General Public License v3.0 | 5 votes |
def catch_marking_configuration_error(f): """ Decorator to catch MarkingNotConfiguredError and redirect, offering to set things up. """ def decorate(request: HttpRequest, course_slug: str, activity_slug: str, *args, **kwargs): with transaction.atomic(): try: return f(request=request, course_slug=course_slug, activity_slug=activity_slug, *args, **kwargs) except MarkingNotConfiguredError: messages.add_message(request, messages.WARNING, 'Marking is not configured for this quiz.') return redirect('offering:quiz:marking_setup', course_slug=course_slug, activity_slug=activity_slug) return decorate
Example #27
Source File: views.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def issue_add_article(request, issue_id): """ Allows an editor to add an article to an issue. :param request: django request object :param issue_id: PK of an Issue object :return: a contextualised django template """ issue = get_object_or_404(models.Issue, pk=issue_id, journal=request.journal) articles = submission_models.Article.objects.filter( journal=request.journal, ).exclude( Q(pk__in=issue.article_pks) | Q(stage=submission_models.STAGE_REJECTED) ) if request.POST.get('article'): article_id = request.POST.get('article') article = get_object_or_404(submission_models.Article, pk=article_id, journal=request.journal) if not article.section: messages.add_message(request, messages.WARNING, 'Articles without a section cannot be added to an issue.') return redirect(reverse('issue_add_article', kwargs={'issue_id': issue.pk})) else: issue.articles.add(article) return redirect(reverse('manage_issues_id', kwargs={'issue_id': issue.pk})) template = 'journal/manage/issue_add_article.html' context = { 'issue': issue, 'articles': articles, } return render(request, template, context)
Example #28
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def sort_issues(request, issue_list): """ Sorts issues by date either asc or dsc :param request: HttpRequest :param issue_list: Issue queryset for sorting :return: None """ sort_type = request.POST.get('sort', None) if not sort_type: messages.add_message( request, messages.WARNING, 'No sort type provided.', ) return if sort_type == 'date_sort_desc': order = '-date' else: order = 'date' ordered_issues = issue_list.order_by(order) for order, issue in enumerate(ordered_issues): issue.order = order issue.save()
Example #29
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def set_render_galley(request, article): galley_id = request.POST.get('render_galley') if galley_id: galley = core_models.Galley.objects.get(pk=galley_id) article.render_galley = galley article.fixedpubcheckitems.select_render_galley = True article.fixedpubcheckitems.save() article.save() messages.add_message(request, messages.SUCCESS, 'Render galley has been set.') else: messages.add_message(request, messages.WARNING, 'No galley id supplied.')
Example #30
Source File: logic.py From janeway with GNU Affero General Public License v3.0 | 5 votes |
def handle_unassign_issue(request, article, issues): try: issue_to_unassign = journal_models.Issue.objects.get(pk=request.POST.get('unassign_issue', None)) if issue_to_unassign in issues: issue_to_unassign.articles.remove(article) issue_to_unassign.save() messages.add_message(request, messages.SUCCESS, 'Article unassigned from Issue.') else: messages.add_message(request, messages.WARNING, 'Issue not in this journals issue list.') except journal_models.Issue.DoesNotExist: messages.add_message(request, messages.WARNING, 'Issue does no exist.')