Show substances in a nicer way

This commit is contained in:
Mark Veidemanis 2024-05-18 03:13:31 +01:00
parent 4baffbe014
commit 0bb64fd144
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 194 additions and 29 deletions

View File

@ -469,7 +469,7 @@ class Favourite(models.Model):
experiences = models.ManyToManyField(Experience, blank=True)
def __str__(self):
return f"{self.name} ({self.common_name})"
return f"{self.name} [{self.nickname}] ({self.common_name})"
# class Perms(models.Model):

View File

@ -6,7 +6,7 @@
{% include 'mixins/partials/notify.html' %}
{% if object is not None %}
<h1 class="title">{{ object.name }} - {{ object.nickname }} - {{ object.common_name }}</h1>
<h1 class="title">{{ object }}</h1>
<p class="subtitle"><strong>{{ object.drug_class }}</strong></p>
<div class="block">
<a class="button is-info" href="#">Prices</a>
@ -16,29 +16,171 @@
<div class="cell">
<div class="box">
<h2 class="subtitle">Dosage</h2>
<ul>
{% for dose in object.dosages.all %}
<li>{{ dose }}</li>
{% endfor %}
</ul>
<table
class="table is-fullwidth is-hoverable"
hx-target="#{{ context_object_name }}-table"
id="{{ context_object_name }}-table"
hx-swap="outerHTML"
hx-trigger="{{ context_object_name_singular }}Event from:body"
hx-get="#">
<tbody>
{% for item in object.dosages.all %}
<tr>
<th>roa</th>
<td>
{{ item.roa }}
</td>
</tr>
<tr>
<th>unit</th>
<td>
{{ item.unit }}
</td>
</tr>
<tr>
<th>threshold</th>
<td>
{{ item.threshold_lower }} - {{ item.threshold_upper }}
</td>
</tr>
<tr>
<th>light</th>
<td>
{{ item.light_lower }} - {{ item.light_upper }}
</td>
</tr>
<tr>
<th>common</th>
<td>
{{ item.common_lower }} - {{ item.common_upper }}
</td>
<tr>
<tr>
<th>strong</th>
<td>
{{ item.strong_lower }} - {{ item.strong_upper }}
</td>
<tr>
<tr>
<th>heavy</th>
<td>
{{ item.heavy_lower }} - {{ item.heavy_upper }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="box">
<h2 class="subtitle">Timing</h2>
<ul>
{% for timing in object.timings.all %}
<li>{{ timing }}</li>
{% endfor %}
</ul>
<table
class="table is-fullwidth is-hoverable"
hx-target="#{{ context_object_name }}-table"
id="{{ context_object_name }}-table"
hx-swap="outerHTML"
hx-trigger="{{ context_object_name_singular }}Event from:body"
hx-get="#">
<tbody>
{% for item in object.timings.all %}
<tr>
<th>roa</th>
<td>
{{ item.roa }}
</td>
</tr>
<tr>
<th>unit</th>
<td>
{{ item.unit }}
</td>
</tr>
<tr>
<th>onset</th>
<td>
{{ item.onset_lower }} - {{ item.onset_upper }}
</td>
</tr>
<tr>
<th>comeup</th>
<td>
{{ item.comeup_lower }} - {{ item.comeup_upper }}
</td>
</tr>
<tr>
<th>peak</th>
<td>
{{ item.peak_lower }} - {{ item.peak_upper }}
</td>
<tr>
<tr>
<th>offset</th>
<td>
{{ item.offset_lower }} - {{ item.offset_upper }}
</td>
<tr>
<tr>
<th>total</th>
<td>
{{ item.total_lower }} - {{ item.total_upper }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="box">
<h2 class="subtitle">Links</h2>
<ul>
{% for link in object.links.all %}
<li>{{ link }}</li>
{% endfor %}
</ul>
<table
class="table is-fullwidth is-hoverable"
hx-target="#{{ context_object_name }}-table"
id="{{ context_object_name }}-table"
hx-swap="outerHTML"
hx-trigger="{{ context_object_name_singular }}Event from:body"
hx-get="#">
<tbody>
{% for item in object.links.all %}
<tr>
<th>source</th>
<td>
{{ item.source }}
</td>
</tr>
<tr>
<th>url</th>
<td>
<a href="{{ item.url }}">{{ item.url }}</a>
</td>
</tr>
<tr>
<th>author</th>
<td>
{{ item.author }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
@ -54,11 +196,39 @@
<div class="box">
<h2 class="subtitle">Effects</h2>
<ul>
{% for effect in object.effects.all %}
<li>{{ effect }}</li>
{% endfor %}
</ul>
<table
class="table is-fullwidth is-hoverable"
hx-target="#{{ context_object_name }}-table"
id="{{ context_object_name }}-table"
hx-swap="outerHTML"
hx-trigger="{{ context_object_name_singular }}Event from:body"
hx-get="#">
<tbody>
{% for item in object.effects.all %}
<tr>
<th>entry</th>
<td>
<a href="{{ item.entry.url }}">{{ item.entry.url }}</a>
</td>
</tr>
<tr>
<th>SEI</th>
<td>
<div class="grid">
{% for effect in item.subjective_effects.all %}
<div class="cell box">
{{ effect }}
</div>
{% endfor %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

View File

@ -65,14 +65,9 @@ class DrugDetail(LoginRequiredMixin, StaffMemberRequiredMixin, ObjectRead):
detail_url_args = ["type", "pk"]
def get_object(self, **kwargs):
print("GET")
pk = kwargs.get("pk")
info = Drug.objects.get(pk=pk)
# self.extra_context = {}
print("info", info)
# return dictionary
return info.__dict__
return info
class DrugClear(LoginRequiredMixin, StaffMemberRequiredMixin, APIView):

View File

@ -53,7 +53,7 @@ class FavouriteDetail(LoginRequiredMixin, ObjectRead):
def get_object(self, **kwargs):
pk = kwargs.get("pk")
info = Favourite.objects.get(pk=pk, user=self.request.user)
return info.__dict__
return info
# class FavouriteClear(LoginRequiredMixin, APIView):