e8bafba0d6a342e0a6de13f4ca05b71a111f22e1,app/grandchallenge/core/views.py,,comicmain,#Any#Any#,188

Before Change


def comicmain(request, page_title=""):
     show content as main page item. Loads pages from the main project 
    challenge_short_name = settings.MAIN_PROJECT_NAME
    if Challenge.objects.filter(short_name=challenge_short_name).count() == 0:
        link = reverse("challenges:create")
        link = link + "?short_name=%s" % challenge_short_name
        link_html = create_HTML_a(
            link, "Create project "%s"" % challenge_short_name
        )
        html = I"m trying to show the first page for main project "%s" here,
        but "%s" does not exist. %s. % (
            challenge_short_name,
            challenge_short_name,
            link_html,
        )
        p = create_temp_page(title="no_pages_found", html=html)
        return render(
            request, "temppage.html", {"site": p.challenge, "currentpage": p}
        )

    pages = getPages(challenge_short_name)
    if pages.count() == 0:
        link = reverse("pages:list", args=[challenge_short_name])
        link_html = create_HTML_a(link, "admin interface")
        html = I"m trying to show the first page for main project "%s" here,
        but "%s" contains no pages. Please add
        some in the %s. % (
            challenge_short_name,
            challenge_short_name,
            link_html,
        )
        p = create_temp_page(title="no_pages_found", html=html)
        return render(
            request, "temppage.html", {"site": p.challenge, "currentpage": p}
        )

    elif page_title == "":
        // if no page title is given, just use the first page found
        p = pages[0]
        p.html = renderTags(request, p)
    else:
        try:
            p = Page.objects.get(
                challenge__short_name=challenge_short_name,
                title__iexact=page_title,
            )
        except Page.DoesNotExist:
            raise Http404

    p.html = renderTags(request, p)
    // render page contents using django template system
    // This makes it possible to use tags like "{% dataset %}" in page

After Change


    challenge_short_name = settings.MAIN_PROJECT_NAME

    try:
        site = getSite(challenge_short_name)
    except Challenge.DoesNotExist:
        link = reverse("challenges:create")
        link = link + "?short_name=%s" % challenge_short_name
        link_html = create_HTML_a(
            link, "Create project "%s"" % challenge_short_name
        )
        html = I"m trying to show the first page for main project "%s" here,
        but "%s" does not exist. %s. % (
            challenge_short_name,
            challenge_short_name,
            link_html,
        )
        page = create_temp_page(title="no_pages_found", html=html)

        return render(
            request,
            "temppage.html",
            {"site": page.challenge, "currentpage": page},
        )

    pages = site.page_set.all()

    if len(pages) == 0:
        link = reverse("pages:list", args=[challenge_short_name])
        link_html = create_HTML_a(link, "admin interface")
        html = I"m trying to show the first page for main project "%s" here,
        but "%s" contains no pages. Please add
        some in the %s. % (
            challenge_short_name,
            challenge_short_name,
            link_html,
        )
        page = create_temp_page(title="no_pages_found", html=html)

        return render(
            request,
            "temppage.html",
            {"site": page.challenge, "currentpage": page},
        )

    if page_title:
        pages = [p for p in pages if p.title.lower() == page_title.lower()]

        if len(pages) != 1:
            raise ValueError(
                f"More than 1 page with title {page_title} was found for {site}"
            )

    page = pages[0]
    page.html = renderTags(request, page)

    return render(request, "page.html", {"currentpage": page})
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 6

Instances


Project Name: comic/grand-challenge.org
Commit Name: e8bafba0d6a342e0a6de13f4ca05b71a111f22e1
Time: 2018-10-18
Author: jamesmeakin@gmail.com
File Name: app/grandchallenge/core/views.py
Class Name:
Method Name: comicmain


Project Name: craffel/mir_eval
Commit Name: 98ae38f57c7a7a369604b4bb78d9879c4a990a24
Time: 2017-03-17
Author: bmcfee@users.noreply.github.com
File Name: mir_eval/chord.py
Class Name:
Method Name: validate_chord_label


Project Name: AlexsLemonade/refinebio
Commit Name: bf4d4be450616eeb0252b276c9febc4a50e83ace
Time: 2020-07-06
Author: willvauclain.dev@gmail.com
File Name: api/data_refinery_api/views/dataset.py
Class Name:
Method Name: validate_dataset