Esempio n. 1
0
def create_temp_page(title="temp_page", html=""):
    """ Create a quick mockup page which you can show, without needing to read 
    anything from database
    
    """
    site = Challenge()  # any page requires a site, create on the fly here.
    site.short_name = "Temp"
    site.name = "Temporary page"
    site.skin = ""
    return Page(challenge=site, title=title, html=html)
Esempio n. 2
0
def upload_handler(request, challenge_short_name):
    """
    Upload a file to the given comicsite, display files previously uploaded
    """
    view_url = reverse('uploads:create',
                       kwargs={'challenge_short_name': challenge_short_name})
    if request.method == 'POST':
        # set values excluded from form here to make the model validate
        site = getSite(challenge_short_name)
        uploadedFile = UploadModel(
            challenge=site,
            permission_lvl=UploadModel.ADMIN_ONLY,
            user=request.user,
        )
        # ADMIN_ONLY
        form = UserUploadForm(request.POST,
                              request.FILES,
                              instance=uploadedFile)
        if form.is_valid():
            form.save()
            filename = ntpath.basename(form.instance.file.file.name)
            messages.success(
                request,
                (f"File '{filename}' sucessfully uploaded. "
                 f"An email has been sent to this projects organizers."),
            )
            send_file_uploaded_notification_email(
                uploader=request.user,
                filename=filename,
                challenge=site,
                site=get_current_site(request),
            )
            return HttpResponseRedirect(view_url)

        else:
            # continue to showing errors
            pass
    else:
        form = UserUploadForm()
    [site, pages,
     metafooterpages] = site_get_standard_vars(challenge_short_name)
    if not (site.is_admin(request.user) or site.is_participant(request.user)):
        p = Page(challenge=site, title="files")
        currentpage = permissionMessage(request, site, p)
        response = render(
            request,
            'page.html',
            {
                'site': site,
                'currentpage': currentpage,
                "pages": pages,
                "metafooterpages": metafooterpages,
            },
        )
        response.status_code = 403
        return response

    return render(
        request,
        'uploads/comicupload.html',
        {
            'form': form,
            'upload_url': view_url,
            'site': site,
            'pages': pages,
            'metafooterpages': metafooterpages,
        },
    )
Esempio n. 3
0
def upload_handler(request):
    """
    Upload a file to the given comicsite, display files previously uploaded
    """
    site = request.challenge

    view_url = reverse(
        "uploads:create", kwargs={"challenge_short_name": site.short_name}
    )

    if request.method == "POST":
        # set values excluded from form here to make the model validate
        uploadedFile = UploadModel(
            challenge=site,
            permission_lvl=UploadModel.ADMIN_ONLY,
            user=request.user,
        )
        # ADMIN_ONLY
        form = UserUploadForm(
            request.POST, request.FILES, instance=uploadedFile
        )
        if form.is_valid():
            form.save()
            filename = basename(form.instance.file.file.name)
            messages.success(
                request,
                (
                    f"File '{filename}' sucessfully uploaded. "
                    f"An email has been sent to this projects organizers."
                ),
            )
            send_file_uploaded_notification_email(
                uploader=request.user,
                filename=filename,
                challenge=site,
                site=get_current_site(request),
            )
            return HttpResponseRedirect(view_url)

        else:
            # continue to showing errors
            pass
    else:
        form = UserUploadForm()

    pages = site.page_set.all()

    if not (site.is_admin(request.user) or site.is_participant(request.user)):
        p = Page(challenge=site, title="files")
        currentpage = permissionMessage(request, p)
        response = render(
            request,
            "page.html",
            {"site": site, "currentpage": currentpage, "pages": pages},
        )
        response.status_code = 403
        return response

    return render(
        request,
        "uploads/comicupload.html",
        {"form": form, "upload_url": view_url, "site": site, "pages": pages},
    )
Esempio n. 4
0
def copy_page(page):
    return Page(challenge=page.challenge, title=page.title, html=page.html)
Esempio n. 5
0
def test_google_group():
    p = Page(html="{% google_group 'my-group' %}")
    rendered = p.cleaned_html()
    assert 'data-groupname="my-group"' in rendered