Skip to content

Commit d36e543

Browse files
author
Kishore kumar J
committed
Added Event Checkboxes to registration
1 parent 4657d35 commit d36e543

File tree

11 files changed

+174
-3
lines changed

11 files changed

+174
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.pyc
22
localsettings.py
3+
*.json
34

participantsprofile/forms.py

+16
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from models import UserProfile
44
from registration.models import RegistrationProfile
55
from models import College
6+
from events.models import Event
67

78
def get_colleges_list():
89
colleges_list = ()
@@ -11,13 +12,28 @@ def get_colleges_list():
1112
colleges_list += ((-1,'Add my College'),)
1213
return colleges_list
1314

15+
def get_events_list():
16+
events_list = ()
17+
for e in Event.objects.all():
18+
events_list += ((e.id, e.caption),)
19+
return events_list
20+
1421
class UserRegistrationForm(RegistrationForm):
1522
fullname = forms.CharField()
1623
phone_no = forms.IntegerField()
1724
college = forms.ChoiceField(choices=())
1825
add_your_college = forms.CharField(required=False, help_text='Enter your college name if not chosen above')
1926
rollno = forms.CharField()
27+
events = forms.MultipleChoiceField(choices=(), widget=forms.CheckboxSelectMultiple, required=False)
2028

2129
def __init__(self, *args, **kwargs):
2230
super(UserRegistrationForm, self).__init__(*args, **kwargs)
2331
self.fields['college'].choices = get_colleges_list()
32+
self.fields['events'].choices = get_events_list()
33+
34+
class ParticipantEventsForm(forms.Form):
35+
events = forms.MultipleChoiceField(choices=(), widget=forms.CheckboxSelectMultiple, required=False)
36+
37+
def __init__(self, *args, **kwargs):
38+
super(forms.Form, self).__init__(*args, **kwargs)
39+
self.fields['events'].choices = get_events_list()
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# encoding: utf-8
2+
import datetime
3+
from south.db import db
4+
from south.v2 import SchemaMigration
5+
from django.db import models
6+
7+
class Migration(SchemaMigration):
8+
9+
def forwards(self, orm):
10+
11+
# Adding M2M table for field events on 'Participant'
12+
db.create_table('participantsprofile_participant_events', (
13+
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
14+
('participant', models.ForeignKey(orm['participantsprofile.participant'], null=False)),
15+
('event', models.ForeignKey(orm['events.event'], null=False))
16+
))
17+
db.create_unique('participantsprofile_participant_events', ['participant_id', 'event_id'])
18+
19+
20+
def backwards(self, orm):
21+
22+
# Removing M2M table for field events on 'Participant'
23+
db.delete_table('participantsprofile_participant_events')
24+
25+
26+
models = {
27+
'auth.group': {
28+
'Meta': {'object_name': 'Group'},
29+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
30+
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
31+
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
32+
},
33+
'auth.permission': {
34+
'Meta': {'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
35+
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
36+
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
37+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
38+
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
39+
},
40+
'auth.user': {
41+
'Meta': {'object_name': 'User'},
42+
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
43+
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
44+
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
45+
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
46+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
47+
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'blank': 'True'}),
48+
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
49+
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'blank': 'True'}),
50+
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
51+
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
52+
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
53+
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
54+
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
55+
},
56+
'contenttypes.contenttype': {
57+
'Meta': {'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
58+
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
59+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
60+
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
61+
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
62+
},
63+
'events.event': {
64+
'Meta': {'object_name': 'Event'},
65+
'additional_info': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
66+
'caption': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
67+
'classic_name': ('django.db.models.fields.CharField', [], {'max_length': '30'}),
68+
'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
69+
'end_time': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
70+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
71+
'rules': ('django.db.models.fields.TextField', [], {}),
72+
'slug': ('django.db.models.fields.SlugField', [], {'db_index': 'True', 'max_length': '50', 'null': 'True', 'blank': 'True'}),
73+
'start_time': ('django.db.models.fields.TimeField', [], {'null': 'True', 'blank': 'True'}),
74+
'venue': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'})
75+
},
76+
'participantsprofile.college': {
77+
'Meta': {'object_name': 'College'},
78+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
79+
'name': ('django.db.models.fields.CharField', [], {'max_length': '150'})
80+
},
81+
'participantsprofile.participant': {
82+
'Meta': {'object_name': 'Participant'},
83+
'college': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'participants'", 'to': "orm['participantsprofile.College']"}),
84+
'email_id': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
85+
'events': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['events.Event']", 'symmetrical': 'False'}),
86+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
87+
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
88+
'phone_no': ('django.db.models.fields.CharField', [], {'max_length': '12'}),
89+
'roll_no': ('django.db.models.fields.CharField', [], {'max_length': '8'}),
90+
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['participantsprofile.UserProfile']", 'unique': 'True'})
91+
},
92+
'participantsprofile.team': {
93+
'Meta': {'object_name': 'Team'},
94+
'for_event': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'teams_registered'", 'to': "orm['events.Event']"}),
95+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
96+
'no_of_persons': ('django.db.models.fields.IntegerField', [], {}),
97+
'participants': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['participantsprofile.Participant']", 'symmetrical': 'False'})
98+
},
99+
'participantsprofile.userprofile': {
100+
'Meta': {'object_name': 'UserProfile'},
101+
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
102+
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'unique': 'True'}),
103+
'user_type': ('django.db.models.fields.CharField', [], {'max_length': '1'})
104+
}
105+
}
106+
107+
complete_apps = ['participantsprofile']

participantsprofile/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Participant(models.Model):
2424

2525
college = models.ForeignKey(College, related_name='participants')
2626
roll_no = models.CharField(max_length=8)
27-
27+
events = models.ManyToManyField(Event)
2828
class Meta:
2929
ordering = ('college',)
3030
def __unicode__(self):

participantsprofile/regbackend.py

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def user_created(sender, user, request, **kwargs):
2121
participant.college = College.objects.get(pk=form.data["college"])
2222
participant.roll_no = form.data['rollno']
2323
participant.save()
24+
for e in form.data.getlist('events'):
25+
participant.events.add(e)
26+
print e
2427

2528
from registration.signals import user_registered
2629
user_registered.connect(user_created)

participantsprofile/views.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from django.shortcuts import render_to_response
2+
from django.http import HttpResponseRedirect
3+
from django.template import RequestContext
4+
from django.contrib.auth.decorators import login_required
5+
6+
from forms import ParticipantEventsForm
7+
8+
@login_required
9+
def participant_events(request):
10+
if request.method == 'POST':
11+
participant = request.user.get_profile().participant_set.all()[0]
12+
form = ParticipantEventsForm(request.POST)
13+
participant.events = form.data.getlist('events')
14+
for e in form.data.getlist('events'):
15+
if e not in [e.id for e in participant.events.all()]:
16+
participant.events.add(e)
17+
return HttpResponseRedirect('./')
18+
else:
19+
participant = request.user.get_profile().participant_set.all()[0]
20+
events = [ e.id for e in participant.events.all()]
21+
form = ParticipantEventsForm(data = {'events':events})
22+
return render_to_response('participantsprofile/participant_events.html', {'form':form}, context_instance=RequestContext(request), mimetype='text/html')

settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
LOGOUT_URL = '/account/signout'
102102
LOGIN_REDIRECT_URL = '/'
103103
REGISTRATION_OPEN = True
104-
AUTH_PROFILE_MODULE = 'participantsprofile.profile'
104+
AUTH_PROFILE_MODULE = 'participantsprofile.UserProfile'
105105

106106
DEFAULT_FROM_EMAIL = '[email protected]'
107107

static/css/base.css

+6
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ p {
9595
padding-top: 30px;
9696
vertical-align: center;
9797
}
98+
.sign_up_table ul {
99+
list-style: none;
100+
}
101+
.participant_events_form ul {
102+
list-style: none;
103+
}
98104
.accordion {
99105
font-size: medium!important;
100106
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "richbase.html" %}
2+
{% block title %}Event Participation{% endblock %}
3+
{% block head %}
4+
{% endblock %}
5+
{% block content %}
6+
<h2>Event Participation</h2>
7+
<h3>Check the Events that you wish to participate in:</h3>
8+
<form action="" class="participant_events_form" method="POST">
9+
{% csrf_token %}
10+
{{ form.as_table }}
11+
<input type="submit" name="bsignup" value="Update">
12+
</form>
13+
14+
{% endblock %}
15+

templates/registration/registration_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h1>Join</h1>
3232
slcollege.onchange();
3333
</script>
3434
</table>
35-
<p><input type="submit" name="bsignup'" value="{% trans "Sign up" %}"> </p>
35+
<p><input type="submit" name="bsignup" value="Sign up"> </p>
3636
</fieldset>
3737
</form>
3838
{% endblock %}

urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
url(r'^account/activate/(?P<activation_key>\w+)/$', 'registration.views.activate', { 'backend': 'registration.backends.default.DefaultBackend' }, name='registration_activate'),
2525
url(r'^account/activate/complete/$', direct_to_template, { 'template': 'registration/activation_complete.html' }, name='registration_activation_complete'),
2626
url(r'^account/signup/$', 'registration.views.register', {'backend':'registration.backends.default.DefaultBackend', 'form_class':UserRegistrationForm }, name='registration_register'),
27+
url(r'^account/profile/event/$', 'participantsprofile.views.participant_events', name='participant_events'),
2728
url(r'^register/closed/$', direct_to_template, { 'template': 'registration/registration_closed.html' }, name='registration_disallowed'),
2829

2930
(r'^account/', include('django_authopenid.urls')),

0 commit comments

Comments
 (0)