modified seed_db and view_event template .
authornishanth
Tue, 13 Apr 2010 14:20:57 +0530
changeset 23 42e2a810e1c8
parent 22 737ec98cf6df
child 24 31d37d0cf557
modified seed_db and view_event template .
reg/events.py
reg/management/commands/seed_db.py
reg/site/urls.py
reg/views.py
templates/account_inactive.html
templates/list_attendees.html
--- a/reg/events.py	Tue Apr 13 12:07:44 2010 +0530
+++ b/reg/events.py	Tue Apr 13 14:20:57 2010 +0530
@@ -41,7 +41,7 @@
     """ get key from profile and send an email.
     """
 
-    print user.get_profile().activation_key
+    print "http://localhost:8000/reg/activate/%s"%user.get_profile().activation_key
 
 def create_event(title, description, start_date, stop_date, created_by=None):
     """ make an event and save it.
--- a/reg/management/commands/seed_db.py	Tue Apr 13 12:07:44 2010 +0530
+++ b/reg/management/commands/seed_db.py	Tue Apr 13 14:20:57 2010 +0530
@@ -9,12 +9,21 @@
 
 def seed_db():
     """ a method to seed the database with random data """
-    
+
+    user = create_user('admin@example.com', '12345678', 'Admin', 'Fossee')
+    user.is_active = True
+    user.is_staff = True
+    user.is_superuser = True
+    user.save()
+
+"""    
     for i in range(20):
         user = create_user('user'+str(i)+'@example.com','123456', 'User', str(i))
 
     for i in range(5):
         create_event("workshop"+str(i), "This is workshop"+str(i), datetime(2010, 4, i+4), datetime(2010, 4, i+6), user)
+
+"""
     
 class Command(NoArgsCommand):
     
--- a/reg/site/urls.py	Tue Apr 13 12:07:44 2010 +0530
+++ b/reg/site/urls.py	Tue Apr 13 14:20:57 2010 +0530
@@ -9,6 +9,7 @@
     (r'^register/$', reg_views.user_register),
     (r'^account_created/$', reg_views.account_created),                       
     (r'^resend_activation/$', reg_views.resend_activation),
+    (r'^activate/(\w+)/$', reg_views.account_activate),
     (r'^profile/view/$', reg_views.view_profile),
     (r'^profile/edit/$', reg_views.edit_profile),                       
     (r'^password_reset/$', reg_views.reset_password),
--- a/reg/views.py	Tue Apr 13 12:07:44 2010 +0530
+++ b/reg/views.py	Tue Apr 13 14:20:57 2010 +0530
@@ -9,7 +9,7 @@
 
 from django.shortcuts import render_to_response, redirect
 
-from workshop.reg.models import Event
+from workshop.reg.models import Event, Profile
 from workshop.reg import forms as reg_forms
 from workshop.reg import events as reg_events
 
@@ -76,6 +76,7 @@
                                               affiliated_to=data['affiliated_to'], 
                                               interests=data['interests']
                                              )
+            reg_events.send_activation(new_user)
             return redirect('/reg/account_created')
         else:
             return render_to_response('register.html', {'form':form})
@@ -90,7 +91,27 @@
     user = request.user
     return render_to_response('account_created.html', {'user':user})
 
+def account_activate(request, activation_key):
+    """ see if the key exists.
+    see if the corresponding user is inactive.
+    """
+
+    user = request.user
+    if user.is_authenticated():
+        return redirect('/reg')
+
+    try:
+        profile = Profile.objects.get(activation_key__iexact=activation_key)
+    except Profile.DoesNotExist:
+        raise Http404
+
+    user = profile.user
+    reg_events.activate_user(user)
+    return render_to_response('account_activated.html', {'user':user})
+    
 def resend_activation(request):
+    """ resend only if user is registered and is inactive.
+    """
 
     try:
         email = request.GET['email']
--- a/templates/account_inactive.html	Tue Apr 13 12:07:44 2010 +0530
+++ b/templates/account_inactive.html	Tue Apr 13 14:20:57 2010 +0530
@@ -2,5 +2,5 @@
 {% block content %}
 Your account is inactive. An activation email has been sent to your email address.<br />
 <a href="/reg/resend_activation/?email={{email}}">Click here</a> to resend the activation email.<br />
-<a href="/reg">click here</a> to go to home page.
+
 {% endblock %}
--- a/templates/list_attendees.html	Tue Apr 13 12:07:44 2010 +0530
+++ b/templates/list_attendees.html	Tue Apr 13 14:20:57 2010 +0530
@@ -1,6 +1,6 @@
 {% extends "base.html" %}
 {% block content %}
-	List of people registered for "{{event.title}}"<br /><br />
+	List of people registered for <a href="/reg/event/view/{{event.key}}">{{event.title}}</a><br /><br />
 	<table cellspacing=5 cellpadding=5>
 	<tr>
 		<td>Name</td>