Skip to content

Commit

Permalink
Merge 2c755c2 into ce21f39
Browse files Browse the repository at this point in the history
  • Loading branch information
MrApplejuice committed Mar 8, 2022
2 parents ce21f39 + 2c755c2 commit dfdc995
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 16 deletions.
14 changes: 14 additions & 0 deletions core/models.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import random
import re
from datetime import timedelta
from typing import Iterable, Optional

Expand Down Expand Up @@ -120,6 +121,19 @@ class Meta:
blank=False,
)

@property
def complementary_color(self):
DARK, LIGHT = "#101010", "#EFEFEF"
if not self.color:
return DARK

r, g, b = [int(x, 16) for x in re.match("#(..)(..)(..)", self.color).groups()]
yiq = ((r * 299) + (g * 587) + (b * 114)) // 1000
if yiq >= 128:
return DARK
else:
return LIGHT


class Tagged(GenericTaggedItemBase):
tag = models.ForeignKey(
Expand Down
8 changes: 6 additions & 2 deletions core/templates/core/bmi_list.html
Expand Up @@ -27,6 +27,7 @@ <h1>
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "BMI" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -55,15 +56,18 @@ <h1>
<td><a href="{% url 'core:child' bmi.child.slug %}">{{ bmi.child }}</a></td>
{% endif %}
<td>{{ bmi.bmi }}</td>
<td>
{% include "core/render_tag_list.html" with tags=bmi.tags.all %}
</td>
</tr>
{% if bmi.notes %}
<tr class="{{ row_class }} row-details">
<td colspan="4"><i class="icon-note mr-2" aria-hidden="true"></i>{{ bmi.notes }}</td>
<td colspan="5"><i class="icon-note mr-2" aria-hidden="true"></i>{{ bmi.notes }}</td>
</tr>
{% endif %}
{% empty %}
<tr>
<th colspan="4">{% trans "No bmi entries found." %}</th>
<th colspan="5">{% trans "No bmi entries found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
6 changes: 5 additions & 1 deletion core/templates/core/diaperchange_list.html
Expand Up @@ -29,6 +29,7 @@ <h1>
<th class="text-center">{% trans "Contents" %}</th>
<th>{% trans "Color" %}</th>
<th>{% trans "Amount" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -62,6 +63,9 @@ <h1>
</td>
<td>{{ change.get_color_display }}</td>
<td>{{ change.amount|default_if_none:"" }}</td>
<td>
{% include "core/render_tag_list.html" with tags=change.tags.all %}
</td>
</tr>
{% if change.notes %}
<tr class="{{ row_class }} row-details">
Expand All @@ -70,7 +74,7 @@ <h1>
{% endif %}
{% empty %}
<tr>
<th colspan="6">{% trans "No diaper changes found." %}</th>
<th colspan="7">{% trans "No diaper changes found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 6 additions & 2 deletions core/templates/core/feeding_list.html
Expand Up @@ -31,6 +31,7 @@ <h1>
{% comment %}Abbreviation of "Amount"{% endcomment %}
<th>{% trans "Amt." %}</th>
<th>{% trans "Duration" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -66,15 +67,18 @@ <h1>
{% endif %}
</td>
<td>{{ feeding.duration|duration_string }}</td>
<td>
{% include "core/render_tag_list.html" with tags=feeding.tags.all %}
</td>
</tr>
{% if feeding.notes %}
<tr class="{{ row_class }} row-details">
<td colspan="7"><i class="icon-note mr-2" aria-hidden="true"></i>{{ feeding.notes }}</td>
<td colspan="8"><i class="icon-note mr-2" aria-hidden="true"></i>{{ feeding.notes }}</td>
</tr>
{% endif %}
{% empty %}
<tr>
<th colspan="7">{% trans "No feedings found." %}</th>
<th colspan="8">{% trans "No feedings found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 6 additions & 2 deletions core/templates/core/head_circumference_list.html
Expand Up @@ -27,6 +27,7 @@ <h1>
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Head Circumference" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -55,15 +56,18 @@ <h1>
<td><a href="{% url 'core:child' head_circumference.child.slug %}">{{ head_circumference.child }}</a></td>
{% endif %}
<td>{{ head_circumference.head_circumference }}</td>
<td>
{% include "core/render_tag_list.html" with tags=head_circumference.tags.all %}
</td>
</tr>
{% if head_circumference.notes %}
<tr class="{{ row_class }} row-details">
<td colspan="4"><i class="icon-note mr-2" aria-hidden="true"></i>{{ head_circumference.notes }}</td>
<td colspan="5"><i class="icon-note mr-2" aria-hidden="true"></i>{{ head_circumference.notes }}</td>
</tr>
{% endif %}
{% empty %}
<tr>
<th colspan="4">{% trans "No head circumference entries found." %}</th>
<th colspan="5">{% trans "No head circumference entries found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 6 additions & 2 deletions core/templates/core/height_list.html
Expand Up @@ -27,6 +27,7 @@ <h1>
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Height" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -55,15 +56,18 @@ <h1>
<td><a href="{% url 'core:child' height.child.slug %}">{{ height.child }}</a></td>
{% endif %}
<td>{{ height.height }}</td>
<td>
{% include "core/render_tag_list.html" with tags=height.tags.all %}
</td>
</tr>
{% if height.notes %}
<tr class="{{ row_class }} row-details">
<td colspan="4"><i class="icon-note mr-2" aria-hidden="true"></i>{{ height.notes }}</td>
<td colspan="5"><i class="icon-note mr-2" aria-hidden="true"></i>{{ height.notes }}</td>
</tr>
{% endif %}
{% empty %}
<tr>
<th colspan="4">{% trans "No height entries found." %}</th>
<th colspan="5">{% trans "No height entries found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
4 changes: 4 additions & 0 deletions core/templates/core/note_list.html
Expand Up @@ -27,6 +27,7 @@ <h1>
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Note" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -54,6 +55,9 @@ <h1>
<td><a href="{% url 'core:child' note.child.slug %}">{{ note.child }}</a></td>
{% endif %}
<td>{{ note.note }}</td>
<td>
{% include "core/render_tag_list.html" with tags=note.tags.all %}
</td>
</tr>
{% empty %}
<tr>
Expand Down
3 changes: 3 additions & 0 deletions core/templates/core/render_tag.html
@@ -0,0 +1,3 @@
<span class="badge badge-pill" style="background-color:{{ tag.color }};color:{{ tag.complementary_color }};">
{{ tag.name|escape }}
</span>
5 changes: 5 additions & 0 deletions core/templates/core/render_tag_list.html
@@ -0,0 +1,5 @@
{% for tag in tags %}
{% include "core/render_tag.html" %}
{% empty %}
-
{% endfor %}
8 changes: 6 additions & 2 deletions core/templates/core/sleep_list.html
Expand Up @@ -29,6 +29,7 @@ <h1>
{% endif %}
<th>{% trans "Duration" %}</th>
<th class="text-center">{% trans "Nap" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -59,15 +60,18 @@ <h1>
{% endif %}
<td>{{ sleep.duration|duration_string }}</td>
<td class="text-center">{{ sleep.nap|bool_icon }}</td>
<td>
{% include "core/render_tag_list.html" with tags=sleep.tags.all %}
</td>
</tr>
{% if sleep.notes %}
<tr class="{{ row_class }} row-details">
<td colspan="6"><i class="icon-note mr-2" aria-hidden="true"></i>{{ sleep.notes }}</td>
<td colspan="7"><i class="icon-note mr-2" aria-hidden="true"></i>{{ sleep.notes }}</td>
</tr>
{% endif %}
{% empty %}
<tr>
<th colspan="6">{% trans "No sleep entries found." %}</th>
<th colspan="7">{% trans "No sleep entries found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 6 additions & 2 deletions core/templates/core/temperature_list.html
Expand Up @@ -27,6 +27,7 @@ <h1>
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Temperature" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -55,15 +56,18 @@ <h1>
<td><a href="{% url 'core:child' temperature.child.slug %}">{{ temperature.child }}</a></td>
{% endif %}
<td>{{ temperature.temperature }}</td>
<td>
{% include "core/render_tag_list.html" with tags=temperature.tags.all %}
</td>
</tr>
{% if temperature.notes %}
<tr class="{{ row_class }} row-details">
<td colspan="4"><i class="icon-note mr-2" aria-hidden="true"></i>{{ temperature.notes }}</td>
<td colspan="5"><i class="icon-note mr-2" aria-hidden="true"></i>{{ temperature.notes }}</td>
</tr>
{% endif %}
{% empty %}
<tr>
<th colspan="4">{% trans "No temperature entries found." %}</th>
<th colspan="5">{% trans "No temperature entries found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
6 changes: 5 additions & 1 deletion core/templates/core/tummytime_list.html
Expand Up @@ -28,6 +28,7 @@ <h1>
{% endif %}
<th>{% trans "Duration" %}</th>
<th>{% trans "Milestone" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -57,10 +58,13 @@ <h1>
{% endif %}
<td>{{ tummytime.duration|duration_string }}</td>
<td>{{ tummytime.milestone }}</td>
<td>
{% include "core/render_tag_list.html" with tags=tummytime.tags.all %}
</td>
</tr>
{% empty %}
<tr>
<th colspan="6">{% trans "No tummy time entries found." %}</th>
<th colspan="7">{% trans "No tummy time entries found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
8 changes: 6 additions & 2 deletions core/templates/core/weight_list.html
Expand Up @@ -27,6 +27,7 @@ <h1>
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Weight" %}</th>
<th>{% trans "Tags" %}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -55,15 +56,18 @@ <h1>
<td><a href="{% url 'core:child' weight.child.slug %}">{{ weight.child }}</a></td>
{% endif %}
<td>{{ weight.weight }}</td>
<td>
{% include "core/render_tag_list.html" with tags=weight.tags.all %}
</td>
</tr>
{% if weight.notes %}
<tr class="{{ row_class }} row-details">
<td colspan="4"><i class="icon-note mr-2" aria-hidden="true"></i>{{ weight.notes }}</td>
<td colspan="5"><i class="icon-note mr-2" aria-hidden="true"></i>{{ weight.notes }}</td>
</tr>
{% endif %}
{% empty %}
<tr>
<th colspan="4">{% trans "No weight entries found." %}</th>
<th colspan="5">{% trans "No weight entries found." %}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions core/templates/timeline/_timeline.html
Expand Up @@ -28,6 +28,11 @@ <h3 class="text-center">
{% for detail in object.details %}
<div><small>{{ detail }}</small></div>
{% endfor %}
{% if object.tags %}
<div>
{% include "core/render_tag_list.html" with tags=object.tags %}
</div>
{% endif %}
</div>
<div class="card-footer text-muted">
{% blocktrans trimmed with since=object.time|timesince time=object.time|time %}
Expand Down
8 changes: 8 additions & 0 deletions core/timeline.py
Expand Up @@ -56,6 +56,7 @@ def _add_tummy_times(min_date, max_date, events, child=None):
"edit_link": edit_link,
"model_name": instance.model_name,
"type": "start",
"tags": instance.tags.all(),
}
)
events.append(
Expand All @@ -68,6 +69,7 @@ def _add_tummy_times(min_date, max_date, events, child=None):
"duration": timesince.timesince(instance.start, now=instance.end),
"model_name": instance.model_name,
"type": "end",
"tags": instance.tags.all(),
}
)

Expand All @@ -92,6 +94,7 @@ def _add_sleeps(min_date, max_date, events, child=None):
"edit_link": edit_link,
"model_name": instance.model_name,
"type": "start",
"tags": instance.tags.all(),
}
)
events.append(
Expand All @@ -103,6 +106,7 @@ def _add_sleeps(min_date, max_date, events, child=None):
"duration": timesince.timesince(instance.start, now=instance.end),
"model_name": instance.model_name,
"type": "end",
"tags": instance.tags.all(),
}
)

Expand Down Expand Up @@ -145,6 +149,7 @@ def _add_feedings(min_date, max_date, events, child=None):
"time_since_prev": time_since_prev,
"model_name": instance.model_name,
"type": "start",
"tags": instance.tags.all(),
}
)
events.append(
Expand All @@ -157,6 +162,7 @@ def _add_feedings(min_date, max_date, events, child=None):
"duration": timesince.timesince(instance.start, now=instance.end),
"model_name": instance.model_name,
"type": "end",
"tags": instance.tags.all(),
}
)

Expand All @@ -183,6 +189,7 @@ def _add_diaper_changes(min_date, max_date, events, child):
},
"edit_link": reverse("core:diaperchange-update", args=[instance.id]),
"model_name": instance.model_name,
"tags": instance.tags.all(),
}
)

Expand All @@ -198,5 +205,6 @@ def _add_notes(min_date, max_date, events, child):
"details": [instance.note],
"edit_link": reverse("core:note-update", args=[instance.id]),
"model_name": instance.model_name,
"tags": instance.tags.all(),
}
)

0 comments on commit dfdc995

Please sign in to comment.