django.shortcuts.get_object_or_404 - python examples

Here are the examples of the python api django.shortcuts.get_object_or_404 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@login_required
@has_request
@typesetting_user_or_production_user_or_editor_required
def epub_generate(request, galley_id):

    galley = get_object_or_404(core_models.Galley, pk=galley_id)
    epub.generate_ebook_lib_epub(request, galley)

    return redirect(request.GET['return'])

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
def index(request):
    
    if request.method == 'POST':
        apps = request.POST.getlist('apps')
        action = request.POST['action']
        for app_id in apps:
            if request.user.is_staff:
                app = get_object_or_404(App, pk=app_id)
            else:
                app = get_object_or_404(App, pk=app_id, user=request.user)
        
            if action == "delete":
                app.delete()

    app_list = App.objects.all()[:5]
    context = {'app_list': app_list}
    return render(request, 'mapps/index.html', context)

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def handle_proof_decision(request, proofing_task_id, decision):
    proofing_task = get_object_or_404(models.ProofingTask,
                                      proofreader=request.user,
                                      pk=proofing_task_id)
    if decision == 'accept':
        proofing_task.accepted = timezone.now()
    elif decision == 'decline':
        proofing_task.completed = timezone.now()
    proofing_task.save()
    kwargs = {'request': request, 'proofing_task': proofing_task, 'decision': decision}
    event_logic.Events.raise_event(event_logic.Events.ON_PROOFREADER_TASK_DECISION,
                                   task_object=proofing_task.round.astignment.article,
                                   **kwargs)
    messages.add_message(request, messages.INFO, 'Proofing Task {0} decision: {1}'.format(proofing_task_id, decision))

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
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.')

3 View Complete Implementation : decorators.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def is_article_preprint_editor(func):
    """
    Checks that the current user is a preprint editor for the current paper
    :param func:
    :return:
    """

    def wrapper(request, *args, **kwargs):
        if not base_check(request):
            return redirect('{0}?next={1}'.format(reverse('core_login'), request.path_info))

        article = get_object_or_404(models.Article.preprints, pk=kwargs['article_id'])

        if request.user in article.subject_editors() or request.user.is_staff:
            return func(request, *args, **kwargs)

        deny_access(request)

    return wrapper

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@typesetting_user_or_production_user_or_editor_required
def preview_figure(request, article_id, galley_id, file_name):
    galley = get_object_or_404(core_models.Galley,
                               pk=galley_id,
                               article__pk=article_id,
                               article__journal=request.journal)
    return article_figure(request, galley.article.pk, galley_id, file_name)

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def view(request, disease_id):
    disease = get_object_or_404(Disease, pk=disease_id)
    gene = disease.gene_set.all()[0]
    # print 'gene', gene.official_name
    # individuals = Individual.objects.all()
    individuals_variants = Variant.objects.filter(gene=gene.official_name)
    # individuals_variants = []
    # for individual in individuals:
    #     individual_variants = Variant.objects.filter(individual=individual, gene=gene.official_name)
    #     individuals_variants.append(individual_variants)
#    individual_variants.query.group_by = ['individual_id']
#    results = query.execute_sql()
#    individuals = Individual.objects.all()
#    for individual in individuals:
#        individual_variants = Variant.objects.find(filter(date__range=["2011-01-01", "2011-01-31"]))
    
    
    return render(request, 'diseases/view.html', {'disease': disease, 'variants': individuals_variants})

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def project_files(request, project_id):

    if request.user.is_staff:
        project = get_object_or_404(Project, pk=project_id)
    else:
        project = get_object_or_404(Project, pk=project_id, user=request.user)

    n_files = project.projectfile_set.count()

    context = {
        'project': project,
        'n_files':n_files
    }
    
    return render(request, 'projects/project_files.html', context)

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def view(request, disease_id):
    disease = get_object_or_404(Disease, pk=disease_id)
    gene = disease.gene_set.all()[0]
    # print 'gene', gene.official_name
    # individuals = Individual.objects.all()
    individuals_variants = Variant.objects.filter(gene=gene.official_name)
    # individuals_variants = []
    # for individual in individuals:
    #     individual_variants = Variant.objects.filter(individual=individual, gene=gene.official_name)
    #     individuals_variants.append(individual_variants)
#    individual_variants.query.group_by = ['individual_id']
#    results = query.execute_sql()
#    individuals = Individual.objects.all()
#    for individual in individuals:
#        individual_variants = Variant.objects.find(filter(date__range=["2011-01-01", "2011-01-31"]))
    
    
    return render(request, 'diseases/view.html', {'disease': disease, 'variants': individuals_variants})

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def handle_updating_subject(request, preprint):
    """
    Pulls a subject pk from POST, checks it exists and astigns 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.'))

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def get_current_field(request, field_id):
    """
    Fetches a field based on whether there is a journal or press in the request object
    :param request: HttpRequest
    :param field_id: Field PK
    :return: Field Object
    """
    if field_id:
        if request.journal:
            field = get_object_or_404(models.Field, pk=field_id, journal=request.journal)
        else:
            field = get_object_or_404(models.Field, pk=field_id, press=request.press)
    else:
        field = None

    return field

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@production_user_or_editor_required
def order_authors(request, article_id):
    article = get_object_or_404(models.Article, pk=article_id, journal=request.journal)

    if request.POST:
        ids = [int(_id) for _id in request.POST.getlist('authors[]')]

        for author in article.frozenauthor_set.all():
            order = ids.index(author.pk)
            author.order = order
            author.save()

    return HttpResponse('Thanks')

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def handle_typeset_decision(request, typeset_task_id, decision):
    typeset_task = get_object_or_404(
        models.TypesetterProofingTask,
        typesetter=request.user,
        pk=typeset_task_id,
        proofing_task__round__astignment__article__journal=request.journal,
    )
    if decision == 'accept':
        typeset_task.accepted = timezone.now()
    elif decision == 'decline':
        typeset_task.completed = timezone.now()
    typeset_task.save()
    kwargs = {'request': request, 'typeset_task': typeset_task, 'decision': decision}
    event_logic.Events.raise_event(event_logic.Events.ON_PROOFING_TYPESET_DECISION,
                                   task_object=typeset_task.proofing_task.round.astignment.article,
                                   **kwargs)
    messages.add_message(request, messages.INFO, 'Typeset Task {0} decision: {1}'.format(typeset_task_id, decision))

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def get_preprint_article_if_id(request, article_id):
    if article_id:
        article = get_object_or_404(submission_models.Article.preprints,
                                    pk=article_id,
                                    date_submitted__isnull=True)
    else:
        article = None

    return article

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def handle_delete_subject(request):
    subject_id = request.POST.get('delete')

    subject = get_object_or_404(models.Subject, pk=subject_id)
    messages.add_message(request, messages.INFO, 'Subject "{subject}" deleted.'.format(subject=subject.name))
    subject.delete()
    return redirect(reverse('preprints_subjects'))

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def edit(request, individual_id):
    individual = get_object_or_404(Individual, pk=individual_id)
    if request.method == 'POST':
        form = IndividualForm(request.POST, instance=individual)
        if form.is_valid():
            form.save()
            return redirect('dashboard')
    #     form = IndividualForm(request.POST, request.FILES)
    #     if form.is_valid():
    #         individual = form.save(commit=False)
    #         individual.user = request.user
    #         individual.save()
    #         return redirect('dashboard')
    else:
        form = IndividualForm(instance=individual)

    return render(request, 'individuals/individual_form.html', {'form':form})

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
def index(request):
    
    if request.method == 'POST':
        apps = request.POST.getlist('apps')
        action = request.POST['action']
        for app_id in apps:
            if request.user.is_staff:
                app = get_object_or_404(App, pk=app_id)
            else:
                app = get_object_or_404(App, pk=app_id, user=request.user)
        
            if action == "delete":
                app.delete()

    app_list = App.objects.all()[:5]
    context = {'app_list': app_list}
    return render(request, 'mapps/index.html', context)

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def view(request, disease_id):
    disease = get_object_or_404(Disease, pk=disease_id)
    gene = disease.gene_set.all()[0]
    # print 'gene', gene.official_name
    # individuals = Individual.objects.all()
    individuals_variants = Variant.objects.filter(gene=gene.official_name)
    # individuals_variants = []
    # for individual in individuals:
    #     individual_variants = Variant.objects.filter(individual=individual, gene=gene.official_name)
    #     individuals_variants.append(individual_variants)
#    individual_variants.query.group_by = ['individual_id']
#    results = query.execute_sql()
#    individuals = Individual.objects.all()
#    for individual in individuals:
#        individual_variants = Variant.objects.find(filter(date__range=["2011-01-01", "2011-01-31"]))
    
    
    return render(request, 'diseases/view.html', {'disease': disease, 'variants': individuals_variants})

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def comment_manager_post(request, preprint):
    if 'comment_public' in request.POST:
        comment_id = request.POST.get('comment_public')
    else:
        comment_id = request.POST.get('comment_reviewed')

    comment = get_object_or_404(models.Comment, pk=comment_id, article=preprint)

    if 'comment_public' in request.POST:
        if comment.is_public:
            comment.is_public = False
        else:
            comment.is_public = True

        comment.is_reviewed = True
    else:
        comment.is_reviewed = True

    comment.save()

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def view(request, variant_id):
    variant = get_object_or_404(Variant, pk=variant_id)

    variant.info = json.loads(variant.info)

    new_dict = SortedDict()
    key_list = list(variant.info.keys())
    key_list.sort()
    for key in key_list:
        new_dict[key] = variant.info[key]

    variant.info = new_dict
    print(type(variant.info))

    return render(request, 'variants/view.html', {'variant': variant})

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def project_files(request, project_id):

    if request.user.is_staff:
        project = get_object_or_404(Project, pk=project_id)
    else:
        project = get_object_or_404(Project, pk=project_id, user=request.user)

    n_files = project.projectfile_set.count()

    context = {
        'project': project,
        'n_files':n_files
    }
    
    return render(request, 'projects/project_files.html', context)

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def handle_author_post(request, preprint):
    file = request.FILES.get('file')
    update_type = request.POST.get('upload_type')
    galley_id = request.POST.get('galley_id')
    galley = get_object_or_404(core_models.Galley, article=preprint, pk=galley_id)

    if request.press.preprint_pdf_only and not files.check_in_memory_mime(in_memory_file=file) == 'application/pdf':
        messages.add_message(request, messages.WARNING, 'You must upload a PDF file.')
        return
    else:
        file = files.save_file_to_article(file, preprint, request.user, label=galley.label)

    models.VersionQueue.objects.create(article=preprint, galley=galley, file=file, update_type=update_type)

    messages.add_message(request, messages.INFO, 'This update has been added to the moderation queue.')

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@proofreader_for_article_required
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.astignment.article)
    else:
        messages.add_message(request, messages.WARNING, 'Requested file is not a galley for proofing')
        return redirect(request.META.get('HTTP_REFERER'))

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def handle_self_typesetter_astignment(production_astignment, request):
    user = get_object_or_404(core_models.Account, pk=request.POST.get('typesetter_id'))
    typeset_task = models.TypesetTask(
        astignment=production_astignment,
        typesetter=user,
        notified=True,
        accepted=timezone.now(),
        typeset_task='This is a self astignment.',
    )

    typeset_task.save()

    messages.add_message(request, messages.SUCCESS, 'You have been astigned as a typesetter to this article.')

    return typeset_task

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@login_required
@has_request
@typesetting_user_or_production_user_or_editor_required
def castius_generate(request, galley_id):

    galley = get_object_or_404(core_models.Galley, pk=galley_id)

    temporary_directory = os.path.join(settings.BASE_DIR, 'files', 'temp')

    driver = CastiusDriver(temporary_directory, galley, request)
    driver.transform()

    return redirect(request.GET['return'])

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def edit(request, individual_id):
    individual = get_object_or_404(Individual, pk=individual_id)
    if request.method == 'POST':
        form = IndividualForm(request.POST, instance=individual)
        if form.is_valid():
            form.save()
            return redirect('dashboard')
    #     form = IndividualForm(request.POST, request.FILES)
    #     if form.is_valid():
    #         individual = form.save(commit=False)
    #         individual.user = request.user
    #         individual.save()
    #         return redirect('dashboard')
    else:
        form = IndividualForm(instance=individual)

    return render(request, 'individuals/individual_form.html', {'form':form})

3 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@typesetter_or_editor_required
def delete_galley(request, typeset_id, galley_id):
    """
    Allows for deletion of a Galley
    :param request: HttpRequest object
    :param typeset_id: TypesetTask object PK
    :param galley_id: Galley object PK
    :return:
    """
    galley = get_object_or_404(
        core_models.Galley,
        pk=galley_id,
        article__journal=request.journal,
    )
    galley.file.unlink_file()
    galley.delete()

    return redirect(reverse('do_typeset_task', kwargs={'typeset_id': typeset_id}))

3 View Complete Implementation : views.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : raonyguimaraes
@login_required
def view(request, variant_id):
    variant = get_object_or_404(Variant, pk=variant_id)

    variant.info = json.loads(variant.info)

    new_dict = SortedDict()
    key_list = list(variant.info.keys())
    key_list.sort()
    for key in key_list:
        new_dict[key] = variant.info[key]

    variant.info = new_dict
    print(type(variant.info))

    return render(request, 'variants/view.html', {'variant': variant})

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def get_model_and_object(model_name, model_pk):
    model = None
    if model_name == 'proofing':
        model = models.ProofingTask
    elif model_name == 'correction':
        model = models.TypesetterProofingTask

    if model:
        return [model, get_object_or_404(model, pk=model_pk, acknowledged__isnull=True)]
    else:
        return [None, None]

3 View Complete Implementation : logic.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
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

0 View Complete Implementation : decorators.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def section_editor_draft_decisions(func):
    """This decorator will check if: the user is a section editor and deny them access if draft decisions
    is enabled on the given journal.

    :param func: the function to callback from the decorator
    :return: either the function call or raises an permissiondenied.
    """
    def wrapper(request, *args, **kwargs):
        article_id = kwargs.get('article_id', None)
        drafting = setting_handler.get_setting('general', 'draft_decisions', request.journal).value

        if request is None or request.user is None:
            deny_access(request)

        if request.user.is_section_editor(request) and article_id:
            article = get_object_or_404(models.Article, pk=article_id)
            if request.user in article.section_editors() and drafting:
                deny_access(request)

        return func(request, *args, **kwargs)

    return wrapper

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@typesetting_user_or_production_user_or_editor_required
def preview_galley(request, article_id, galley_id):
    """
    Displays a preview of a galley object
    :param request: HttpRequest object
    :param article_id: Article object PK
    :param galley_id: Galley object PK
    :return: HttpResponse
    """
    article = get_object_or_404(
        submission_models.Article,
        pk=article_id,
        journal=request.journal,
    )
    galley = get_object_or_404(
        core_models.Galley,
        pk=galley_id,
        article=article,
    )

    if galley.type == 'xml' or galley.type == 'html':
        template = 'proofing/preview/rendered.html'
    elif galley.type == 'epub':
        template = 'proofing/preview/epub.html'
    else:
        template = 'proofing/preview/embedded.html'

    context = {
        'galley': galley,
        'article': article
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@staff_member_required
def delete_license(request, license_pk):
    """
    Presents an interface to delete a license object.
    :param request: HttpRequest object
    :param license_pk: int, Licence object pk
    :return: HttpResponse or HttpRedirect
    """
    license_to_delete = get_object_or_404(
        models.Licence,
        pk=license_pk,
        journal=request.journal
    )
    license_articles = models.Article.objects.filter(
        license=license_to_delete
    )

    if request.POST and 'delete' in request.POST:
        messages.add_message(
            request,
            messages.INFO,
            'License {0} deleted'.format(license_to_delete.name)
        )
        license_to_delete.delete()

        return redirect(reverse('submission_licenses'))

    template = 'submission/manager/delete_license.html'
    context = {
        'license': license_to_delete,
        'license_articles': license_articles,
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@proofreader_for_article_required
def preview_galley(request, proofing_task_id, galley_id):
    """
    Displays a preview of a galley object
    :param request: HttpRequest object
    :param proofing_task_id: ProofingTask object PK
    :param galley_id: Galley object PK
    :return: HttpResponse
    """
    proofing_task = get_object_or_404(models.ProofingTask, pk=proofing_task_id)
    galley = get_object_or_404(proofing_task.galleys_for_proofing, pk=galley_id)

    if galley.type == 'xml' or galley.type == 'html':
        template = 'proofing/preview/rendered.html'
    elif galley.type == 'epub':
        template = 'proofing/preview/epub.html'
    else:
        template = 'proofing/preview/embedded.html'

    context = {
        'proofing_task': proofing_task,
        'galley': galley,
        'article': proofing_task.round.astignment.article
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@staff_member_required
def serve_press_file(request, file_id):
    """
    If a user is staff this view will serve a press file.
    :param request: HttpRequest
    :param file_id: core.File object pk
    :return: HttpStreamingResponse or Http404
    """
    file = get_object_or_404(core_models.File, pk=file_id)

    # If the file has an article_id the press should not serve it.
    # TODO: when untangling Files/Galleys this should be reviewed
    if file.article_id:
        raise Http404

    path_parts = ('press',)

    response = files.serve_any_file(
        request,
        file,
        False,
        path_parts=path_parts,
    )

    return response

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@proofing_manager_for_article_required
def complete_proofing(request, article_id):
    """
    Allows a proofing manager to mark proofing a complete
    :param request: HttpRequest object
    :param article_id: Article object PK
    :return: HttpResponse object
    """
    article = get_object_or_404(submission_models.Article,
                                stage=submission_models.STAGE_PROOFING,
                                pk=article_id)
    message = logic.get_complete_proofing_message(request, article)

    if request.POST:
        message = request.POST.get('content_email')
        article.stage = submission_models.STAGE_READY_FOR_PUBLICATION
        article.proofingastignment.completed = timezone.now()
        article.save()

        journal_models.FixedPubCheckItems.objects.get_or_create(article=article)

        kwargs = {'request': request, 'article': article, 'user_message': message,
                  'skip': True if 'skip' in request.POST else False}
        event_logic.Events.raise_event(event_logic.Events.ON_PROOFING_COMPLETE, task_object=article, **kwargs)

        if request.journal.element_in_workflow(element_name='proofing'):
            workflow_kwargs = {'handshake_url': 'proofing_list', 'request': request, 'article': article,
                               'switch_stage': True}
            return event_logic.Events.raise_event(event_logic.Events.ON_WORKFLOW_ELEMENT_COMPLETE, task_object=article,
                                                  **workflow_kwargs)
        else:
            return redirect(reverse('publish_article', kwargs={'article_id': article.pk}))

    template = 'proofing/complete_proofing.html'
    context = {
        'article': article,
        'message': message,
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@staff_member_required
def create_template(request, reminder_id, template_name):
    """
    If a new Reminder.template doesn't exist, they are redirected here to create a new one.
    :param request: HttpRequest object
    :param reminder_id: Reminder object PK
    :param template_name: string, Reminder.template string
    :return: if POST HttpRedirect otherwise HttpResponse
    """
    reminder = get_object_or_404(models.Reminder, journal=request.journal, pk=reminder_id)

    if request.POST:
        template = request.POST.get('template')
        setting_handler.create_setting('email', template_name, 'rich-text', reminder.subject, '', is_translatable=True)
        setting_handler.save_setting('email', template_name, request.journal, template)

        return redirect(reverse('cron_reminders'))

    template = 'cron/create_template.html'
    context = {
        'reminder': reminder,
        'template_name': template_name,
    }

    return render(request, template, context)

0 View Complete Implementation : decorators.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def editor_user_required(func):
    """ This decorator checks that a user is an editor, Note that this decorator does NOT check for conflict of interest
    problems. Use the article_editor_user_required decorator (not yet written) to do a check against an article.

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

    def wrapper(request, *args, **kwargs):

        article_id = kwargs.get('article_id', None)

        if not base_check(request):
            return redirect('{0}?next={1}'.format(reverse('core_login'), request.path_info))

        if request.user.is_editor(request) or request.user.is_staff:
            return func(request, *args, **kwargs)

        elif request.user.is_section_editor(request) and article_id:
            article = get_object_or_404(models.Article, pk=article_id)
            if request.user in article.section_editors():
                return func(request, *args, **kwargs)
            else:
                deny_access(request, "You are not a section editor for this article")

        else:
            deny_access(request)

    return wrapper

0 View Complete Implementation : decorators.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
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

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@proofing_manager_for_article_required
def acknowledge(request, article_id, model_name, model_pk):
    """
    Acks a ProofingTask or TypesetterProofingTask
    :param request: HttpRequest object
    :param article_id: Article object PK
    :param model_name: string, name of a model
    :param model_pk: int, PK of model
    :return: HttpRedirect or HttpResponse
    """
    model, model_object = logic.get_model_and_object(model_name, model_pk)
    article = get_object_or_404(submission_models.Article, pk=article_id)
    text = logic.get_ack_message(request, article, model_name, model_object)

    if request.POST:
        message = request.POST.get('content_email', None)
        kwargs = {'request': request,
                  'article': article,
                  'user_message': message,
                  'model_object': model_object,
                  'model_name': model_name,
                  'skip': True if 'skip' in request.POST else False}
        event_logic.Events.raise_event(event_logic.Events.ON_PROOFING_ACK, task_object=article, **kwargs)
        model_object.acknowledged = timezone.now()
        model_object.save()
        return redirect(reverse('proofing_article', kwargs={'article_id': article.pk}))

    template = 'proofing/acknowledge.html'
    context = {
        'model': model,
        'model_object': model_object,
        'model_name': model_name,
        'text': text,
        'article': article,
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@proofreader_for_article_required
def delete_note(request, proofing_task_id, galley_id):
    """
    Allows Proofreader to delete a note
    :param request: HttpRequest object
    :param proofing_task_id: ProofingTask object PK
    :param galley_id: Galley object PK
    :return: HttpResponse
    """
    if request.user.is_staff:
        get_object_or_404(models.ProofingTask, pk=proofing_task_id)
    else:
        get_object_or_404(models.ProofingTask,
                          (Q(proofreader=request.user) |
                           Q(round__astignment__proofing_manager=request.user)),
                          pk=proofing_task_id)

    if request.POST:
        note_id = request.POST.get('note_id')
        note = get_object_or_404(models.Note, galley__pk=galley_id, pk=note_id)
        note.delete()

        return_dict = {'id': note.pk, 'deleted': True}

    else:
        return_dict = {'deleted': False}

    return HttpResponse(json.dumps(return_dict), content_type="application/json")

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@editor_user_required
def featured_articles(request):

    featured_arts = models.FeaturedArticle.objects.filter(journal=request.journal)
    featured_article_pks = [f.article.pk for f in featured_arts.all()]
    articles = submission_models.Article.objects.filter(date_published__isnull=False,
                                                        journal=request.journal).exclude(pk__in=featured_article_pks)

    if 'article_id' in request.POST:
        article_id = request.POST.get('article_id')
        article = get_object_or_404(submission_models.Article, pk=article_id, journal=request.journal)

        models.FeaturedArticle.objects.create(
            article=article,
            journal=request.journal,
            added_by=request.user,
            sequence=request.journal.next_featured_article_order()
        )

        return redirect(reverse('featured_articles_setup'))

    if 'delete' in request.POST:
        article_id = request.POST.get('delete')
        featured_article = get_object_or_404(models.FeaturedArticle, article__pk=article_id,
                                             journal=request.journal)
        featured_article.delete()
        return redirect(reverse('featured_articles_setup'))

    template = 'featured_setup.html'
    context = {
        'featured_articles': featured_arts,
        'articles': articles,
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@proofing_manager_or_editor_required
def proofing_astign_article(request, article_id, user_id=None):
    """
    astigns 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_astignment = models.Proofingastignment.objects.create(article=article,
                                                                       proofing_manager=user,
                                                                       notified=True,
                                                                       editor=request.user)
        proofing_astignment.add_new_proofing_round()

        message = "{0} has been astigned as proofing manager to {1}".format(
            proofing_astignment.proofing_manager.full_name(),
            proofing_astignment.article.satle)
        messages.add_message(request, messages.INFO, message)

        kwargs = {
            'request': request, 'proofing_astignment': proofing_astignment,
        }
        event_logic.Events.raise_event(event_logic.Events.ON_PROOFING_MANAGER_astIGNMENT, task_object=article, **kwargs)

    else:
        messages.add_message(request, messages.WARNING, 'User is not a proofing manager.')

    return redirect(reverse('proofing_list'))

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@typesetter_for_corrections_required
def typesetting_corrections(request, typeset_task_id):
    """
    Allows a typesetter to undertake corrections
    :param request: HttpRequest object
    :param typeset_task_id: TypesetterProofingTask PK
    :return: HttpRedirect or HttpResponse
    """
    typeset_task = get_object_or_404(models.TypesetterProofingTask, pk=typeset_task_id)
    article = typeset_task.proofing_task.round.astignment.article
    form = forms.CompleteCorrections(instance=typeset_task)

    if request.POST:
        form = forms.CompleteCorrections(request.POST, instance=typeset_task)

        if form.is_valid():
            typeset_task = form.save(commit=False)
            typeset_task.completed = timezone.now()
            typeset_task.save()

            kwargs = {'article': article, 'typeset_task': typeset_task, 'request': request}
            event_logic.Events.raise_event(event_logic.Events.ON_CORRECTIONS_COMPLETE, task_object=article, **kwargs)

            messages.add_message(request, messages.INFO, 'Corrections task complete')
            return redirect(reverse('proofing_correction_requests'))

    template = 'proofing/typesetting/typesetting_corrections.html'
    context = {
        'typeset_task': typeset_task,
        'article': article,
        'form': form,
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def view_page(request, page_name):
    """
    Displays an individual CMS page using either the journal or press page template.
    :param request: HttpRequest object
    :param page_name: a string matching models.Page.page_name
    :return: HttpResponse object
    """
    current_page = get_object_or_404(models.Page, name=page_name,
                                     content_type=request.model_content_type,
                                     object_id=request.site_type.pk)

    if request.journal:
        template = 'cms/page.html'
    else:
        template = 'press/cms/page.html'
    context = {
        'page': current_page,
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@preprint_editor_or_author_required
def preprints_author_article(request, article_id):
    """
    Allows authors to view the metadata and replace galley files for their articles.
    :param request: HttpRequest
    :param article_id: Article PK
    :return: HttpRedirect if POST or HttpResponse
    """
    preprint = get_object_or_404(submission_models.Article.preprints, pk=article_id)
    metrics_summary = preprint_logic.metrics_summary([preprint])

    if request.POST:
        if 'submit' in request.POST:
            return preprint_logic.handle_preprint_submission(request, preprint)
        else:
            preprint_logic.handle_author_post(request, preprint)
            return redirect(reverse('preprints_author_article', kwargs={'article_id': preprint.pk}))

    template = 'admin/preprints/author_article.html'
    context = {
        'preprint': preprint,
        'metrics_summary': metrics_summary,
        'preprint_journals': preprint_logic.get_list_of_preprint_journals(),
        'pending_updates': models.VersionQueue.objects.filter(article=preprint, date_decision__isnull=True)
    }

    return render(request, template, context)

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
@login_required
@article_edit_user_required
def delete_author(request, article_id, author_id):
    """Allows submitting author to delete an author object."""
    article = get_object_or_404(
        models.Article,
        pk=article_id,
        journal=request.journal
    )
    author = get_object_or_404(
        core_models.Account,
        pk=author_id
    )

    article.authors.remove(author)

    if article.correspondence_author == author:
        article.correspondence_author = None

    try:
        ordering = models.ArticleAuthorOrder.objects.get(
            article=article,
            author=author,
        ).delete()
    except models.ArticleAuthorOrder.DoesNotExist:
        past

    return redirect(reverse('submit_authors', kwargs={'article_id': article_id}))

0 View Complete Implementation : decorators.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def copyeditor_for_copyedit_required(func):
    """ This decorator checks that a user is a copyeditor and that they are the copyeditor for this article.

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

    def wrapper(request, *args, **kwargs):
        if not base_check(request):
            return redirect('{0}?next={1}'.format(reverse('core_login'), request.path_info))

        copyedit_id = kwargs['copyedit_id']
        copyedit = get_object_or_404(copyediting_models.Copyeditastignment, pk=copyedit_id)

        if request.user == copyedit.copyeditor and request.user.is_copyeditor(request) or request.user.is_staff:
            return func(request, *args, **kwargs)
        else:
            deny_access(request)

    return wrapper

0 View Complete Implementation : views.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def preprints_list(request, subject_slug=None):
    """
    Displays a list of all published preprints.
    :param request: HttpRequest
    :return: HttpResponse
    """
    if subject_slug:
        subject = get_object_or_404(models.Subject, slug=subject_slug)
        articles = preprint_logic.get_subject_articles(subject)
    else:
        subject = None
        articles = submission_models.Article.preprints.filter(date_published__lte=timezone.now())

    paginator = Paginator(articles, 15)
    page = request.GET.get('page', 1)

    try:
        articles = paginator.page(page)
    except PageNotAnInteger:
        articles = paginator.page(1)
    except EmptyPage:
        articles = paginator.page(paginator.num_pages)

    template = 'preprints/list.html'
    context = {
        'articles': articles,
        'subject': subject,
        'subjects': models.Subject.objects.filter(enabled=True)
    }

    return render(request, template, context)

0 View Complete Implementation : decorators.py
Copyright GNU Affero General Public License v3.0
Author : BirkbeckCTP
def article_stage_review_required(func):
    """
    Checks that the article is in one of the review stages
    :param func: func
    :return: PermissionDenied or func
    """

    def review_required_wrapper(request, article_id=None, *args, **kwargs):
        if not article_id:
            logger.debug('404 thrown as no article_id in kwargs')
            raise Http404

        article = get_object_or_404(
            models.Article,
            pk=article_id
        )

        if not article.stage in models.REVIEW_STAGES:
            deny_access(request)
        else:
            return func(request, article_id, *args, **kwargs)

    return review_required_wrapper