Fixing recommendations from pylint
This commit is contained in:
@@ -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 three_d_viewer.models import Category, Sample, Question, Answer
|
||||
from models import Category, Sample, Question, Answer
|
||||
|
||||
admin.site.register(Category)
|
||||
admin.site.register(Sample)
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
"""
|
||||
Handle asynchronous calls from the web pages
|
||||
"""
|
||||
|
||||
from django.utils import simplejson
|
||||
from dajaxice.decorators import dajaxice_register
|
||||
|
||||
from three_d_viewer.models import Question
|
||||
|
||||
|
||||
@dajaxice_register
|
||||
def dajaxice_example(request):
|
||||
test = check_answer(request, 3, 1)
|
||||
print test
|
||||
return simplejson.dumps({'message': 'Hello from Python!'})
|
||||
from models import Question
|
||||
|
||||
|
||||
@dajaxice_register
|
||||
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))
|
||||
|
||||
result = False
|
||||
@@ -20,5 +22,5 @@ def check_answer(request, answerid, questionid):
|
||||
print type(answer.id)
|
||||
if answer.id == int(answerid):
|
||||
result = True
|
||||
print 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
|
||||
|
||||
|
||||
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)
|
||||
active = models.BooleanField(default=True)
|
||||
|
||||
@@ -9,16 +17,27 @@ class CommonInfo(models.Model):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
"""
|
||||
Declare the class as abstract
|
||||
"""
|
||||
abstract = True
|
||||
|
||||
|
||||
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,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='children')
|
||||
|
||||
|
||||
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)
|
||||
description = models.CharField(max_length=2000, default='', blank=True,
|
||||
null=True)
|
||||
@@ -27,10 +46,16 @@ class Sample(CommonInfo):
|
||||
|
||||
|
||||
class Question(models.Model):
|
||||
"""
|
||||
The definition of a multiple choice question, associated with a Sample
|
||||
"""
|
||||
text = models.CharField(max_length=2000)
|
||||
sample = models.ForeignKey(Sample, related_name='questions')
|
||||
|
||||
def correct_answers(self):
|
||||
"""
|
||||
Return a list of correct answers to the question
|
||||
"""
|
||||
return self.answers.filter(correct=True)
|
||||
|
||||
def __unicode__(self):
|
||||
@@ -38,6 +63,9 @@ class Question(models.Model):
|
||||
|
||||
|
||||
class Answer(models.Model):
|
||||
"""
|
||||
The definition of an answer to a Question
|
||||
"""
|
||||
text = models.CharField(max_length=2000)
|
||||
correct = models.BooleanField(default=False)
|
||||
question = models.ForeignKey(Question, related_name='answers')
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"""
|
||||
Define the views for the Django MVC
|
||||
"""
|
||||
|
||||
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 three_d_viewer.models import Sample
|
||||
@@ -15,6 +16,9 @@ def children_tag(category):
|
||||
|
||||
|
||||
class IndexView(generic.ListView):
|
||||
"""
|
||||
Define the page to display the Sample objects that can be viewed
|
||||
"""
|
||||
template_name = 'three_d_viewer/index.html'
|
||||
context_object_name = 'active_samples'
|
||||
|
||||
@@ -26,5 +30,8 @@ class IndexView(generic.ListView):
|
||||
|
||||
|
||||
class DetailView(generic.DetailView):
|
||||
"""
|
||||
Define the view to view the 3D model of a sample
|
||||
"""
|
||||
model = Sample
|
||||
template_name = 'three_d_viewer/detail.html'
|
||||
|
||||
Reference in New Issue
Block a user