def test_article_detail_rendering(self): a: Article = Article() a.size = ">XXL" a.type = 3 a.price = "1337" a.quantity = "250" self.assertEquals( render_article_properties_division(a), '<div class="article_properties_division"><br />Size: >XXL<br />Type: ' + 'Kids<br />Price: 13.37 €<br />Pieces left (app.): 250<br /></div><br />' )
def add_article_to_group(grpid: int, size: str, arttyp: int, user: Profile): grp: ArticleGroup = ArticleGroup.objects.get(id=grpid) a: Article = Article() a.underConstruction = True a.group = grp a.description = grp.group_name a.visible = False a.price = "0000" a.largeText = "# This group hasn't been updated yet.\nPlease update matrix of group N° " \ + str(grpid) + "\n<!-- DEFAULT NOIMP TEXT -->" a.cachedText = compile_markdown(a.largeText) a.type = arttyp a.quantity = 0 a.size = size a.addedByUser = user a.chestsize = 0 a.save()
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))
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() pass
def make_testing_db(): m = Media() m.headline = "Most ugly image" m.lowResFile = "https://example.com/image.jpg" m.highResFile = "https://example.com/image.jpg" m.save() print("media created") u = Profile() u.authuser = User.objects.all()[0] u.active = True u.dect = 5234 u.displayName = "Test Profile 01" u.rights = 0 u.avatarMedia = m u.notes = "<center>This is to test html insertion</center>" u.save() print("Profile created") a = Article() a.cachedText = "<h2>This is a dummy article due to testing purposes</h2>" a.description = "Test article" a.price = "$15.00" a.quantity = 1000 a.size = "XXL" a.type = 1 a.visible = True a.addedByUser = u a.save() print("Article created") am = ArticleMedia() am.AID = a am.MID = m am.save() print("Article media link created") mu = MediaUpload() mu.MID = m mu.UID = u mu.save() print("Media user link created") p = Post() p.title = "Test post 01" p.cacheText = "<p>this is a test post<br/>generated by tools.make_testing_db()</p>" p.createdByUser = u p.visibleLevel = 0 s = Settings() s.changedByUser = u s.property = '''[{ "type":"link", "href":"example.com","text":"Visit example.com" },{"type":"link","text":"Visit the top level website", "href":".."}]''' s.SName = 'frontpage.ui.navbar.content' s.requiredLevel = 0 s.save() print("NavBar setting created")