+def initialize():
+ from eventos.models import Evento
+ from datetime import datetime
+
+ emsl = Evento()
+ emsl.nome = 'Encontro Mineiro de Software Livre'
+ emsl.nome_local = 'UFLA'
+ emsl.nome_contato = 'Monserrat'
+ emsl.data_inicio = datetime(2007, 10, 18)
+ emsl.data_final = datetime(2007, 10, 20)
+ emsl.telefone = ''
+ emsl.rua = ''
+ emsl.numero = ''
+ emsl.cidade = 'Lavras'
+ emsl.uf = 'MG'
+ emsl.save()
class Secao(models.Model):
nome = models.CharField(maxlength=100)
+ index = models.BooleanField(help_text='Se marcado aparecerá na index, '
+ 'acima das notícias. Caso contrário, aparecerá no menu principal')
corpo = models.TextField()
class Meta:
verbose_name_plural = 'seções'
class Admin:
- pass
+ js = ('/site_media/tiny_mce/tiny_mce.js',
+ '/site_media/js/textarea-noticias.js',)
def __str__(self):
return self.nome
-# -*- coding: utf-8; -*-
+# -*- coding: utf8; -*-
"""
Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
Boston, MA 02111-1307, USA.
"""
from django.db import models
+from django.contrib.localflavor.br.br_states import STATE_CHOICES as _states
+# bad hack!
+STATE_CHOICES = [(x, unicode(y).encode('utf8')) for x, y in _states]
+del _states
class Evento(models.Model):
nome = models.CharField(maxlength=100)
nome_contato = models.CharField('Nome do contato', maxlength=100)
telefone = models.CharField(maxlength=100)
cidade = models.CharField(maxlength=100)
- uf = models.CharField(maxlength=100) # TODO: should became a combobox
+ uf = models.CharField(maxlength=2, choices=STATE_CHOICES)
rua = models.CharField(maxlength=100)
numero = models.CharField('Número', maxlength=10)
info_adicional = models.TextField()
)
def __str__(self):
- return self.name
+ return self.nome
class AreaDeInteresse(models.Model):
nome = models.CharField(maxlength=100)
email = models.CharField(maxlength=100)
- telefone_residencial = models.CharField(maxlength=11)
- telefone_celular = models.CharField(maxlength=11)
- telefone_comercial = models.CharField(maxlength=11)
+ telefone_residencial = models.CharField(maxlength=11, blank=True)
+ telefone_celular = models.CharField(maxlength=11, blank=True)
+ telefone_comercial = models.CharField(maxlength=11, blank=True)
rua = models.CharField(maxlength=100)
numero = models.CharField(maxlength=10)
+# -*- coding: utf8; -*-
"""
Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
Boston, MA 02111-1307, USA.
"""
from django import newforms as forms
-from django.newforms.widgets import Textarea
+from django.newforms.widgets import Textarea, PasswordInput
+from eventmanager.eventos.models import \
+ AreaDeInteresse, CategoriaPalestra, STATE_CHOICES
+
+MKCHOICES = lambda K:[(x.id, str(x)) for x in K.objects.all()]
class InscreverPalestra(forms.Form):
- pass
+ def __init__(self, *args, **kwargs):
+ super(InscreverPalestra, self).__init__(*args, **kwargs)
+
+ newchoices = MKCHOICES(CategoriaPalestra)
+ self.fields['categoria'].choices = newchoices
+
+ titulo = forms.CharField(max_length=100)
+ tema = forms.CharField(max_length=100)
+ categoria = forms.ChoiceField()
+ descricao_curta = forms.CharField(widget=Textarea(),
+ label='Descrição curta')
+ descricao_longa = forms.CharField(widget=Textarea(),
+ label='Descrição longa')
+
class CadastroPalestrante(forms.Form):
- nome = forms.CharField(max_length=100)
+ def __init__(self, *args, **kwargs):
+ super(CadastroPalestrante, self).__init__(*args, **kwargs)
+
+ newchoices = MKCHOICES(AreaDeInteresse)
+ self.fields['area_interesse'].choices = newchoices
+
+ nome_completo = forms.CharField(max_length=100)
+ nome_usuario = forms.CharField(max_length=100)
+ senha = forms.CharField(max_length=100, widget=PasswordInput())
email = forms.CharField(max_length=100)
- telefone_comercial = forms.CharField(max_length=11)
- telefone_residencial = forms.CharField(max_length=11)
- telefone_celular = forms.CharField(max_length=11)
+ telefone_comercial = forms.CharField(max_length=11, required=False)
+ telefone_residencial = forms.CharField(max_length=11, required=False)
+ telefone_celular = forms.CharField(max_length=11, required=False)
- instituicao = forms.CharField(max_length=100)
- minicurriculo = forms.CharField(widget=Textarea())
+ instituicao = forms.CharField(max_length=100, label='Instituição')
+ minicurriculo = forms.CharField(widget=Textarea(), label='Mini Currículo')
rua = forms.CharField(max_length=100)
- numero = forms.CharField(max_length=10)
+ numero = forms.CharField(max_length=10, label='Número')
bairro = forms.CharField(max_length=100)
cidade = forms.CharField(max_length=100)
- uf = forms.CharField(max_length=100)
+ uf = forms.ChoiceField(choices=STATE_CHOICES)
- areas_interesse = forms.MultipleChoiceField()
+ area_interesse = forms.MultipleChoiceField(label='Áreas de Interesse')
<style type="text/css">
body {
- margin: 10px;
+ margin: 0px 60px 10px 60px;
background-color: #fff;
+ font-family: verdana,arial,helvetica,sans-serif;
}
h1.title {
color: #f00;
+ background: url(/site_media/imgs/logo.png) no-repeat;
+ width: 156px;
+ height: 190px;
+ overflow: hidden;
+ float: left;
+ }
+
+ h1.title a {
+ display: block;
+ padding-top: 190px;
+ }
+
+ h2 {
+ padding: 0px 0px 0px 0px;
+ margin: 0px;
+ text-transform: uppercase;
+ color: #cc0000;
}
label {
font-weight: bold;
}
- #login-form {
+ em {
+ color: #999;
+ }
+
+ #headsection {
+ border: solid 1px #f7f7f7;
+ background: #f7f7f7;
+ margin-bottom: 10px;
+ padding: 8px;
+ }
+
+ #right-box {
position: absolute;
- right: 10px;
- background-color: #f7f7f7;
- padding: 10px;
+ right: 60px;
+ top: 10px;
+ width: 200px;
+ border: solid 1px blue;
+ }
+
+ #login-form {
}
#login-form label {
#login-form input[type=password] {
width: 40px;
}
- </style>
- </head>
- <body>
- <h1 class="title"><a href="/">Encontro Mineiro de Software Livre</a></h1>
- {% if user.is_authenticated %}
-
- <ul>
- <li><a href="/inscrever_palestra">Inscreva uma palestra</a></li>
- <li><a href="/inscrever_minicurso">Inscreva um minicurso</a></li>
- <li><a href="/logout">Sair</a></li>
- </ul>
+ #menu {
+ }
- {% else %}
+ #content {
+ padding: 5px;
+ }
- <form id="login-form" method="post" action=".">
- <h3>Login</h3>
- <div class="field">
- <label for="id_username">Usuário:</label>
- <input id="id_username" class="vTextField required" type="text"
- maxlength="30" name="username" />
- </div>
- <div class="field">
- <label for="id_password-login">Senha:</label>
- <input id="id_password-login" class="vTextField required"
- type="password" name="password" />
+ #news {
+ list-style-type: none;
+ padding-left: 0px;
+ border: dotted 1px #d7d7d7;
+ }
- <input type="submit" value="Login" class="submit" name="submitting_login_form" />
- </div>
+ #news li {
+ padding: 4px;
+ }
- <a href="/cadastro">Cadastre-se</a>
- </form>
+ .even {
+ background-color: #f7e7fe;
+ }
+ </style>
+ </head>
+ <body>
+ <div id="headsection">
+ <h1 class="title"><a href="/">Encontro Mineiro de Software Livre</a></h1>
+ <div id="right-box">
+
+ {% if user.is_authenticated %}
+ <ul id="main-menu">
+ <li><a href="/inscrever_palestra">Inscreva uma palestra</a></li>
+ <li><a href="/inscrever_minicurso">Inscreva um minicurso</a></li>
+ <li><a href="/logout">Sair</a></li>
+ </ul>
+
+ {% else %}
+
+ <form id="login-form" method="post" action=".">
+ <h3>Login</h3>
+ <div class="field">
+ <label for="id_username">Usuário:</label>
+ <input id="id_username" class="vTextField required" type="text"
+ maxlength="30" name="username" />
+ </div>
+ <div class="field">
+ <label for="id_password-login">Senha:</label>
+ <input id="id_password-login" class="vTextField required"
+ type="password" name="password" />
+
+ <input type="submit" value="Login" class="submit" name="submitting_login_form" />
+ </div>
+
+ <a href="/cadastro">Cadastre-se</a>
+ </form>
+ {% endif %}
- {% endif %}
+ </div>
- {% if menu %}
- <ul id="menu">
- {% for i in menu %}
- <li><a href="/secao/{{ i.id }}">{{ i.titulo }}</a></li>
- {% endfor %}
- </ul>
- {% endif %}
+ {% if menu %}
+ <ul id="menu">
+ {% for i in menu %}
+ <li><a href="/secao/{{ i.id }}">{{ i.titulo }}</a></li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+ <br style="clear: both;" />
+ </div>
- <div id="conteudo">
+ <div id="content">
{% block content %}{% endblock %}
</div>
{% extends "base.html" %}
{% block content %}
-{{ form.as_p }}
+{% if ok %}
+
+<div class="confirmation">
+ <p>Cadastro efetuado com sucesso, você já foi autenticado.</p>
+
+ <p>Use o menu que apareceu para cadastrar uma palestra ou um minicurso</p>
+</div>
+
+{% else %}
+
+<form id="cadastro" method="post" action=".">
+ {{ form.as_p }}
+ <input type="submit" value="Ok!" />
+</form>
+
+{% endif %}
{% endblock %}
{% extends "base.html" %}
{% block content %}
+{% if index_sections %}
+{% for i in index_sections %}
+<h2>{{ i }}</h2>
+{{ i.corpo }}
+<br /><br />
+{% endfor %}
+{% endif %}
+
{% if news %}
-<hr />
<h2>Notícias</h2>
<ul id="news">
{% for i in news %}
- <li>
+ <li class="{% cycle odd,even %}">
<strong>{{ i.titulo }}</strong> — <em>{{ i.data_criacao }} (por {{ i.autor }})</em>
<p>{{ i.chamada }}</p>
<a href="/noticias/{{ i.id }}">Leia mais</a>
{% extends "base.html" %}
{% block content %}
-{{ form.as_p }}
+{% if ok %}
+
+<div class="confirmation">
+ <p>Sua palestra foi cadastrada com sucesso!</p>
+</div>
+
+{% else %}
+
+<form id="cadastro" method="post" action=".">
+ {{ form.as_p }}
+ <input type="submit" value="Ok!" />
+</form>
+
+{% endif %}
{% endblock %}
<p>{{ noticia.chamada }}</p>
<p>{{ noticia.corpo }}</p>
+<a href="javascript:;" onclick="history.back ();">Voltar</a>
+
{% endblock %}
+# -*- coding: utf8; -*-
"""
Copyright (C) 2007 Lincoln de Sousa <lincoln@archlinux-br.org>
"""
from django.shortcuts import render_to_response
from django.template import RequestContext, Context
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth.models import Group, User
+from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth import login
+
from eventmanager.decorators import enable_login_form
from eventmanager.forms import InscreverPalestra, CadastroPalestrante
-from eventmanager.conteudo.models import Noticia, Menu
+from eventmanager.conteudo.models import Noticia, Menu, Secao
+from eventmanager.eventos.models import *
@enable_login_form
def index(request):
news = Noticia.objects.order_by('-data_criacao')
menus = Menu.objects.all()
+ index_sections = Secao.objects.filter(index=True)
+ menu_sections = Secao.objects.filter(index=False)
- c = Context({'news': news, 'menu': menus})
+ c = Context({'news': news, 'menu': menus, 'menu_sections': menu_sections,
+ 'index_sections': index_sections})
return render_to_response('index.html', c,
context_instance=RequestContext(request))
+
@enable_login_form
def cadastro(request):
- form = CadastroPalestrante()
- c = Context({'form': form})
- return render_to_response('cadastro.html', c,
+ # context extension
+ c = {}
+
+ if request.POST:
+ # django's newforms lib requires a new instance of a form to be bounded
+ # with data, to be validated and used.
+ form = CadastroPalestrante(request.POST)
+ if form.is_valid():
+ cd = form.cleaned_data
+ wrong = False
+
+ # XXX: really ugly hack to use django validation machinary...
+ badattr = form._BaseForm__errors
+
+ if not cd['telefone_comercial'] and \
+ not cd['telefone_residencial'] and \
+ not cd['telefone_celular']:
+ badattr['telefone_comercial'] = ['Algum número de telefone '
+ 'precisa ser informado']
+ wrong = True
+
+ # don't save duplicated users...
+ try:
+ User.objects.get(username=cd['nome_usuario'])
+ badattr['nome_usuario'] = ['Este nome de usuário já existe!']
+ wrong = True
+ except User.DoesNotExist:
+ pass
+
+ if not wrong:
+ group = Group.objects.get_or_create(name='palestrantes')[0]
+
+ p = Palestrante()
+ p.user = User(username=cd['nome_usuario'], email=cd['email'])
+ p.user.set_password(cd['senha'])
+ p.user.save()
+ p.user.groups.add(group)
+
+ p.nome = cd['nome_completo']
+ p.email = cd['email']
+ p.telefone_comercial = cd['telefone_comercial']
+ p.telefone_residencial = cd['telefone_residencial']
+ p.telefone_celular = cd['telefone_celular']
+ p.rua = cd['rua']
+ p.numero = cd['numero']
+ p.bairro = cd['bairro']
+ p.cidade = cd['cidade']
+ p.uf = cd['uf']
+ p.minicurriculo = cd['minicurriculo']
+ p.save()
+
+ for i in cd['area_interesse']:
+ p.area_interesse.add(i)
+
+ c.update({'ok': 1})
+
+ fakepost = request.POST.copy()
+ fakepost['username'] = cd['nome_usuario']
+ fakepost['password'] = cd['senha']
+
+ manipulator = AuthenticationForm(request)
+ errors = manipulator.get_validation_errors(fakepost)
+ got_user = manipulator.get_user()
+ login(request, got_user)
+ else:
+ form = CadastroPalestrante()
+
+ c.update({'form': form})
+ return render_to_response('cadastro.html', Context(c),
context_instance=RequestContext(request))
+
+@login_required
def inscrever_palestra(request):
- form = InscreverPalestra()
- c = Context({'form': form})
- return render_to_response('inscrever_palestra.html', c,
+ c = {}
+ if request.POST:
+ form = InscreverPalestra(request.POST)
+ if form.is_valid():
+ cd = form.cleaned_data
+ p = Palestra()
+ p.titulo = cd['titulo']
+ p.tema = cd['tema']
+ p.categoria = CategoriaPalestra.objects.get(pk=cd['categoria'])
+ p.descricao_curta = cd['descricao_curta']
+ p.descricao_longa = cd['descricao_longa']
+ p.evento = Evento.objects.get(pk=1) # let the hammer play arround!
+ p.save()
+
+ up = User.objects.get(pk=request.user.id)
+ p.palestrante.add()
+ else:
+ form = InscreverPalestra()
+ c.update({'form': form})
+
+ return render_to_response('inscrever_palestra.html', Context(c),
context_instance=RequestContext(request))