Commit cf8ef300 authored by chris's avatar chris

Main django application

parent 1061e5cc
from django import forms
from models import Poll, Choice, Bulletin, Vote
class PollForm(forms.ModelForm):
description = forms.CharField(widget=forms.Textarea)
class Meta:
model = Poll
fields = ('title','description')
class ChoiceForm(forms.ModelForm):
choice = forms.CharField(widget=forms.TextInput(attrs={'class':'hasdatepicker','size':'10',}))
details = forms.CharField(required=False,widget=forms.TextInput(attrs={'size':'32',}))
class Meta:
model = Choice
exclude = ('poll','votecount')
class BulletinForm(forms.ModelForm):
class Meta:
model = Bulletin
class VoteForm(forms.ModelForm):
comment = forms.CharField(required=False,widget=forms.TextInput(attrs={'class':'comment'}))
choice = forms.CharField()
voter = forms.CharField(required=False)
class Meta:
model = Vote
fields = ('choice','voice','comment')
from django.db import models
import os
from binascii import hexlify
def _createId():
# Generate a 4 caracters id
return hexlify(os.urandom(2))
class Poll(models.Model):
# Override django id AutoField with randomly generatyed hash
id = models.CharField(primary_key=True,unique=True,max_length=8,default=_createId)
title = models.CharField('Question',max_length=50)
pub_date = models.DateField('date published',auto_now_add=True)
upd_date = models.DateField('date updated',auto_now=True)
author = models.CharField(max_length=20)
description = models.CharField(max_length=200)
#public = models.BooleanField()
def __unicode__(self):
return self.title
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=20)
details = models.CharField(max_length=30,blank=True)
votecount = models.IntegerField(default=0,blank=True)
def __unicode__(self):
return self.choice
class Bulletin(models.Model):
poll = models.ForeignKey(Poll,editable=False)
voter = models.CharField("",max_length=20)
def __unicode__(self):
return self.voter
class Vote(models.Model):
choice = models.ForeignKey(Choice)
bulletin = models.ForeignKey(Bulletin)
voice = models.BooleanField(blank=True)
comment = models.CharField(max_length=30,blank=True)
def __unicode__(self):
return self.voice
"""
# First, define the Manager subclass.
class VoteBuletin(models.Manager):
def get_query_set(self):
return super(VoteBuletin, self).get_query_set().filter(author='Roald Dahl')
"""
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}
This diff is collapsed.
from django.db import models
# Create your models here.
"""
This file demonstrates two different styles of tests (one doctest and one
unittest). These will both pass when you run "manage.py test".
Replace these with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)
__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
>>> 1 + 1 == 2
True
"""}
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/user/login/")
else:
form = UserCreationForm()
return render_to_response("registration/register.html", {
'form': form,
}, context_instance=RequestContext(request))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment