Fixing recommendations from pylint
This commit is contained in:
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
@@ -0,0 +1,3 @@
|
|||||||
|
"""
|
||||||
|
Define three_d_viewer as a package
|
||||||
|
"""
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
"""
|
||||||
|
Configuration for the Django admin site
|
||||||
|
"""
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from three_d_viewer.models import Category, Sample, Question, Answer
|
from models import Category, Sample, Question, Answer
|
||||||
|
|
||||||
admin.site.register(Category)
|
admin.site.register(Category)
|
||||||
admin.site.register(Sample)
|
admin.site.register(Sample)
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
|
"""
|
||||||
|
Handle asynchronous calls from the web pages
|
||||||
|
"""
|
||||||
|
|
||||||
from django.utils import simplejson
|
from django.utils import simplejson
|
||||||
from dajaxice.decorators import dajaxice_register
|
from dajaxice.decorators import dajaxice_register
|
||||||
|
|
||||||
from three_d_viewer.models import Question
|
from models import Question
|
||||||
|
|
||||||
|
|
||||||
@dajaxice_register
|
|
||||||
def dajaxice_example(request):
|
|
||||||
test = check_answer(request, 3, 1)
|
|
||||||
print test
|
|
||||||
return simplejson.dumps({'message': 'Hello from Python!'})
|
|
||||||
|
|
||||||
|
|
||||||
@dajaxice_register
|
@dajaxice_register
|
||||||
def check_answer(request, answerid, questionid):
|
def check_answer(request, answerid, questionid):
|
||||||
|
"""
|
||||||
|
Check whether answerid is the correct answer for questionid.
|
||||||
|
Returns a boolean in 'result'
|
||||||
|
"""
|
||||||
|
|
||||||
question = Question.objects.get(id=int(questionid))
|
question = Question.objects.get(id=int(questionid))
|
||||||
|
|
||||||
result = False
|
result = False
|
||||||
@@ -20,5 +22,5 @@ def check_answer(request, answerid, questionid):
|
|||||||
print type(answer.id)
|
print type(answer.id)
|
||||||
if answer.id == int(answerid):
|
if answer.id == int(answerid):
|
||||||
result = True
|
result = True
|
||||||
print simplejson.dumps({'result': result})
|
|
||||||
return simplejson.dumps({'result': result})
|
return simplejson.dumps({'result': result})
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
|
"""
|
||||||
|
Defines the models that that Django application uses
|
||||||
|
"""
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
class CommonInfo(models.Model):
|
class CommonInfo(models.Model):
|
||||||
|
"""
|
||||||
|
Common base class for models that need a name and active field. It is
|
||||||
|
intended to be an abstract class.
|
||||||
|
"""
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
active = models.BooleanField(default=True)
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
@@ -9,16 +17,27 @@ class CommonInfo(models.Model):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
"""
|
||||||
|
Declare the class as abstract
|
||||||
|
"""
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
class Category(CommonInfo):
|
class Category(CommonInfo):
|
||||||
|
"""
|
||||||
|
Contains the details for a category of samples. Categories have a parent
|
||||||
|
category field to another category which creates a tree structure.
|
||||||
|
"""
|
||||||
parent = models.ForeignKey('self', blank=True, null=True,
|
parent = models.ForeignKey('self', blank=True, null=True,
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
related_name='children')
|
related_name='children')
|
||||||
|
|
||||||
|
|
||||||
class Sample(CommonInfo):
|
class Sample(CommonInfo):
|
||||||
|
"""
|
||||||
|
The definition of a model itself. The model_filename is the path relative
|
||||||
|
to the models directory.
|
||||||
|
"""
|
||||||
model_filename = models.CharField(max_length=1000)
|
model_filename = models.CharField(max_length=1000)
|
||||||
description = models.CharField(max_length=2000, default='', blank=True,
|
description = models.CharField(max_length=2000, default='', blank=True,
|
||||||
null=True)
|
null=True)
|
||||||
@@ -27,10 +46,16 @@ class Sample(CommonInfo):
|
|||||||
|
|
||||||
|
|
||||||
class Question(models.Model):
|
class Question(models.Model):
|
||||||
|
"""
|
||||||
|
The definition of a multiple choice question, associated with a Sample
|
||||||
|
"""
|
||||||
text = models.CharField(max_length=2000)
|
text = models.CharField(max_length=2000)
|
||||||
sample = models.ForeignKey(Sample, related_name='questions')
|
sample = models.ForeignKey(Sample, related_name='questions')
|
||||||
|
|
||||||
def correct_answers(self):
|
def correct_answers(self):
|
||||||
|
"""
|
||||||
|
Return a list of correct answers to the question
|
||||||
|
"""
|
||||||
return self.answers.filter(correct=True)
|
return self.answers.filter(correct=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
@@ -38,6 +63,9 @@ class Question(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Answer(models.Model):
|
class Answer(models.Model):
|
||||||
|
"""
|
||||||
|
The definition of an answer to a Question
|
||||||
|
"""
|
||||||
text = models.CharField(max_length=2000)
|
text = models.CharField(max_length=2000)
|
||||||
correct = models.BooleanField(default=False)
|
correct = models.BooleanField(default=False)
|
||||||
question = models.ForeignKey(Question, related_name='answers')
|
question = models.ForeignKey(Question, related_name='answers')
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
"""
|
||||||
|
Define the views for the Django MVC
|
||||||
|
"""
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.shortcuts import get_object_or_404, render
|
|
||||||
from django.http import HttpResponseRedirect, HttpResponse
|
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
|
||||||
from three_d_viewer.models import Sample
|
from three_d_viewer.models import Sample
|
||||||
@@ -15,6 +16,9 @@ def children_tag(category):
|
|||||||
|
|
||||||
|
|
||||||
class IndexView(generic.ListView):
|
class IndexView(generic.ListView):
|
||||||
|
"""
|
||||||
|
Define the page to display the Sample objects that can be viewed
|
||||||
|
"""
|
||||||
template_name = 'three_d_viewer/index.html'
|
template_name = 'three_d_viewer/index.html'
|
||||||
context_object_name = 'active_samples'
|
context_object_name = 'active_samples'
|
||||||
|
|
||||||
@@ -26,5 +30,8 @@ class IndexView(generic.ListView):
|
|||||||
|
|
||||||
|
|
||||||
class DetailView(generic.DetailView):
|
class DetailView(generic.DetailView):
|
||||||
|
"""
|
||||||
|
Define the view to view the 3D model of a sample
|
||||||
|
"""
|
||||||
model = Sample
|
model = Sample
|
||||||
template_name = 'three_d_viewer/detail.html'
|
template_name = 'three_d_viewer/detail.html'
|
||||||
|
|||||||
Reference in New Issue
Block a user