Commits

Ed Crewe  committed 6b80f72

add user to votes too

  • Participants
  • Parent commits 4caf572

Comments (0)

Files changed (3)

File gaepuv/puv/poll/models.py

     datechoice = db.ReferenceProperty(DateChoice)
     created_by = db.StringProperty()
     created_on = db.DateTimeProperty(auto_now_add = 1)
+    user = db.UserProperty()
 
 class Country(db.Model):
     """ 2 letter iso code to geocode """

File gaepuv/puv/poll/views.py

     else:
         nochoice = None
     dates = models.DateChoice.all().filter('poll = ', poll)
-
+    user = users.get_current_user()
+    if user:
+        created_by = user.nickname()
     # Record the vote
     if request.method == 'POST':
         created_by = request.POST.get('created_by','')
                 if not poll.anonymous and created_by:
                     voter = models.Voter(poll = poll,
                                          choice = choice,
+                                         user = user,
                                          created_by = created_by)
                     voter.save()
         date_keys = request.POST.getlist('date')
             if not poll.anonymous and created_by:
                 voter = models.Voter(poll = poll,
                                      datechoice = datechoice,
+                                     user = user,
                                      created_by = created_by)
                 voter.save()
         poll.total_votes += 1
               'nochoice' : nochoice,
               'dates'  : dates, 
               'genjs' : js,
-              'input_type' : input_type
+              'input_type' : input_type,
+              'created_by' : created_by
             }
     return render_to_response('poll_details.html', props)

File gaepuv/puv/templates/poll_details.html

 {% if not poll.anonymous %}
 <fieldset>
 <label>Your name:</label>
-<input type="text" name="created_by"  size="40" id="id_created_by" value="" />
+<input type="text" name="created_by"  size="40" id="id_created_by" value="{{ created_by }}" />
 {% endif %}
 {% if nochoice %}
 <p>{{ nochoice.choice }}</p>