incorporated gen_key .
--- a/.hgignore Thu Apr 08 16:35:46 2010 +0530
+++ b/.hgignore Thu Apr 08 22:28:15 2010 +0530
@@ -3,3 +3,6 @@
*.db
*.pyc
*.swp
+*.bak
+*.swo
+*.db-journal
--- a/feedback/models.py Thu Apr 08 16:35:46 2010 +0530
+++ b/feedback/models.py Thu Apr 08 22:28:15 2010 +0530
@@ -39,12 +39,11 @@
('3', 'Somewhat instructive'),
('4', 'Not instructive'))
-
class Feedback(models.Model):
""" A table to hold the feedbacks.
"""
- user = models.ForeignKey(User)
+ user_ip = models.CharField(max_length=15)
event = models.ForeignKey(Event)
range_of_topics = models.CharField(max_length=1, choices=TOPICS_CHOICES,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/reg/events.py Thu Apr 08 22:28:15 2010 +0530
@@ -0,0 +1,41 @@
+#!/usr/bin/python
+
+from django.contrib.auth.models import User
+
+from django.db import IntegrityError
+
+from workshop.reg.models import Event
+from workshop.reg.utils import gen_key
+
+def create_user(email, password, firstname="", lastname=""):
+ """ create a user with random username and set the password.
+ """
+
+ username = ('%s %s'%(firstname, lastname)).title().strip()
+ new_user = User.objects.create_user(username, email, password)
+ new_user.firstname = firstname
+ new_user.lastname = lastname
+ new_user.is_active = False
+ new_user.save()
+ return new_user
+
+def create_event(title, desc, start_date, stop_date, created_by=None):
+ """ make an event and save it.
+ """
+
+ new_event = Event()
+ new_event.title = title
+ new_event.description = desc
+ new_event.start_date = start_date
+ new_event.stop_date = stop_date
+ new_event.save()
+ if created_by:
+ new_event.organizers.add(created_by)
+
+ new_event.key = gen_key()
+ while True:
+ try:
+ new_event.save()
+ return new_event
+ except IntegrityError:
+ new_event.key = gen_key()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/reg/management/__init__.py Thu Apr 08 22:28:15 2010 +0530
@@ -0,0 +1,1 @@
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/reg/management/commands/seed_db.py Thu Apr 08 22:28:15 2010 +0530
@@ -0,0 +1,24 @@
+import sys
+from datetime import datetime
+
+from django.core.management.base import NoArgsCommand
+
+from django.contrib.auth.models import User
+
+from workshop.reg.events import create_user, create_event
+
+def seed_db():
+ """ a method to seed the database with random data """
+
+ 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):
+
+ def handle_noargs(self, **options):
+ """ Just copied the code from seed_db.py """
+
+ seed_db()
--- a/reg/models.py Thu Apr 08 16:35:46 2010 +0530
+++ b/reg/models.py Thu Apr 08 22:28:15 2010 +0530
@@ -13,6 +13,8 @@
""" A model to hold extra information about the user.
"""
+ key = models.CharField(max_length=10, unique=True)
+
user = models.ForeignKey(User, unique=True)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
profession = models.CharField(max_length=1, choices=PROFESSION_CHOICES)
@@ -20,14 +22,18 @@
interests = models.CharField(max_length=100, verbose_name="Fields of Interest",
help_text="Ex: Python, Image Processing, Bio Informatics etc.")
+ activation_key = models.CharField(max_length=30, unique=True)
+
class Event(models.Model):
""" A model for the workshop information.
"""
+ key = models.CharField(max_length=10, unique=True)
+
title = models.CharField(max_length=100)
description = models.TextField()
start_date = models.DateField()
- end_date = models.DateField()
+ stop_date = models.DateField()
attendees = models.ManyToManyField(User, related_name="%(class)s_attendees")
organizers = models.ManyToManyField(User, related_name="%(class)s_organizers")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/reg/site/urls.py Thu Apr 08 22:28:15 2010 +0530
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import *
+
+from workshop.reg import views as reg_views
+
+urlpatterns = patterns('',
+ ('^$', reg_views.something),
+)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/reg/utils.py Thu Apr 08 22:28:15 2010 +0530
@@ -0,0 +1,6 @@
+import string
+import random
+
+def gen_key():
+ allowed_chars = string.digits+string.uppercase
+ return ''.join([random.choice(allowed_chars) for i in range(10)])
--- a/reg/views.py Thu Apr 08 16:35:46 2010 +0530
+++ b/reg/views.py Thu Apr 08 22:28:15 2010 +0530
@@ -1,1 +1,7 @@
-# Create your views here.
+from django.shortcuts import render_to_response
+
+def homepage(request):
+ """ List all the workshops and their status.
+ """
+
+ events = Event.objects.all()
--- a/settings.py Thu Apr 08 16:35:46 2010 +0530
+++ b/settings.py Thu Apr 08 22:28:15 2010 +0530
@@ -82,3 +82,5 @@
'workshop.reg',
#'workshop.quiz',
)
+
+AUTH_PROFILE_MODULE = 'reg.Profile'
--- a/urls.py Thu Apr 08 16:35:46 2010 +0530
+++ b/urls.py Thu Apr 08 22:28:15 2010 +0530
@@ -14,4 +14,8 @@
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
+
+ (r'^reg/', include('workshop.reg.site.urls')),
+ (r'^quiz/', include('workshop.quiz.site.urls')),
+ (r'^feedback/', include('workshop.feedback.site.urls')),
)