forked from thegreatape/raid-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getting the basics of registration working
- Loading branch information
Thomas Mayfield
committed
Jun 3, 2009
1 parent
9f5f8b3
commit f9bf5b5
Showing
12 changed files
with
177 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |