diff --git a/core/models.py b/core/models.py index 71a8362..b096caa 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,4 @@ from django.db import models # Create your models here. + diff --git a/core/tests.py b/core/tests.py index 2247054..5d6c0da 100644 --- a/core/tests.py +++ b/core/tests.py @@ -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. diff --git a/core/views.py b/core/views.py index e5cd584..2fc514d 100644 --- a/core/views.py +++ b/core/views.py @@ -8,5 +8,3 @@ def homepage(request): context = RequestContext(request) return render_to_response('homepage.html', context) - - diff --git a/database.db b/database.db index d413aec..41642ab 100644 Binary files a/database.db and b/database.db differ diff --git a/settings.py b/settings.py index 3fb6d08..b47243f 100644 --- a/settings.py +++ b/settings.py @@ -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', 'your_email@domain.com'), ) @@ -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 @@ -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', ) diff --git a/subscription/__init__.py b/subscription/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/subscription/admin.py b/subscription/admin.py new file mode 100644 index 0000000..93f93a0 --- /dev/null +++ b/subscription/admin.py @@ -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) diff --git a/subscription/forms.py b/subscription/forms.py new file mode 100644 index 0000000..60b5aed --- /dev/null +++ b/subscription/forms.py @@ -0,0 +1,7 @@ +from django import forms +from subscription.models import Subscription + +class SubscriptionForm(forms.ModelForm): + class Meta: + model = Subscription + exclude= ("created_at",) diff --git a/subscription/models.py b/subscription/models.py new file mode 100644 index 0000000..ec8116f --- /dev/null +++ b/subscription/models.py @@ -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" diff --git a/subscription/tests.py b/subscription/tests.py new file mode 100644 index 0000000..2247054 --- /dev/null +++ b/subscription/tests.py @@ -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 +"""} + diff --git a/subscription/urls.py b/subscription/urls.py new file mode 100644 index 0000000..e4e53b4 --- /dev/null +++ b/subscription/urls.py @@ -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'), +) diff --git a/subscription/views.py b/subscription/views.py new file mode 100644 index 0000000..a3c9884 --- /dev/null +++ b/subscription/views.py @@ -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 = "not-reply@eventex.com.br", + 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) + + + + + + + + diff --git a/templates/homepage.html b/templates/homepage.html index a1211ce..86ea4b8 100644 --- a/templates/homepage.html +++ b/templates/homepage.html @@ -1,63 +1,14 @@ - - - - - -EventeX - - - - - - -
- - - - -
-
-
-

Bem vindo ao EventeX!

-
-

O evento mais sensacional do ano depois do DevInRio!

-

Você não pode perder esta oportunidade

-
    -
  • Abertura das inscrições em 12/02/2011 -
-

Para dúvidas ou maiores informações entre em contato @ eventex@eventex.com.br -

-
-
-
 
-
- - - - - +{% extends 'master.html' %} +{% block title %}Página inicial{% endblock title %} +{% block content %} +

Bem vindo ao EventeX!

+
+

O evento mais sensacional do ano depois do DevInRio!

+

Você não pode perder esta oportunidade

+ +
+{% endblock content %} diff --git a/templates/master.html b/templates/master.html new file mode 100644 index 0000000..2e9b4ed --- /dev/null +++ b/templates/master.html @@ -0,0 +1,56 @@ + + + + + +Eventex - {% block title %}{% endblock title %} + + + + + + +
+ + + + +
+
+
+ {% block content %} + {% endblock content %} +
+
+
 
+
+ + + + + diff --git a/templates/subscription/new.html b/templates/subscription/new.html new file mode 100644 index 0000000..5b33d80 --- /dev/null +++ b/templates/subscription/new.html @@ -0,0 +1,12 @@ +{% extends 'master.html' %} +{% block title %}Formulário de inscrição{% endblock title %} +{% block content %} +

Formulário de Inscrição

+
+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+{% endblock content %} diff --git a/templates/subscription/success.html b/templates/subscription/success.html new file mode 100644 index 0000000..be8b553 --- /dev/null +++ b/templates/subscription/success.html @@ -0,0 +1,15 @@ +{% extends 'master.html' %} +{% block title %}Inscrição efetuada com sucesso{% endblock title %} +{% block content %} +

Inscrição efetuada com sucesso

+
+

Parabéns {{ subscription.name }}

+

Sua inscrição foi processada corretamente em {{subscription.created_at|date:"d/M/Y" }}.

+

Em breve alguém entrará em contato pelo + {% if subscription.phone %} + telefone {{subscription.phone }} + {% else %} + e-mail {{ subscription.email }} + {% endif %}

+
+{% endblock content %} diff --git a/urls.py b/urls.py index b0af46c..b8b9abe 100644 --- a/urls.py +++ b/urls.py @@ -3,12 +3,13 @@ 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.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT }) + (r'^media/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT }), + (r'^inscricao/', include('subscription.urls', namespace='subscription')), # Example: # (r'^eventex/', include('eventex.foo.urls')), @@ -16,5 +17,5 @@ # (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)), )