Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
2º Sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmveloso committed Feb 19, 2011
1 parent 2384a41 commit 2003a33
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 73 deletions.
1 change: 1 addition & 0 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.db import models

# Create your models here.

10 changes: 9 additions & 1 deletion core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ def test_basic_addition(self):
Tests that 1 + 1 always equals 2.
"""
self.failUnlessEqual(1 + 1, 2)

def HomepageUrlTest(TestCase):
"""
Testa se a pagina inicial e carregada ao acessar a
raiz do site.
"""
response = self.client.get('/')
self.assertEquals(200, response.status_code)
self.assertTemplateUsed(response, 'index.html')

__test__ = {"doctest": """
Another way to test that 1 + 1 is equal to 2.
Expand Down
2 changes: 0 additions & 2 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ def homepage(request):
context = RequestContext(request)
return render_to_response('homepage.html', context)



Binary file modified database.db
Binary file not shown.
14 changes: 11 additions & 3 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

PROJECT_DIR = os.path.dirname(__file__)

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = ''
EMAIL_PORT = 25


ADMINS = (
# ('Your Name', '[email protected]'),
)
Expand All @@ -31,11 +38,11 @@
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
TIME_ZONE = 'America/Sao_Paulo'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'pt-br'

SITE_ID = 1

Expand Down Expand Up @@ -95,8 +102,9 @@
'django.contrib.sites',
'django.contrib.messages',
'core',
'subscription',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
Empty file added subscription/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions subscription/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import datetime
from django.contrib import admin
from subscription.models import Subscription

class SubscriptionAdmin(admin.ModelAdmin):
list_display = ('name', 'email', 'phone', 'created_at', 'subscribed_today')
date_hierarchy = 'created_at'
search_fields = ('name', 'email', 'phone', 'cpf', 'created_at')
list_filter = ['created_at']

def subscribed_today(self, obj):
return obj.created_at.date() == datetime.date.today()

subscribed_today.short_description = 'Inscrito hoje?'
subscribed_today.boolean = True


admin.site.register(Subscription, SubscriptionAdmin)
7 changes: 7 additions & 0 deletions subscription/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django import forms
from subscription.models import Subscription

class SubscriptionForm(forms.ModelForm):
class Meta:
model = Subscription
exclude= ("created_at",)
20 changes: 20 additions & 0 deletions subscription/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#coding: utf-8

from django.db import models

# Create your models here.

class Subscription(models.Model):
name = models.CharField('Nome', max_length=100)
cpf = models.CharField('CPF', max_length=11, unique=True)
email = models.EmailField('E-mail', unique=True)
phone = models.CharField('Telefone', max_length=20, blank=True)
created_at = models.DateTimeField('Data inscrição', auto_now_add=True)

def __unicode__(self):
return self.name

class Meta:
ordering = ["created_at"]
verbose_name = u"Inscrição"
verbose_name_plural = u"Inscrições"
23 changes: 23 additions & 0 deletions subscription/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
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
"""}

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

urlpatterns = patterns('subscription.views',
url(r'^$', 'subscribe', name='subscribe'),
url(r'^(\d+)/sucesso/$', 'success', name='success'),
)
52 changes: 52 additions & 0 deletions subscription/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding: utf-8
# Create your views here.

from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from subscription.models import Subscription
from subscription.forms import SubscriptionForm
from django.core.urlresolvers import reverse
from django.core.mail import send_mail

def subscribe(request):
if request.method == "POST":
return create(request)
else:
return new(request)

def new(request):
form = SubscriptionForm()
context = RequestContext(request, {'form':form})
return render_to_response('subscription/new.html', context)

def create(request):
form = SubscriptionForm(request.POST)
if not form.is_valid():
context = RequestContext(request, {'form':form})
return render_to_response('subscription/new.html', context)

subscription = form.save()
send_subscription_confirmation(subscription)
return HttpResponseRedirect(reverse('subscription:success', args=[subscription.pk]))

def send_subscription_confirmation(subscription):
send_mail(
subject = u'EventeX - Confirmação de inscrição',
message = u'{0}, obrigado por se inscrever no EventeX!'.format(subscription.name),
from_email = "[email protected]",
recipient_list = [subscription.email],
)

def success(request, pk):
subscription = get_object_or_404(Subscription, pk=pk)
context = RequestContext(request, {'subscription':subscription})
return render_to_response('subscription/success.html', context)








77 changes: 14 additions & 63 deletions templates/homepage.html
Original file line number Diff line number Diff line change
@@ -1,63 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
Name : Milestone
Description: A two-column, fixed-width design for 1024x768 screen resolutions.
Version : 1.0
Released : 20100309
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>EventeX</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="{{ MEDIA_URL }}style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="logo">
<h1><a href="#">EventeX</a></h1>
<p><em>Welcome to the Django</a></em></p>
</div>
<hr />
<!-- end #logo -->
<div id="header">
<div id="menu">
<ul>
<li class="current_page_item"><a href="#" class="first">Home</a></li>
<li><a href="#">Inscrições</a></li>
<li><a href="#">Contato</a></li>
<li><a href="#">Admin</a></li>
</ul>
</div>
<!-- end #menu -->
</div>
<!-- end #header -->
<!-- end #header-wrapper -->
<div id="page">
<div id="content">
<div class="post">
<h2 class="title"><a href="#">Bem vindo ao EventeX!</a></h2>
<div class="entry">
<p>O evento mais sensacional do ano depois do DevInRio!</p>
<p>Você não pode perder esta oportunidade</p>
<ul>
<li>Abertura das inscrições em <strong>12/02/2011</strong>
</ul>
<p>Para dúvidas ou maiores informações entre em contato @ <a href="#">[email protected]</a>
</div>
</div>
</div><!-- end #content -->
<div style="clear: both;">&nbsp;</div>
</div>
<!-- end #page -->
<div id="footer">
<p>Copyleft (c) 2011 Gustavo Veloso. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p><center><a href="http://www.djangoproject.com/" target="_blank"><img src="http://media.djangoproject.com/img/badges/djangomade124x25.gif" border="0" alt="Made with Django." title="Made with Django." /></a></center>
</div>
<!-- end #footer -->
</body>
</html>
{% extends 'master.html' %}
{% block title %}Página inicial{% endblock title %}
{% block content %}
<h2 class="title"><a href="#">Bem vindo ao EventeX!</a></h2>
<div class="entry">
<p>O evento mais sensacional do ano depois do DevInRio!</p>
<p>Você não pode perder esta oportunidade</p>
<ul>
<li><a href="{% url subscription:subscribe %}"><strong>Inscreva-se já</strong></a></li>
<li>Para dúvidas ou maiores informações contate-nos pelo <a href="mailto:[email protected]">
[email protected]</a>
</ul>
</div>
{% endblock content %}
56 changes: 56 additions & 0 deletions templates/master.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
Name : Milestone
Description: A two-column, fixed-width design for 1024x768 screen resolutions.
Version : 1.0
Released : 20100309
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Eventex - {% block title %}{% endblock title %}</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="{{ MEDIA_URL }}style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="logo">
<h1><a href="#">EventeX</a></h1>
<p><em>Welcome to the Django</a></em></p>
</div>
<hr />
<!-- end #logo -->
<div id="header">
<div id="menu">
<ul>
<li><a href="#" class="first">Home</a></li>
<li><a href="{% url subscription:subscribe %}">Inscrições</a></li>
<li><a href="#">Contato</a></li>
<li><a href="#">Admin</a></li>
</ul>
</div>
<!-- end #menu -->
</div>
<!-- end #header -->
<!-- end #header-wrapper -->
<div id="page">
<div id="content">
<div class="post">
{% block content %}
{% endblock content %}
</div>
</div><!-- end #content -->
<div style="clear: both;">&nbsp;</div>
</div>
<!-- end #page -->
<div id="footer">
<p>Copyleft (c) 2011 Gustavo Veloso. Design by <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p><center><a href="http://www.djangoproject.com/" target="_blank"><img src="http://media.djangoproject.com/img/badges/djangomade124x25.gif" border="0" alt="Made with Django." title="Made with Django." /></a></center>
</div>
<!-- end #footer -->
</body>
</html>
12 changes: 12 additions & 0 deletions templates/subscription/new.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'master.html' %}
{% block title %}Formulário de inscrição{% endblock title %}
{% block content %}
<h2 class="title"><a href="#">Formulário de Inscrição</a></h2>
<div class="entry">
<form action="." method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Enviar">
</form>
</div>
{% endblock content %}
15 changes: 15 additions & 0 deletions templates/subscription/success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'master.html' %}
{% block title %}Inscrição efetuada com sucesso{% endblock title %}
{% block content %}
<h2 class="title"><a href="#">Inscrição efetuada com sucesso</a></h2>
<div class="entry">
<p>Parabéns {{ subscription.name }}</p>
<p>Sua inscrição foi processada corretamente em {{subscription.created_at|date:"d/M/Y" }}.</p>
<p>Em breve alguém entrará em contato pelo
{% if subscription.phone %}
telefone {{subscription.phone }}
{% else %}
e-mail {{ subscription.email }}
{% endif %}</p>
</div>
{% endblock content %}
9 changes: 5 additions & 4 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
from django.conf import settings

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

urlpatterns = patterns('',
(r'^$', homepage),
(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT })
(r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT }),
(r'^inscricao/', include('subscription.urls', namespace='subscription')),
# Example:
# (r'^eventex/', include('eventex.foo.urls')),

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

# Uncomment the next line to enable the admin:
# (r'^admin/', include(admin.site.urls)),
(r'^admin/', include(admin.site.urls)),
)

0 comments on commit 2003a33

Please sign in to comment.