Exemplo n.º 1
0
 def setUp(self):
     # Setup test articles
     g: ArticleGroup = ArticleGroup()
     g.group_name = "Test Group"
     g.save()
     a: Article = Article()
     a.size = "XXL"
     a.type = 3
     a.price = "3000"
     a.quantity = 100
     a.group = g
     a.largeText = "A long text"
     a.description = "A different description"
     a.visible = False
     a.cachedText = "A long text"
     a.chestsize = 100
     a.underConstruction = True
     a.save()
     a = Article()
     a.size = "S"
     a.type = 3
     a.price = "2500"
     a.quantity = 250
     a.group = g
     a.largeText = "A long text"
     a.description = "A description"
     a.visible = True
     a.cachedText = "A long text"
     a.chestsize = 102
     a.underConstruction = True
     a.save()
     a = Article()
     a.size = "XXL"
     a.type = 2
     a.quantity = 1313
     a.price = "1337"
     a.group = g
     a.largeText = "A long text"
     a.description = "A description"
     a.visible = True
     a.cachedText = "A long text"
     a.chestsize = 100
     a.underConstruction = True
     a.save()
     a = Article()
     a.size = "S"
     a.type = 2
     a.quantity = 169
     a.price = "1111"
     a.group = g
     a.largeText = "A long text"
     a.description = "A description"
     a.visible = True
     a.cachedText = "A long text"
     a.chestsize = 100
     a.underConstruction = True
     a.save()
     #init_db()
     #make_testing_db()
     pass
Exemplo n.º 2
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))