Commits

Jernej Kos  committed 5b4fbe0

Record the user that first entered a subject.

  • Participants
  • Parent commits d5ae918

Comments (0)

Files changed (3)

File survey/models.py

 from django import forms, template
 from django.db import models
+from django.contrib.auth.models import User
 
 import polymorphic
 import random
 
     super(Survey, self).save(*args, **kwargs)
 
-  def submit(self, data, subject = None):
+  def submit(self, data, subject = None, user = None):
     if subject is None:
-      subject = Subject()
+      subject = Subject(created_by = user)
       subject.save()
 
     for question in self.questions.all():
 
   sid = models.AutoField(primary_key = True)
   created_at = models.DateTimeField(auto_now_add = True)
+  created_by = models.ForeignKey(User, null = True)
 
 class Answer(models.Model):
   subject = models.ForeignKey(Subject, related_name = 'answers')

File survey/views.py

 def enter_survey_instance(request, survey_id):
   survey = get_object_or_404(survey_models.Survey, pk = survey_id)
   if request.method == 'POST':
-    subject = survey.submit(request.POST)
+    subject = survey.submit(request.POST, user = request.user)
     return render_to_response('survey/submit_done.html', dict(
       survey = survey, subject = subject), context_instance = RequestContext(request))
 

File templates/survey/list_subjects.html

 Subjects:
 <hr/>
 {% for subject in survey.get_subjects %}
-<a href="{% url edit_survey survey.pk subject.pk %}">Subject {{ subject.pk }}</a> ({{ subject.created_at }})<br/>
+<a href="{% url edit_survey survey.pk subject.pk %}">Subject {{ subject.pk }}</a> ({{ subject.created_at }}, entered by <i>{{ subject.created_by }}</i>)<br/>
 {% endfor %}
 <hr/>
 <a href="{% url enter_survey survey.pk %}">Enter new subject</a>