diff --git a/db.sqlite3 b/db.sqlite3 index 8a79ac1..2791a43 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ 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 @@ - \ 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