Skip to content

Commit

Permalink
getting the basics of registration working
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Mayfield committed Jun 3, 2009
1 parent 9f5f8b3 commit f9bf5b5
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 39 deletions.
5 changes: 4 additions & 1 deletion raid_calendar/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from raid_scheduler.raid_calendar.models import Raid
from django.contrib import admin

admin.site.register(Raid)
class RaidAdmin(admin.ModelAdmin):
fields = ('title', 'date', 'roll_date', 'raid_leader')

admin.site.register(Raid, RaidAdmin)
6 changes: 6 additions & 0 deletions raid_calendar/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django import forms

class RegistrationForm(forms.Form):
role = forms.ChoiceField(choices=(('dps', 'DPS'), ('healer', "Healer"), ('tank', 'Tank')),
widget=forms.RadioSelect)
standby = forms.BooleanField(False)
19 changes: 16 additions & 3 deletions raid_calendar/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
from django.contrib.auth.models import User
from django.db import models

class Registration(models.Model):
player = models.ForeignKey(User)
role = models.CharField(max_length=256)
number = models.IntegerField(blank=True, null=True)

def __unicode__(self):
return self.player.username

class Raid(models.Model):
title = models.CharField(max_length=256)
date = models.DateTimeField('date/time of the raid')
registered = models.ManyToManyField(User, related_name="registered_raiders")
guaranteed_spots = models.ManyToManyField(User, related_name="guaranteed_spots")
standby_spots = models.ManyToManyField(User, related_name="standby_spots")
roll_date = models.DateTimeField('time when spots will be automatically rolled for')
registered = models.ManyToManyField(Registration, related_name="registered_raiders", blank=True)
raid_leader = models.ForeignKey(User)

def __unicode__(self):
return self.title

def url(self):
return self.id

def is_registered(self, player):
return len(self.registered.filter(player=player))
31 changes: 13 additions & 18 deletions raid_calendar/templates/home/calendar.djhtml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Raid Calendar</title>
<style type="text/css">
body {font-family: Arial,Helvetica,sans-serif; background: #eee;}
.cal-wrap { width: 700px;}
.cal-cell { width: 90px; height: 90px; float: left; margin: 2px; padding: 2px; border: 1px solid #ddd; background:#fff}
</style>
</head>
<body>
<h1>{{date}}</h1>
<div class="cal-wrap">
{% for i in days %}
<span class="cal-cell">{{i|default:""}}</span>
{% extends "home/wrap.djhtml" %}
{% block content %}
<h1>{{date}}</h1>
<div class="cal-wrap">
{% for date in days %}
<span class="cal-cell">
{{date.day|default:""}}<br/>
{% if date.raids %}
{% for raid in date.raids %}<a href="{{raid.url}}">{{ raid.title }}</a>{% endfor %}<br/>
{% endif %}
</span>
{% endfor %}
</div>
</body>
</html>
{% endblock %}

9 changes: 9 additions & 0 deletions raid_calendar/templates/home/login.djhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "home/wrap.djhtml" %}
{% block content %}
<h1>Login</h1>
<form action="login" method="POST">
{{form.as_p}}
<input type="submit" value="Login"/>
</form>
{% endblock %}

9 changes: 9 additions & 0 deletions raid_calendar/templates/home/signup.djhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "home/wrap.djhtml" %}
{% block content %}
<h1>Create New User</h1>
<form action="signup" method="POST">
{{form.as_p}}
<input type="submit" value="Signup"/>
</form>
{% endblock %}

27 changes: 27 additions & 0 deletions raid_calendar/templates/home/wrap.djhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Raid Calendar</title>
<style type="text/css">
body {font-family: Arial,Helvetica,sans-serif; background: #fff;}
.content-wrap {margin-left: 200px; padding: 20px; background: #eee; height: 600px; width: 50%;}
.user-util {float:right}
.cal-wrap { width: 700px; position:relative;}
.cal-cell { width: 90px; height: 90px; float: left; margin: 2px; padding: 2px; border: 1px solid #ddd; background:#fff}
</style>
</head>
<body>
<div class="content-wrap">
<div class="user-util">
{% if user.is_authenticated %}
Welcome Back, {{ user.username }}
{% else %}
<a href="login">Login</a> | <a href="signup">Sign Up</a>
{% endif %}
</div>
{% block content %}
{% endblock %}
</div>
</div>
</body>
</html>
22 changes: 22 additions & 0 deletions raid_calendar/templates/raid/view.djhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "home/wrap.djhtml" %}
{% block content %}
<h1>{{raid.title}}</h1>
<div>Time: {{raid.date}} Server Time</div>
<div>Spots for this raid will be automatically rolled for on: </div>
<h2>Currently Registered</h2>
<table border="1"><tr><th>Player</th><th>Role</th></tr>
{% for registration in raid.registered.all %}
<tr>
<td>{{registration.player.username}}</td>
<td>{{registration.role}}</td>
</tr>{% endfor %}
</table>
{% if not is_registered %}
<h2>Sign Up</h2>
<form action="" method="POST">
{{ registration_form.as_p }}
<input type="Submit" value="Register"/>
</form>
{% endif %}
{% endblock %}

8 changes: 8 additions & 0 deletions raid_calendar/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('raid_scheduler.raid_calendar.views',
(r'^$', 'home'),
(r'^signup$', 'create_user'),
(r'^logout$', 'logout_user' ),
(r'^(?P<raid_id>\d+)$', 'view_raid')
)
62 changes: 55 additions & 7 deletions raid_calendar/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
from django.http import HttpResponse
from django.shortcuts import render_to_response
from calendar import Calendar
from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout

from calendar import Calendar
from forms import RegistrationForm
from datetime import date, datetime
from raid_calendar.models import Raid
from raid_calendar.models import Raid, Registration

def home(request):
today = date.today()
raids = Raid.objects.filter(date__gte=datetime(today.year, today.month, 1))
days = sum(Calendar().monthdayscalendar(today.year, today.month), [])
days = [{'day': x} for x in sum(Calendar().monthdayscalendar(today.year, today.month), [])]

for raid in raids:
days[days.index(raid.date.day)] = "%i - %s" % (raid.date.day, raid.title)
event = days[days.index({'day': raid.date.day})]
if "raids" in event:
event["raids"].append(raid)
else:
event["raids"] = [raid]

context = {'date': today.strftime('%B %Y'),
'days' : days}
return render_to_response('home/calendar.djhtml', context)
return render_to_response('home/calendar.djhtml', context, context_instance=RequestContext(request))

@login_required
def view_raid(request, raid_id):
raid = get_object_or_404(Raid, id=raid_id)
if request.method == 'POST':
form = RegistrationForm(request.POST)
print request.POST
if form.is_valid():
registration = Registration(player=request.user,
role=form.cleaned_data['role'])
registration.save()
raid.registered.add(registration)
raid.save()
else:
form = RegistrationForm()
return render_to_response('raid/view.djhtml',
{'raid': raid,
'registration_form': form,
'is_registered': raid.is_registered(request.user)},
context_instance=RequestContext(request))


def create_user(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
User.objects.create_user(form.cleaned_data['username'], '', form.cleaned_data['password1'])
return HttpResponseRedirect('/')
else:
return render_to_response('home/signup.djhtml', {'form': form})
else:
return render_to_response('home/signup.djhtml', {'form': UserCreationForm()}, context_instance=RequestContext(request))

def logout_user(request):
logout(request)
return HttpResponseRedirect('/')
5 changes: 4 additions & 1 deletion settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = '/Users/thomasmayfield/Code/raid_scheduler.db' # Or path to database file if using sqlite3.
DATABASE_NAME = '/Users/thomasmayfield/Code/db_raid_scheduler.db' # Or path to database file if using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
Expand Down Expand Up @@ -78,5 +78,8 @@
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.admindocs',
'raid_scheduler.raid_calendar'
)

LOGIN_URL = 'login'
13 changes: 4 additions & 9 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
(r'^raid_scheduler/', 'raid_scheduler.raid_calendar.views.home'),

# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'', include('raid_scheduler.raid_calendar.urls')),
(r'^login$', 'django.contrib.auth.views.login', {'template_name': 'home/login.djhtml'} ),
(r'^logout$', 'django.contrib.auth.views.logout' ),
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/(.*)', admin.site.root),
)

0 comments on commit f9bf5b5

Please sign in to comment.