prettified the home page and moved workshops to another page called workshops.
authornishanth
Mon, 12 Apr 2010 18:15:21 +0530
changeset 18 7dae32a2439b
parent 17 125b6fc8f20b
child 19 115860e87238
prettified the home page and moved workshops to another page called workshops.
reg/events.py
reg/forms.py
reg/models.py
reg/site/urls.py
reg/views.py
templates/base.html
templates/index.html
templates/list_events.html
templates/login.html
templates/view_event.html
templates/view_profile.html
--- a/reg/events.py	Mon Apr 12 16:17:53 2010 +0530
+++ b/reg/events.py	Mon Apr 12 18:15:21 2010 +0530
@@ -75,7 +75,6 @@
     new_password = gen_key(10)
     user.set_password(new_password)
     user.save()
-    print "The new password is", new_password
     return new_password
 
 def change_password(user, new_password):
--- a/reg/forms.py	Mon Apr 12 16:17:53 2010 +0530
+++ b/reg/forms.py	Mon Apr 12 18:15:21 2010 +0530
@@ -46,6 +46,24 @@
         model = Profile
         fields = ['email', 'password', 'confirm_password', 'first_name', 'last_name', 'gender', 'profession', 'affiliated_to', 'interests']
 
+    def clean_first_name(self):
+        """ firstname should contain only alphabets.
+        """
+
+        first_name = self.cleaned_data['first_name']
+        if first_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return first_name
+
+    def clean_last_name(self):
+        """ only alphabets allowed.
+        """
+
+        last_name = self.cleaned_data['last_name']
+        if last_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return last_name
+
     def clean_email(self):
         """ check if a user exists with same email.
         """
@@ -97,10 +115,8 @@
         """
 
         stop_date = self.cleaned_data['stop_date']
-        try:
-            start_date = datetime.strptime(self.data['start_date'], "%Y-%m-%d").date()
-        except ValueError:
-            raise forms.ValidationError("Enter a valid date")
+
+        start_date = self.clean_start_date()
 
         if start_date > stop_date:
             raise forms.ValidationError('The event stops even before it starts. I am starting to wonder what kind of event is this.')
@@ -157,6 +173,8 @@
         if not new_password == self.data['confirm_password']:
             raise forms.ValidationError("Passwords do not match")
 
+        return new_password
+
 class EditProfileForm(forms.Form):
     """ form for editing the profile.
     """
@@ -168,4 +186,22 @@
     affiliated_to = forms.CharField(max_length=100, required=True, label="College/Company")
     interests = forms.CharField(max_length=100, label="Fields of interest")
 
+    def clean_first_name(self):
+        """ firstname should contain only alphabets.
+        """
 
+        first_name = self.cleaned_data['first_name']
+        if first_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return first_name
+
+    def clean_last_name(self):
+        """ only alphabets allowed.
+        """
+
+        last_name = self.cleaned_data['last_name']
+        if last_name.strip(string.ascii_letters):
+            raise forms.ValidationError("Name must contain only alphabets")
+        return last_name
+
+
--- a/reg/models.py	Mon Apr 12 16:17:53 2010 +0530
+++ b/reg/models.py	Mon Apr 12 18:15:21 2010 +0530
@@ -40,8 +40,8 @@
 
     title = models.CharField(max_length=100)
     description = models.TextField()
-    start_date = models.DateField(help_text="YYYY-MM-DD")
-    stop_date = models.DateField(help_text="YYYY-MM-DD")
+    start_date = models.DateField(verbose_name="Start Date")
+    stop_date = models.DateField(verbose_name="End Date")
     attendees = models.ManyToManyField(User, related_name="%(class)s_attendees")
     organizers = models.ManyToManyField(User, related_name="%(class)s_organizers")
     
--- a/reg/site/urls.py	Mon Apr 12 16:17:53 2010 +0530
+++ b/reg/site/urls.py	Mon Apr 12 18:15:21 2010 +0530
@@ -12,6 +12,7 @@
     (r'^password_reset/$', reg_views.reset_password),
     (r'^password_change/$', reg_views.change_password),
     (r'^event/create/$', reg_views.create_event),
+    (r'^event/list/$', reg_views.list_events),                       
     (r'^event/view/(\w+)/$', reg_views.view_event),
     (r'^event/register/(\w+)/$', reg_views.register_for_event),
     (r'^event/feedback/open/(\w+)/$', reg_views.open_feedback),
--- a/reg/views.py	Mon Apr 12 16:17:53 2010 +0530
+++ b/reg/views.py	Mon Apr 12 18:15:21 2010 +0530
@@ -1,3 +1,5 @@
+from datetime import datetime
+
 from django.contrib.auth.models import User
 from django.contrib.auth import authenticate, login, logout
 from django.contrib.auth.decorators import login_required
@@ -19,9 +21,8 @@
     """
 
     user = request.user
-    events = Event.objects.all()[:10]
 
-    return render_to_response('index.html', {'user':user, 'events':events})
+    return render_to_response('index.html', {'user':user})
 
 def user_login(request):
     """ get the user object from e-mail and then check for password.
@@ -324,4 +325,18 @@
         form = reg_forms.EditProfileForm(old_info)
         return render_to_response('edit_profile.html', {'user':user, 'form':form})
 
+def list_events(request):
+    """ Get all the events including those that are over and list them.
+    """
 
+    user = request.user
+
+    today = datetime.now()
+    context = {'user':user,
+               'upcoming_events': Event.objects.filter(start_date__gt=today),
+               'ongoing_events': Event.objects.filter(start_date__lte=today, stop_date__gte=today),
+               'previous_events': Event.objects.filter(stop_date__lt=today),
+              }
+
+    return render_to_response('list_events.html', context)
+
--- a/templates/base.html	Mon Apr 12 16:17:53 2010 +0530
+++ b/templates/base.html	Mon Apr 12 18:15:21 2010 +0530
@@ -137,7 +137,7 @@
 		<li><a href="/reg/register/">Register</a></li>
 	{% endif %}
 	<br />
-	<li><a href="/reg/events/list">Workshops</a></li>
+	<li><a href="/reg/event/list">Workshops</a></li>
 	</ul>
 </div>
 <br />
--- a/templates/index.html	Mon Apr 12 16:17:53 2010 +0530
+++ b/templates/index.html	Mon Apr 12 18:15:21 2010 +0530
@@ -1,6 +1,7 @@
 {% extends "base.html" %}
 {% block content %}
-	{% for event in events %}
-		<a href="/reg/event/view/{{event.key}}">{{event.title}}</a><br />
-	{% endfor %}
+	{% if user.is_staff %}
+		<a href="/reg/event/create">Create an event</a><br />	
+	{% endif %}
+
 {% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/list_events.html	Mon Apr 12 18:15:21 2010 +0530
@@ -0,0 +1,42 @@
+{% extends "base.html" %}
+{% block content %}
+	{% if ongoing_events %}
+		Ongoing Workshops:
+		<table cellspacing=5 cellpadding=5>
+		{% for event in ongoing_events %}
+			<tr>
+				<td><a href="/reg/event/view/{{event.key}}">{{event.title}}</a></td>
+				<td>{{event.start_date|date:"d M Y"}} - {{event.stop_date|date:"d M Y"}}</td>
+			</tr>
+		{% endfor %}
+		</table>
+	{% endif %}
+	
+	{% if upcoming_events %}
+		Upcoming Workshops:
+		<table cellspacing=5 cellpadding=5>
+		{% for event in upcoming_events %}
+			<tr>
+				<td><a href="/reg/event/view/{{event.key}}">{{event.title}}</a></td>
+				<td>{{event.start_date|date:"d M Y"}} - {{event.stop_date|date:"d M Y"}}</td>
+			</tr>
+		{% endfor %}
+		</table>
+	{% endif %}
+	
+	<br />
+	
+	{% if previous_events %}
+		Previous Workshops:
+		<table cellspacing=5 cellpadding=5>
+		{% for event in previous_events %}
+			<tr>
+				<td><a href="/reg/event/view/{{event.key}}">{{event.title}}</a></td>
+				<td>{{event.start_date|date:"d M Y"}} - {{event.stop_date|date:"d M Y"}}</td>
+			</tr>
+		{% endfor %}
+		</table>
+	{% endif %}
+
+{% endblock %}
+
--- a/templates/login.html	Mon Apr 12 16:17:53 2010 +0530
+++ b/templates/login.html	Mon Apr 12 18:15:21 2010 +0530
@@ -4,4 +4,5 @@
 {{ form.as_p }}
 <input type="submit" value="Login">
 </form>
+<a href="/reg/password_reset/">Forgot Password</a>
 {% endblock %}
--- a/templates/view_event.html	Mon Apr 12 16:17:53 2010 +0530
+++ b/templates/view_event.html	Mon Apr 12 18:15:21 2010 +0530
@@ -2,9 +2,10 @@
 {% block content %}
 	<h3>{{ event.title }}</h3><br />
 	Description:<br />
-	{{event.description}}<br />
+	{{event.description|linebreaksbr}}<br />
 	duration of the workshop: {{event.start_date}} to {{event.stop_date}}<br />
-	{% if not is_guest %}
+	
+	{% if not is_guest and event.registration_is_open %}
 		{% if is_attendee %}
 			You have registered for this workshop.
 		{% else %}
--- a/templates/view_profile.html	Mon Apr 12 16:17:53 2010 +0530
+++ b/templates/view_profile.html	Mon Apr 12 18:15:21 2010 +0530
@@ -1,6 +1,8 @@
 {% extends "base.html" %}
 {% block content %}
-<a href="/reg/profile/edit">Edit Profile</a><br />
+<a href="/reg/profile/edit">Edit Profile</a> | 
+<a href="/reg/password_change">Change Password</a>
+<br />
 {{user.first_name}} {{user.last_name}}<br />
 {{user_profile.affiliated_to }}<br />
 {{user_profile.interests }}<br />