Anonymous avatar Anonymous committed 6b80f72

add user to votes too

Comments (0)

Files changed (3)

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 """

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)

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>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.