From 6d40700cf3befe32ebfe4296e0bbd4f427037d55 Mon Sep 17 00:00:00 2001 From: Shane Frischkorn Date: Wed, 11 Sep 2013 23:44:40 +1000 Subject: [PATCH] Implemented tree view for selection of samples --- db.sqlite3 | Bin 159744 -> 159744 bytes three_d_viewer/models.py | 3 +- three_d_viewer/templates/children.html | 7 ---- three_d_viewer/templates/main.html | 1 - .../templates/three_d_viewer/detail.html | 26 +++++++----- .../templates/three_d_viewer/home.html | 31 ++++++++++++++ .../templates/three_d_viewer/index.html | 9 ----- .../templates/three_d_viewer/sampletree.html | 26 ++++++++++++ three_d_viewer/tests.py | 1 + three_d_viewer/urls.py | 2 +- three_d_viewer/views.py | 38 ++++++++++-------- 11 files changed, 99 insertions(+), 45 deletions(-) delete mode 100644 three_d_viewer/templates/children.html delete mode 100644 three_d_viewer/templates/main.html create mode 100644 three_d_viewer/templates/three_d_viewer/home.html delete mode 100644 three_d_viewer/templates/three_d_viewer/index.html create mode 100644 three_d_viewer/templates/three_d_viewer/sampletree.html diff --git a/db.sqlite3 b/db.sqlite3 index 8a79ac1efe6ce0c9d4d0b9c9a957ef743ff325a7..2791a43a9180deb433e6134c38608ad87e9bffab 100644 GIT binary patch delta 377 zcmZp8z}fJCbAmKu*+dy<#rQeEaTk5EK}o(!mRXc zvy{n?{+g({&SZ;zyrDYE^hX2vFs#VjE0lMnt?+-&pj1S1bKzXt>VcK%#` z4}Oo$f(91+sw&LBjD#G*Ha(Z0QByIi*wiAYBD<*6 Uf_wm$p8VmT)b4p4^3X|XbF=1n2^=&GJ@HgB1JHg1s#GlK+znwpq zKNqMWo_~5SKcl9ig?Vv7v58rcVR2e|euYJnxp{7SUPe_;k+F%XWwNCa^Y-ohjJ^ke tnh!DXKjc5ezZj@_20x?Sn5`T&e93?lUS(008AuJ#GL1 diff --git a/three_d_viewer/models.py b/three_d_viewer/models.py index d501a67..58da823 100644 --- a/three_d_viewer/models.py +++ b/three_d_viewer/models.py @@ -42,7 +42,8 @@ class Sample(CommonInfo): description = models.CharField(max_length=2000, default='', blank=True, null=True) parent = models.ForeignKey(Category, blank=True, null=True, - on_delete=models.SET_NULL) + on_delete=models.SET_NULL, + related_name="samples") class Question(models.Model): diff --git a/three_d_viewer/templates/children.html b/three_d_viewer/templates/children.html deleted file mode 100644 index 6bd5d19..0000000 --- a/three_d_viewer/templates/children.html +++ /dev/null @@ -1,7 +0,0 @@ -
    - {% for child in children %} -
  • {{ child }}
  • - {% child.children.count > 0 %} - {% children_list child %} - {% endfor %} -
\ No newline at end of file diff --git a/three_d_viewer/templates/main.html b/three_d_viewer/templates/main.html deleted file mode 100644 index 38d7759..0000000 --- a/three_d_viewer/templates/main.html +++ /dev/null @@ -1 +0,0 @@ -{% children_tag parent %} \ No newline at end of file diff --git a/three_d_viewer/templates/three_d_viewer/detail.html b/three_d_viewer/templates/three_d_viewer/detail.html index c7b107b..97e8c08 100644 --- a/three_d_viewer/templates/three_d_viewer/detail.html +++ b/three_d_viewer/templates/three_d_viewer/detail.html @@ -366,8 +366,7 @@ function my_callback(data){ } alert(message); } - - + @@ -380,16 +379,23 @@ function my_callback(data){
- {% if sample.questions %} - {{ sample.questions.all.0 }}
- {% for answer in sample.questions.all.0.answers.all %} - {{ answer}}
- {% endfor %} - - {% endif %} +
+ {% include "three_d_viewer/sampletree.html" %} +
+
+
+ {% if sample.questions %} + {{ sample.questions.all.0 }}
+ {% for answer in sample.questions.all.0.answers.all %} + {{ answer}}
+ {% endfor %} + + {% endif %} +
+
- +

diff --git a/three_d_viewer/templates/three_d_viewer/home.html b/three_d_viewer/templates/three_d_viewer/home.html new file mode 100644 index 0000000..d893d36 --- /dev/null +++ b/three_d_viewer/templates/three_d_viewer/home.html @@ -0,0 +1,31 @@ +{% load static %} +{% load dajaxice_templatetags %} + + + + 3D Sample Viewer + + + + + + +
+ + +
+
+
+ {% include "three_d_viewer/sampletree.html" %} +
+
+
+

Put some intro text sort of stuff here +

+
+ \ No newline at end of file diff --git a/three_d_viewer/templates/three_d_viewer/index.html b/three_d_viewer/templates/three_d_viewer/index.html deleted file mode 100644 index 9854e21..0000000 --- a/three_d_viewer/templates/three_d_viewer/index.html +++ /dev/null @@ -1,9 +0,0 @@ -{% if active_samples %} - -{% else %} -

No samples are available.

-{% endif %} \ No newline at end of file diff --git a/three_d_viewer/templates/three_d_viewer/sampletree.html b/three_d_viewer/templates/three_d_viewer/sampletree.html new file mode 100644 index 0000000..8b18aa0 --- /dev/null +++ b/three_d_viewer/templates/three_d_viewer/sampletree.html @@ -0,0 +1,26 @@ + + +
+ +
diff --git a/three_d_viewer/tests.py b/three_d_viewer/tests.py index dd3417d..71eabc9 100644 --- a/three_d_viewer/tests.py +++ b/three_d_viewer/tests.py @@ -7,6 +7,7 @@ Replace this with more appropriate tests for your application. from django.test import TestCase from three_d_viewer.models import Category, Question, Answer +from three_d_viewer.views import DetailView import ajax diff --git a/three_d_viewer/urls.py b/three_d_viewer/urls.py index 4ab5c49..963d4b6 100644 --- a/three_d_viewer/urls.py +++ b/three_d_viewer/urls.py @@ -4,7 +4,7 @@ from three_d_viewer import views urlpatterns = patterns( '', - url(r'^$', views.IndexView.as_view(), name='index'), + url(r'^$', views.HomeView.as_view(), name='home'), url(r'^(?P\d+)/$', views.DetailView.as_view(), name='detail'), url(r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), diff --git a/three_d_viewer/views.py b/three_d_viewer/views.py index 290b73b..e54fd09 100644 --- a/three_d_viewer/views.py +++ b/three_d_viewer/views.py @@ -5,33 +5,39 @@ Define the views for the Django MVC from django import template from django.views import generic -from three_d_viewer.models import Sample +from three_d_viewer.models import Sample, Category register = template.Library() -@register.inclusion_tag('children.html') -def children_tag(category): - children = category.children.all() - return {'children': children} - - -class IndexView(generic.ListView): +class HomeView(generic.ListView): """ - Define the page to display the Sample objects that can be viewed + Show the home page """ - template_name = 'three_d_viewer/index.html' - context_object_name = 'active_samples' - def get_queryset(self): - """ - Return the active samples - """ - return Sample.objects.filter(active=True) + template_name = 'three_d_viewer/home.html' + model = Sample + + def get_context_data(self, **kwargs): + context = super(HomeView, self).get_context_data(**kwargs) + context['active_samples'] = Sample.objects.filter(active=True) + context['parent_categories'] = Category.objects.filter(parent=None). \ + filter(active=True) + return context class DetailView(generic.DetailView): """ Define the view to view the 3D model of a sample """ + model = Sample template_name = 'three_d_viewer/detail.html' + parent_categories = Category.objects.filter(parent=None). \ + filter(active=True) + + def get_context_data(self, **kwargs): + context = super(DetailView, self).get_context_data(**kwargs) + context['active_samples'] = Sample.objects.filter(active=True) + context['parent_categories'] = Category.objects.filter(parent=None). \ + filter(active=True) + return context