Fixing pep8 recommendations
This commit is contained in:
@@ -3,16 +3,18 @@ from dajaxice.decorators import dajaxice_register
|
|||||||
|
|
||||||
from three_d_viewer.models import Question
|
from three_d_viewer.models import Question
|
||||||
|
|
||||||
|
|
||||||
@dajaxice_register
|
@dajaxice_register
|
||||||
def dajaxice_example(request):
|
def dajaxice_example(request):
|
||||||
test = check_answer(request, 3, 1)
|
test = check_answer(request, 3, 1)
|
||||||
print test
|
print test
|
||||||
return simplejson.dumps({'message':'Hello from Python!'})
|
return simplejson.dumps({'message': 'Hello from Python!'})
|
||||||
|
|
||||||
@dajaxice_register
|
|
||||||
|
@dajaxice_register
|
||||||
def check_answer(request, answerid, questionid):
|
def check_answer(request, answerid, questionid):
|
||||||
question = Question.objects.get(id=int(questionid))
|
question = Question.objects.get(id=int(questionid))
|
||||||
|
|
||||||
result = False
|
result = False
|
||||||
for answer in question.correct_answers():
|
for answer in question.correct_answers():
|
||||||
print type(answer.id)
|
print type(answer.id)
|
||||||
@@ -20,4 +22,3 @@ def check_answer(request, answerid, questionid):
|
|||||||
result = True
|
result = True
|
||||||
print simplejson.dumps({'result': result})
|
print simplejson.dumps({'result': result})
|
||||||
return simplejson.dumps({'result': result})
|
return simplejson.dumps({'result': result})
|
||||||
|
|
||||||
@@ -20,7 +20,8 @@ class Category(CommonInfo):
|
|||||||
|
|
||||||
class Sample(CommonInfo):
|
class Sample(CommonInfo):
|
||||||
model_filename = models.CharField(max_length=1000)
|
model_filename = models.CharField(max_length=1000)
|
||||||
description = models.CharField(max_length=2000, default='', blank=True, null=True)
|
description = models.CharField(max_length=2000, default='', blank=True,
|
||||||
|
null=True)
|
||||||
parent = models.ForeignKey(Category, blank=True, null=True,
|
parent = models.ForeignKey(Category, blank=True, null=True,
|
||||||
on_delete=models.SET_NULL)
|
on_delete=models.SET_NULL)
|
||||||
|
|
||||||
@@ -30,15 +31,16 @@ class Question(models.Model):
|
|||||||
sample = models.ForeignKey(Sample, related_name='questions')
|
sample = models.ForeignKey(Sample, related_name='questions')
|
||||||
|
|
||||||
def correct_answers(self):
|
def correct_answers(self):
|
||||||
return self.answers.filter(correct = True)
|
return self.answers.filter(correct=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|
||||||
|
|
||||||
class Answer(models.Model):
|
class Answer(models.Model):
|
||||||
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')
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.text
|
return self.text
|
||||||
|
|||||||
@@ -13,33 +13,33 @@ class ModelsTest(TestCase):
|
|||||||
#def setUp(self):
|
#def setUp(self):
|
||||||
#CommonInfo.objects.create(name="test", active=True)
|
#CommonInfo.objects.create(name="test", active=True)
|
||||||
# Animal.objects.create(name="cat", sound="meow")
|
# Animal.objects.create(name="cat", sound="meow")
|
||||||
|
|
||||||
def test_common_unicode(self):
|
def test_common_unicode(self):
|
||||||
"""
|
"""
|
||||||
Tests the unicode method for categories
|
Tests the unicode method for categories
|
||||||
"""
|
"""
|
||||||
testcat = Category(name='test', active=True)
|
testcat = Category(name='test', active=True)
|
||||||
self.assertEqual("test", testcat.__unicode__())
|
self.assertEqual("test", testcat.__unicode__())
|
||||||
|
|
||||||
def test_question_unicode(self):
|
def test_question_unicode(self):
|
||||||
"""
|
"""
|
||||||
Tests the unicode method for questions
|
Tests the unicode method for questions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
testquestion = Question(text="Test")
|
testquestion = Question(text="Test")
|
||||||
self.assertEqual("Test", testquestion.__unicode__())
|
self.assertEqual("Test", testquestion.__unicode__())
|
||||||
|
|
||||||
def test_answer_unicode(self):
|
def test_answer_unicode(self):
|
||||||
"""
|
"""
|
||||||
Tests the unicode method for answers
|
Tests the unicode method for answers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
testanswer = Answer(text="Test")
|
testanswer = Answer(text="Test")
|
||||||
self.assertEqual("Test", testanswer.__unicode__())
|
self.assertEqual("Test", testanswer.__unicode__())
|
||||||
|
|
||||||
def test_no_correct_answers(self):
|
def test_no_correct_answers(self):
|
||||||
testquestion = Question(text="Test")
|
testquestion = Question(text="Test")
|
||||||
|
|
||||||
Answer(text="Test", correct=False, question=testquestion)
|
Answer(text="Test", correct=False, question=testquestion)
|
||||||
|
|
||||||
self.assertEqual(len(testquestion.correct_answers()), 0)
|
self.assertEqual(len(testquestion.correct_answers()), 0)
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ from django.conf import settings
|
|||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
from three_d_viewer import views
|
from three_d_viewer import views
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns(
|
||||||
|
'',
|
||||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||||
url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
|
url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(), name='detail'),
|
||||||
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
|
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
|
||||||
{'document_root': settings.MEDIA_ROOT}),
|
{'document_root': settings.MEDIA_ROOT}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user