Start adding views
authorDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 26 Feb 2021 16:50:10 +0000 (11:50 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 26 Feb 2021 16:52:33 +0000 (11:52 -0500)
core/urls.py
tickle/models.py
tickle/templates/tickle/area_detail.html [new file with mode: 0644]
tickle/templates/tickle/area_list.html [new file with mode: 0644]
tickle/templates/tickle/area_list_item.html [new file with mode: 0644]
tickle/urls.py [new file with mode: 0644]
tickle/views.py

index f0559db..0d79c71 100644 (file)
@@ -14,8 +14,9 @@ Including another URLconf
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
 from django.contrib import admin
-from django.urls import path
+from django.urls import include, path
 
 urlpatterns = [
     path('admin/', admin.site.urls),
+    path('climbing/', include('tickle.urls')),
 ]
index 3b2deb8..86cb752 100644 (file)
@@ -29,12 +29,14 @@ BOULDER_DIFFICULTY_CHOICES = (
     ('v16', 'v16'),
 )
 
+# TODO Provide a way of getting only Area objects which contain boulders/routes
 class Area(models.Model):
     parent = models.ForeignKey(
         'self',
         blank=True,
         null=True,
         on_delete=models.CASCADE,
+        related_name='children',
     )
     name = models.CharField(max_length=64)
     notes = models.TextField(blank=True)
@@ -46,7 +48,11 @@ class Area(models.Model):
         return '{} > {}'.format(self.parent, self.name)
 
 class Boulder(models.Model):
-    area = models.ForeignKey('Area', on_delete=models.PROTECT)
+    area = models.ForeignKey(
+        'Area',
+        on_delete=models.PROTECT,
+        related_name='boulders',
+    )
     name = models.CharField(max_length=64)
     difficulty = models.CharField(
         choices=BOULDER_DIFFICULTY_CHOICES,
@@ -128,7 +134,11 @@ PROTECTION_STYLE_CHOICES = (
 )
 
 class Route(models.Model):
-    area = models.ForeignKey('Area', on_delete=models.PROTECT)
+    area = models.ForeignKey(
+        'Area',
+        on_delete=models.PROTECT,
+        related_name='routes'
+    )
     name = models.CharField(max_length=64)
     protection_style = models.CharField(max_length=8, choices=PROTECTION_STYLE_CHOICES)
     mountainproject = models.URLField(blank=True)
diff --git a/tickle/templates/tickle/area_detail.html b/tickle/templates/tickle/area_detail.html
new file mode 100644 (file)
index 0000000..b951f76
--- /dev/null
@@ -0,0 +1,32 @@
+<html>
+  <head></head>
+  <body>
+    <h1>{{ area.name }}</h1>
+
+    {% if area.children.count > 0 %}
+      <ul>
+        {% for child in area.children.all %}
+          {% include 'tickle/area_list_item.html' with area=child %}
+        {% endfor %}
+      </ul>
+    {% endif %}
+
+    {% if area.boulders.count > 0 %}
+      Boulders
+      <ul>
+        {% for boulder in area.boulders.all %}
+          <li>{{ boulder.name }}</li>
+        {% endfor %}
+      </ul>
+    {% endif %}
+
+    {% if area.routes.count > 0 %}
+      Routes
+      <ul>
+        {% for route in area.routes.all %}
+          <li>{{ route.name }}</li>
+        {% endfor %}
+      </ul>
+    {% endif %}
+  </body>
+</html>
diff --git a/tickle/templates/tickle/area_list.html b/tickle/templates/tickle/area_list.html
new file mode 100644 (file)
index 0000000..3cdadae
--- /dev/null
@@ -0,0 +1,11 @@
+<html>
+  <head></head>
+  <body>
+    <h1>All Areas</h1>
+    <ul>
+      {% for area in area_list %}
+        {% include 'tickle/area_list_item.html' %}
+      {% endfor %}
+    </ul>
+  </body>
+</html>
diff --git a/tickle/templates/tickle/area_list_item.html b/tickle/templates/tickle/area_list_item.html
new file mode 100644 (file)
index 0000000..de6bfcc
--- /dev/null
@@ -0,0 +1,30 @@
+<li>
+  <header>
+    <a href='{% url "tickle:area-detail" pk=area.pk %}'>{{ area.name }}</a>
+  </header>
+  {% if area.children.count > 0 %}
+    <ul>
+      {% for child in area.children.all %}
+        {% include 'tickle/area_list_item.html' with area=child %}
+      {% endfor %}
+    </ul>
+  {% endif %}
+
+  {% if area.boulders.count > 0 %}
+    Boulders
+    <ul>
+      {% for boulder in area.boulders.all %}
+        <li>{{ boulder.name }}</li>
+      {% endfor %}
+    </ul>
+  {% endif %}
+
+  {% if area.routes.count > 0 %}
+    Routes
+    <ul>
+      {% for route in area.routes.all %}
+        <li>{{ route.name }}</li>
+      {% endfor %}
+    </ul>
+  {% endif %}
+</li>
diff --git a/tickle/urls.py b/tickle/urls.py
new file mode 100644 (file)
index 0000000..06c007e
--- /dev/null
@@ -0,0 +1,19 @@
+from django.urls import path
+
+from . import views
+
+# TODO Move attempts and todos to sub-area under user URLs
+# TODO Use something other than primary keys in URLs
+
+app_name = 'tickle'
+
+urlpatterns = (
+    path('area', views.area_list, name='area-list'),
+    path('area/<int:pk>', views.area_detail, name='area-detail'),
+    path('attempt', views.attempt_list, name='attempt-list'),
+    path('boulder', views.boulder_list, name='boulder-list'),
+    path('boulder/<int:pk>', views.boulder_detail, name='boulder-detail'),
+    path('route', views.route_list, name='route-list'),
+    path('route/<int:pk>', views.route_detail, name='route-detail'),
+    path('todo', views.todo_list, name='todo-list'),
+)
index 91ea44a..858d48c 100644 (file)
@@ -1,3 +1,35 @@
-from django.shortcuts import render
+from django.views.generic import DetailView, ListView
 
-# Create your views here.
+from . import models
+
+class AreaDetailView(DetailView):
+    model = models.Area
+area_detail = AreaDetailView.as_view()
+
+class AreaListView(ListView):
+    queryset = models.Area.objects.filter(parent=None)
+area_list = AreaListView.as_view()
+
+class AttemptListView(ListView):
+    pass
+attempt_list = AttemptListView.as_view()
+
+class BoulderDetailView(DetailView):
+    pass
+boulder_detail = BoulderDetailView.as_view()
+
+class BoulderListView(ListView):
+    pass
+boulder_list = BoulderListView.as_view()
+
+class RouteDetailView(DetailView):
+    pass
+route_detail = RouteDetailView.as_view()
+
+class RouteListView(ListView):
+    pass
+route_list = RouteListView.as_view()
+
+class TodoListView(ListView):
+    pass
+todo_list = TodoListView.as_view()