Skip to content

Commit

Permalink
Improve product descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
atjn committed Jan 19, 2025
1 parent acf6b47 commit 0dcd5cc
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 31 deletions.
2 changes: 2 additions & 0 deletions stregsystem/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class ProductAdmin(admin.ModelAdmin):
)
fields = (
"name",
"name_style",
"description",
"price",
("active", "deactivate_date"),
("start_date", "quantity", "get_bought"),
Expand Down
18 changes: 11 additions & 7 deletions stregsystem/fixtures/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@
"model": "stregsystem.product",
"pk": 51,
"fields": {
"name": "<h1>Futtetyr</h1>",
"name": "Futtetyr",
"name_style": "font-size: 2em;\nfont-weight: bold;\ncolor: red;\nmargin: .5em 0;",
"price": 33300,
"active": true,
"start_date": null,
Expand Down Expand Up @@ -395,7 +396,8 @@
"model": "stregsystem.product",
"pk": 1836,
"fields": {
"name": "<h1>FLAN billet</h1>",
"name": "FLAN billet",
"name_style": "font-size: 2em;\nfont-weight: bold;\ncolor: red;\nmargin: .5em 0;",
"price": 4269,
"active": true,
"start_date": null,
Expand Down Expand Up @@ -613,7 +615,9 @@
"model": "stregsystem.product",
"pk": 1903,
"fields": {
"name": "<h3>Månedens Øl</h3><br>September: Bonk Beer",
"name": "Månedens Øl",
"name_style": "font-size: 1.15em;\nfont-weight: bold;\nmargin: 1em 0;",
"description": "September: Bonk Beer",
"price": 1460,
"active": true,
"start_date": null,
Expand Down Expand Up @@ -715,8 +719,8 @@
"fields": {
"text": "<div id=\"maanedens-oel\"></div>\r\n<script>\r\n var p = \"Ny!\";\r\n var elem = document.getElementById(\"maanedens-oel\").parentElement;\r\n // Set it to 7 and not 40 if you want the tests to break ;)\r\n if (new Date().getDate() <= 40) {\r\n elem.innerText = p;\r\n }\r\n else {\r\n elem.remove();\r\n }\r\n</script>",
"active": true,
"background_color": "Yellow",
"text_color": "",
"background_color": "yellow",
"text_color": "black",
"start_date": "2025-01-14",
"end_date": "2125-01-14",
"comment": "",
Expand All @@ -732,8 +736,8 @@
"fields": {
"text": "Udgår!",
"active": true,
"background_color": "",
"text_color": "",
"background_color": "red",
"text_color": "black",
"start_date": "2025-01-14",
"end_date": "2125-01-14",
"comment": "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 4.1.13 on 2025-01-19 00:48

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("stregsystem", "0022_productnote"),
]

operations = [
migrations.AddField(
model_name="product",
name="description",
field=models.CharField(blank=True, max_length=64),
),
migrations.AddField(
model_name="product",
name="name_style",
field=models.TextField(
default="",
help_text="If product is very cool, usually something like: font-size: 2em; font-weight: bold; color: red; margin: 1em 0;",
max_length=64,
),
),
migrations.AlterField(
model_name="productnote",
name="background_color",
field=models.CharField(
default="yellow", help_text="Write a valid html color", max_length=20
),
),
migrations.AlterField(
model_name="productnote",
name="text_color",
field=models.CharField(
default="black", help_text="Write a valid html color", max_length=20
),
),
]
6 changes: 4 additions & 2 deletions stregsystem/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ def __str__(self):

class Product(models.Model): # id automatisk...
name = models.CharField(max_length=64)
name_style = models.TextField(max_length=64, default="", help_text="If product is very cool, usually something like: font-size: 2em; font-weight: bold; color: red; margin: 1em 0;")
description = models.CharField(max_length=64, blank=True)
price = models.IntegerField() # penge, oere...
active = models.BooleanField()
start_date = models.DateField(blank=True, null=True)
Expand Down Expand Up @@ -640,9 +642,9 @@ class ProductNote(models.Model):
text = models.TextField()
active = models.BooleanField(default=True)
background_color = models.CharField(
max_length=20, help_text="Write a valid html color (default: red)", blank="red"
max_length=20, help_text="Write a valid html color", default="yellow"
) # If anyone wants to use LightGoldenRodYellow, they can
text_color = models.CharField(max_length=20, help_text="Write a valid html color (default: black)", blank="black")
text_color = models.CharField(max_length=20, help_text="Write a valid html color", default="black")
start_date = models.DateField()
end_date = models.DateField()
comment = models.TextField(blank=True)
Expand Down
20 changes: 18 additions & 2 deletions stregsystem/static/stregsystem/stregsystem.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ button {
font: inherit;
text-decoration: underline;
color: LinkText;

&:active{
&:active {
color: ActiveText;
}

& * {
text-decoration: underline;
}
}
}

Expand Down Expand Up @@ -138,6 +141,19 @@ table h2, table h3 {
margin-bottom: 6px;
}

#product-overview {
& button {
text-align: left;
}
& span {
display: inline-block;
}
& .note-box {
padding: 2px 4px 2px 4px;
border-radius: 8px;
}
}

.center-around {
font-size: 0.8rem;
line-height: 0.8rem;
Expand Down
43 changes: 31 additions & 12 deletions stregsystem/templates/stregsystem/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
margin-top: 1.5em;
margin-bottom: 1.5em;
}
.note-box {
display: inline;
padding: 2px 4px 2px 4px;
border-radius: 8px;
color: black;
background-color: red;
}
</style>
{% endblock %}

Expand Down Expand Up @@ -66,7 +59,7 @@

<div id="message">{% block message %}{% endblock %}</div>

<div class="horizontal-table">
<div id="product-overview" class="horizontal-table">
{% block products %}
{% if product_note_pair_list %}
{% autoescape off %}
Expand All @@ -83,9 +76,22 @@
</td>
<td>
{% for note in pair.note %}
<div class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</div>
<span class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</span>
{% endfor %}
<span style="display: inline-block">{{pair.product.name}}</span>
<span
class="name"
{% if pair.product.name_style %}
style="{{pair.product.name_style}}"
{% endif %}
>
{{pair.product.name}}
</span>
{% if pair.product.description %}
<br>
<span class="description">
{{pair.product.description}}
</span>
{% endif %}
</td>
<td class="price">{{pair.product.price|money}} kr</td>
</tr>
Expand All @@ -103,9 +109,22 @@
<td>{{pair.product.id|product_id_and_alias_string}}</td>
<td>
{% for note in pair.note %}
<div class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</div>
<span class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</span>
{% endfor %}
<span style="display: inline-block">{{pair.product.name}}</span>
<span
class="name"
{% if pair.product.name_style %}
style="{{pair.product.name_style}}"
{% endif %}
>
{{pair.product.name}}
</span>
{% if pair.product.description %}
<br>
<span class="description">
{{pair.product.description}}
</span>
{% endif %}
</td>
<td class="price">{{pair.product.price|money}} kr</td>
</tr>
Expand Down
52 changes: 44 additions & 8 deletions stregsystem/templates/stregsystem/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,69 @@ <h4>Du
{% csrf_token %}
<input type="hidden" value="{{ room.id }}" name="room_id">
<input type="hidden" value="{{ member.id }}" name="member_id">
<div class="horizontal-table">
<div id="product-overview" class="horizontal-table">
<table class="default">
<tr>
<th>Produkt</th>
<th>Pris</th>
</tr>
{% for product in product_list|partition:"2"|first %}
{% for pair in product_note_pair_list|partition:"2"|first %}
<tr>
<td>
<button value="{{ product.id }}" name="product_id" class="linkalike">{{product.name}}</button>
<button value="{{ pair.product.id }}" name="product_id" class="linkalike">
{% for note in pair.note %}
<span class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</span>
{% endfor %}
<span
class="name"
{% if pair.product.name_style %}
style="{{pair.product.name_style}}"
{% endif %}
>
{{pair.product.name}}
</span>
{% if pair.product.description %}
<br>
<span class="description">
{{pair.product.description}}
</span>
{% endif %}
</button>
</td>
<td class="price">{{product.price|money}} kr</td>
<td class="price">{{pair.product.price|money}} kr</td>
</tr>
{% endfor %}
</table>
{% if product_list|partition:"2"|last %}
{% if product_note_pair_list|partition:"2"|last %}
<table class="default">
<tr>
<th>Produkt</th>
<th>Pris</th>
</tr>
{% for product in product_list|partition:"2"|last %}
{% for pair in product_note_pair_list|partition:"2"|last %}
<tr>
<td>
<button value="{{ product.id }}" name="product_id" class="linkalike">{{product.name}}</button>
<button value="{{ pair.product.id }}" name="product_id" class="linkalike">
{% for note in pair.note %}
<span class="note-box" style="background-color: {{note.background_color}}; color: {{note.text_color}}">{{note.text}}</span>
{% endfor %}
<span
class="name"
{% if pair.product.name_style %}
style="{{pair.product.name_style}}"
{% endif %}
>
{{pair.product.name}}
</span>
{% if pair.product.description %}
<br>
<span class="description">
{{pair.product.description}}
</span>
{% endif %}
</button>
</td>
<td class="price">{{product.price|money}} kr</td>
<td class="price">{{pair.product.price|money}} kr</td>
</tr>
{% endfor %}
</table>
Expand Down
13 changes: 13 additions & 0 deletions stregsystem/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def roomindex(request):

def index(request, room_id):
room = get_object_or_404(Room, pk=int(room_id))
product_list = __get_productlist(room_id)
ProductNotePair = namedtuple('ProductNotePair', 'product note')
product_note_pair_list = [
ProductNotePair(product, __get_active_notes_for_product(product)) for product in __get_productlist(room_id)
Expand All @@ -122,6 +123,10 @@ def sale(request, room_id):
room = get_object_or_404(Room, pk=room_id)
news = __get_news()
product_list = __get_productlist(room_id)
ProductNotePair = namedtuple('ProductNotePair', 'product note')
product_note_pair_list = [
ProductNotePair(product, __get_active_notes_for_product(product)) for product in __get_productlist(room_id)
]

buy_string = request.POST['quickbuy'].strip()
# Handle empty line
Expand Down Expand Up @@ -188,6 +193,10 @@ def _multibuy_hint(now, member):
def quicksale(request, room, member: Member, bought_ids):
news = __get_news()
product_list = __get_productlist(room.id)
ProductNotePair = namedtuple('ProductNotePair', 'product note')
product_note_pair_list = [
ProductNotePair(product, __get_active_notes_for_product(product)) for product in __get_productlist(room.id)
]
now = timezone.now()

# Retrieve products and construct transaction
Expand Down Expand Up @@ -228,6 +237,10 @@ def quicksale(request, room, member: Member, bought_ids):
def usermenu(request, room, member, bought, from_sale=False):
negative_balance = member.balance < 0
product_list = __get_productlist(room.id)
ProductNotePair = namedtuple('ProductNotePair', 'product note')
product_note_pair_list = [
ProductNotePair(product, __get_active_notes_for_product(product)) for product in __get_productlist(room.id)
]
news = __get_news()
promille = member.calculate_alcohol_promille()
(
Expand Down

0 comments on commit 0dcd5cc

Please sign in to comment.