Exemplo n.º 1
0
def action_add_multiple_media(request: HttpRequest):
    try:
        category: str = request.POST["category"]
        files = request.FILES.getlist('files')
        user: Profile = get_current_user(request)
        for f in files:
            handle_file(user, str(f.name), category,
                        "### There is no media description", f)
    except Exception as e:
        return redirect("/admin/media/add?hint=" + str(e))
    return redirect("/admin/media/add")
Exemplo n.º 2
0
def action_add_single_media(request: HttpRequest):
    try:
        headline = request.POST["headline"]
        category = request.POST["category"]
        text = request.POST["text"]
        file = request.FILES['file']
        user: Profile = get_current_user(request)
        handle_file(user, headline, category, text, file)
    except Exception as e:
        return redirect("/admin/media/add?hint=" + str(e))
    return redirect("/admin/media/add")
Exemplo n.º 3
0
def render_article_page(request: HttpRequest):
    forcefilter: bool = False
    if request.GET.get("showfilter"):
        forcefilter = True
    u: Profile = get_current_user(request)
    a = render_error_panel(request)
    a += '<div class="admin-popup w3-row w3-padding-64 w3-twothird w3-container"><h3>Articles:</h3><br/>'
    if u.rights > 1 or forcefilter:
        a += render_objects_form(request)
    a += render_group_list(request, u)
    a += render_alone_article_list(request, u)
    if u.rights > 1 or forcefilter:
        a += render_objects_form(request)
    a += '</div>'
    return a
Exemplo n.º 4
0
def action_change_user_avatar(request: HttpRequest):
    try:
        user_id = int(request.GET["payload"])
        media_id = int(request.GET["media_id"])
        user: Profile = Profile.objects.get(pk=int(user_id))
        u: Profile = get_current_user(request)
        if not (u == user) and u.rights < 4:
            return redirect(
                "/admin?error='You're not allowed to edit other users.'")
        medium = Media.objects.get(pk=int(media_id))
        user.avatarMedia = medium
        user.save()
    except Exception as e:
        return redirect("/admin?error=" + str(e))
    return redirect("/admin/users")
Exemplo n.º 5
0
def handle_group_article_add(request: HttpRequest):
    groupid: int = -1
    size = ""
    arttype = 4
    dp = ""
    try:
        groupid = int(request.GET["gid"])
        size = str(request.GET["size"])
        arttype = int(request.GET["type"])
        dp = request.GET["dp"]
    except:
        return redirect(
            "/admin/articles/editgroup?msgid=editgroup.brokenrequest&dp=" + dp)
    add_article_to_group(groupid, size, arttype, get_current_user(request))
    return redirect("/admin/articles/editgroup?gid=" + str(groupid) + "&dp=" +
                    dp)
Exemplo n.º 6
0
def action_save_article(request: HttpRequest):
    """
    This function creates a new or saves an article based on the
    (hopefully) provided POST data elements:
        * price in cents
        * largetext as a markdown text
        * type as a number between 0 and 3 (both inclusive)
        * description a normal text containing the short description
        * visible a bool str if the article should be visible yet
        * quantity the amount of the current aviable pieces
        * size the size of the article (10 char text)
        * [id] (GET) the ID of the article to edit (if non is provided
            it will be assumed that it is a new article)
    The user who added the article will be automatically determined.
    The flashImage will be handled by set action_set_image(request)
    If the article to be saved is a newly generated one the function
    will redirect the user to the flash image selection dialog or
    otherwise will redirect the user to the articles page.
    :param request The current HttpRequest
    :return The crafted response
    """
    try:
        price = request.POST["price"]
        largetext = request.POST["largetext"]
        article_type = request.POST["type"]
        description = request.POST["description"]
        visible = parse_bool(request.POST["visible"])
        quantity = int(request.POST["quantity"])
        size = request.POST["size"]
        chestsize: int = request.POST["chestsize"]
        userp: Profile = get_current_user(request)
        aid = -1  # This means that it's a new article
        a: Article = None
        if request.GET.get("id"):
            aid = int(request.GET["id"])
            a = Article.objects.get(pk=aid)
        else:
            a = Article()
        a.price = str(price)
        a.largeText = str(largetext)
        a.cachedText = compile_markdown(largetext)
        a.type = int(article_type)
        a.description = str(description)
        a.visible = visible
        a.quantity = int(quantity)
        a.size = str(size)
        a.chestsize = chestsize
        a.addedByUser = userp
        a.save()
        if aid < 0:
            logger.info("User '" + userp.displayName +
                        "' created a new article (UID: " + str(userp.pk) + ")")
            return redirect(
                "/admin/media/select?action_url=/admin/actions/add-image-to-article&payload="
                + str(a.id))
        else:
            logger.info("User '" + userp.displayName +
                        "' modified an article (UID: " + str(userp.pk) +
                        " AID: " + str(aid) + ")")
            return redirect("/admin/articles")
    except Exception as e:
        logger.exception(e)
        return redirect('/admin/?error=' + str(e))