Commits

Jernej Kos  committed 9ee024a

Added question separators and some admin improvements.

  • Participants
  • Parent commits 5b4fbe0

Comments (0)

Files changed (9)

File survey/admin.py

 
 from . import models as survey_models
 
-admin.site.register(survey_models.Survey)
+class QuestionInline(admin.TabularInline):
+  model = survey_models.Question
+  extra = 0
+
+class SurveyAdmin(admin.ModelAdmin):
+  inlines = [
+    QuestionInline
+  ]
+
+admin.site.register(survey_models.Survey, SurveyAdmin)
+
+class SimpleChoiceInline(admin.TabularInline):
+  model = survey_models.SimpleChoice
+
+class SimpleChoiceQuestionAdmin(admin.ModelAdmin):
+  inlines = [
+    SimpleChoiceInline
+  ]
 
 admin.site.register(survey_models.SimpleChoice)
-admin.site.register(survey_models.SimpleChoiceQuestion)
+admin.site.register(survey_models.SimpleChoiceQuestion, SimpleChoiceQuestionAdmin)
+
+class ChoiceColumnInline(admin.TabularInline):
+  model = survey_models.ChoiceColumn
+
+class ChoiceRowInline(admin.TabularInline):
+  model = survey_models.ChoiceRow
+
+class ColumnChoiceQuestionAdmin(admin.ModelAdmin):
+  inlines = [
+    ChoiceColumnInline,
+    ChoiceRowInline
+  ]
 
 admin.site.register(survey_models.ChoiceColumn)
 admin.site.register(survey_models.ChoiceRow)
-admin.site.register(survey_models.ColumnChoiceQuestion)
+admin.site.register(survey_models.ColumnChoiceQuestion, ColumnChoiceQuestionAdmin)
+
+class MultipleChoiceInline(admin.TabularInline):
+  model = survey_models.MultipleChoice
+
+class MultipleChoiceQuestionAdmin(admin.ModelAdmin):
+  inlines = [
+    MultipleChoiceInline
+  ]
 
 admin.site.register(survey_models.MultipleChoice)
-admin.site.register(survey_models.MultipleChoiceQuestion)
+admin.site.register(survey_models.MultipleChoiceQuestion, MultipleChoiceQuestionAdmin)
 
 admin.site.register(survey_models.NumericRangeQuestion)
 
 admin.site.register(survey_models.NumericEntryQuestion)
+
+admin.site.register(survey_models.SeparatorQuestion)

File survey/models.py

   class Meta:
     ordering = ['order']
 
+  survey = models.ForeignKey('Survey', related_name = 'questions')
   order = models.IntegerField()
   description = models.TextField()
 
     return tpl.render(template.Context({ "form" : form, "question" : self }))
 
   def __unicode__(self):
-    return u"%d) %s" % (self.order, self.description)
+    if len(self.description) > 70:
+      return self.description[:67] + u"..."
+    
+    return self.description
+
+class SeparatorQuestion(Question):
+  def get_form(self, **kwargs): pass
+  def submit(self, data): pass
 
 class SimpleChoice(models.Model):
   class Meta:
 
   sid = models.CharField(primary_key = True, max_length = 15, editable = False, default = generate_sid)
   title = models.CharField(max_length = 200)
-  questions = models.ManyToManyField(Question)
 
   def save(self, *args, **kwargs):
     if self.sid is None:
       subject.save()
 
     for question in self.questions.all():
+      if question.get_form() is None:
+        continue
+      
       try:
         answer = Answer.objects.get(subject = subject, survey = self, question = question)
       except Answer.DoesNotExist:

File survey/views.py

 
   answers = []
   for question in survey.questions.all():
+    if question.get_form() is None:
+      continue
+    
     answer = survey.subject_answers.get(question = question, subject = subject)
     answers.append(answer)
 

File templates/survey/questions/column_choice.html

-<b>({{ question.order }}) {{ question.description }}</b>
+<b>{{ question.description }}</b>
 <br/>
 {{ form.as_p }}

File templates/survey/questions/multiple_choice.html

-<b>({{ question.order }}) {{ question.description }}</b>
+<b>{{ question.description }}</b>
 <br/>
 {{ form.choice }}
 <br/>

File templates/survey/questions/numeric_entry.html

-<b>({{ question.order }}) {{ question.description }}</b>
+<b>{{ question.description }}</b>
 <br/>
 {{ form.value }}

File templates/survey/questions/numeric_range.html

-<b>({{ question.order }}) {{ question.description }}</b>
+<b>{{ question.description }}</b>
 <br/>
 {{ form.choice }}

File templates/survey/questions/separator.html

+<b><u>{{ question.description }}</u></b>

File templates/survey/questions/simple_choice.html

-<b>({{ question.order }}) {{ question.description }}</b>
+<b>{{ question.description }}</b>
 <br/>
 {{ form.choice }}