Skip to content

Commit 8e0c794

Browse files
committed
Add forminput project
1 parent 60b538b commit 8e0c794

File tree

12 files changed

+150
-6
lines changed

12 files changed

+150
-6
lines changed

dgentledjango/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
# Don't forget to use absolute paths, not relative paths.
110110
)
111111

112+
ACCOUTN_ACTIVATION_DAYS = 7
112113
INSTALLED_APPS = (
113114
'django.contrib.auth',
114115
'django.contrib.contenttypes',
@@ -117,6 +118,10 @@
117118
'django.contrib.messages',
118119
'django.contrib.staticfiles',
119120
'intro',
121+
'forminput',
122+
'registration',
123+
'registration_defaults',
124+
'userreg',
120125
# Uncomment the next line to enable the admin:
121126
'django.contrib.admin',
122127
# Uncomment the next line to enable admin documentation:

dgentledjango/urls.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
admin.autodiscover()
66

77
urlpatterns = patterns('',
8-
# Examples:
9-
# url(r'^$', 'dgentledjango.views.home', name='home'),
10-
# url(r'^dgentledjango/', include('dgentledjango.foo.urls')),
8+
## Introduction
119
url(r'^intro/$', 'intro.views.index'),
1210
url(r'^teacher/(?P<teacher_id>\d+)/$', 'intro.views.teacherdetail'),
1311
url(r'^student/(?P<student_id>\d+)/$', 'intro.views.studentdetail'),
1412

15-
# Uncomment the admin/doc line below to enable admin documentation:
16-
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
13+
## Form input
14+
url(r'^forminput/$', 'forminput.views.index'),
15+
url(r'^band/(?P<band_id>\d+)/$', 'forminput.views.banddetail'),
16+
url(r'^band/$', 'forminput.views.bandindex'),
1717

18-
# Uncomment the next line to enable the admin:
18+
19+
## User Registration
20+
url(r'^accounts/', include('registration.backends.default.urls')),
21+
22+
## Administration
1923
url(r'^admin/', include(admin.site.urls)),
2024
)

forminput/__init__.py

Whitespace-only changes.

forminput/__init__.pyc

144 Bytes
Binary file not shown.

forminput/forms.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django import forms
2+
from forminput.models import Band
3+
4+
class BandForm(forms.ModelForm):
5+
class Meta:
6+
model = Band
7+

forminput/forms.pyc

667 Bytes
Binary file not shown.

forminput/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.db import models
2+
3+
# Create your models here.
4+
5+
class Band(models.Model):
6+
7+
name = models.CharField(max_length=64)
8+

forminput/models.pyc

474 Bytes
Binary file not shown.

forminput/tests.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
This file demonstrates writing tests using the unittest module. These will pass
3+
when you run "manage.py test".
4+
5+
Replace this with more appropriate tests for your application.
6+
"""
7+
8+
from django.test import TestCase
9+
10+
11+
class SimpleTest(TestCase):
12+
def test_basic_addition(self):
13+
"""
14+
Tests that 1 + 1 always equals 2.
15+
"""
16+
self.assertEqual(1 + 1, 2)

forminput/views.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Create your views here.
2+
3+
from django.shortcuts import render_to_response
4+
from django.http import HttpResponse, HttpResponseRedirect
5+
from django.template import Context, loader, RequestContext
6+
from intro.models import Teacher, Student
7+
from forminput.models import Band
8+
from forminput.forms import BandForm
9+
10+
def index(request):
11+
teacher_list = Teacher.objects.all()
12+
student_list = Student.objects.all()
13+
band_list = Band.objects.all()
14+
return render_to_response('forminput/index.html',
15+
{'teacher_list': teacher_list,
16+
'student_list': student_list,
17+
'band_list': band_list},
18+
context_instance = RequestContext(request))
19+
20+
def banddetail(request, band_id):
21+
try:
22+
band = Band.objects.get(pk=band_id)
23+
except Band.DoesNotExist:
24+
raise Http404
25+
26+
return render_to_response('forminput/band_detail.html',
27+
{'band': band})
28+
29+
def bandindex(request):
30+
if request.method == "POST":
31+
form = BandForm(request.POST)
32+
try:
33+
if form.is_valid():
34+
form.save()
35+
return HttpResponseRedirect('/forminput/')
36+
else:
37+
print "well..."
38+
print request.POST
39+
except Exception, e:
40+
print e

0 commit comments

Comments
 (0)