Some nicer display logic
authorDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 4 Mar 2022 17:45:07 +0000 (12:45 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 4 Mar 2022 17:45:07 +0000 (12:45 -0500)
src/climbing/models.py
src/user_profile/models.py
src/user_profile/templates/auth/user_detail.html

index 83d437f..dd2493c 100644 (file)
@@ -41,7 +41,34 @@ class Route(models.Model):
     notes = models.TextField(blank=True, null=True)
 
     def __str__(self):
-        return self.name
+        pitch_count = self.pitches.count()
+
+        if pitch_count == 0:
+            return self.name
+
+        if pitch_count == 1:
+            return '{} {}'.format(self.name, self.difficulty)
+
+        return '{} {} ({} pitches)'.format(
+            self.name,
+            self.difficulty,
+            pitch_count,
+        )
+
+    @property
+    def difficulty(self):
+        diff = None
+        diff_index = -1
+
+        for pitch in self.pitches.all():
+            for index, diff_choice in enumerate(ROUTE_DIFFICULTY_CHOICES):
+                if pitch.difficulty == diff_choice[0]:
+                    if diff_index < index:
+                        diff = pitch.difficulty
+                        diff_index = index
+                    break
+
+        return diff
 
 ROUTE_DIFFICULTY_CHOICES = (
     ('5.0', '5.0'),
@@ -99,11 +126,14 @@ class Pitch(models.Model):
         on_delete=models.CASCADE,
         related_name='pitches',
     )
-    name = models.CharField(max_length=64, null=True)
+    name = models.CharField(max_length=64, blank=True, null=True)
     difficulty = models.CharField(max_length=5, choices=ROUTE_DIFFICULTY_CHOICES)
     safety = models.CharField(max_length=4, choices=SAFETY_CHOICES)
     notes = models.TextField(blank=True, null=True)
 
+    class Meta:
+        verbose_name_plural = 'pitches'
+
     def __str__(self):
         if self.name:
             return '{} ({})'.format(self.name, self.difficulty)
index 7aeb9bf..23d9151 100644 (file)
@@ -3,6 +3,8 @@ from django.db import models
 from django.db.models.signals import post_save
 from django.dispatch import receiver
 
+from core import utils
+
 class UserProfile(models.Model):
     user = models.OneToOneField(
         User,
@@ -14,6 +16,14 @@ class UserProfile(models.Model):
     def __str__(self):
         return self.user.username
 
+    @property
+    def todos(self):
+        return utils.merge(
+            self.user.boulder_todos.order_by('name'),
+            self.user.route_todos.order_by('name'),
+            'name',
+        )
+
 @receiver(post_save, sender=User)
 def create_profile(sender, instance, **kwargs):
     profile, created = UserProfile.objects.get_or_create(user=instance)
index 1ff382b..91e49c1 100644 (file)
@@ -1,5 +1,34 @@
 {% extends 'core/base.html' %}
 
 {% block content %}
-{{ object.username }}
+  {{ object.username }}
+
+  <div>
+    <header>TODOs</header>
+    {% if object.todos %}
+      <ul>
+        {% for todo in object.todos %}
+          <li>
+            {{ todo.route.name }}
+          </li>
+        {% endfor %}
+      </ul>
+    {% else %}
+      <em>No TODOs found.</em>
+    {% endif %}
+  </div>
+
+  <div>
+    <header>Ticks</header>
+    {% if object.ticks %}
+      <ul>
+        {% for tick in object.ticks %}
+          <li>
+          </li>
+        {% endfor %}
+      </ul>
+    {% else %}
+      <em>No ticks found.</em>
+    {% endif %}
+  </div>
 {% endblock %}