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

Commit

Permalink
4º sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmveloso committed Mar 20, 2011
1 parent 4f6cd42 commit 7d92839
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 2 deletions.
12 changes: 12 additions & 0 deletions core/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib import admin
from core.models import Speaker, Contact

class ContactInline(admin.TabularInline):
model = Contact
extra = 1

class SpeakerAdmin(admin.ModelAdmin):
inlines = [ContactInline,]
prepopulated_fields = {'slug': ('name', )}

admin.site.register(Speaker, SpeakerAdmin)
83 changes: 82 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,85 @@
from django.db import models
from django.utils.translation import ugettext as _
import datetime

# Create your models here.
class Speaker(models.Model):
name = models.CharField(max_length=255)
slug = models.SlugField()
url = models.URLField(verify_exists=False)
description = models.TextField(blank=True)
avatar = models.FileField(upload_to='palestrantes', blank=True, null=True)

class Meta:
verbose_name = 'Palestrante'
verbose_name_plural = 'Palestrantes'

def __unicode__(self):
return self.name

class KindContactManager(models.Manager):
def __init__(self, kind):
super(KindContactManager, self).__init__()
self.kind = kind

def get_query_set(self):
qs = super(KindContactManager, self).get_query_set()
qs.filter = kind=self.kind
return qs

class Contact(models.Model):
KINDS = (
('P', _('Telefone')),
('E', _('E-mail')),
('F', _('Fax')))
speaker = models.ForeignKey(Speaker, verbose_name=_('Palestrante'))
kind = models.CharField(max_length=1, choices=KINDS)
value = models.CharField(max_length=255)

objects = models.Manager()
phones = KindContactManager('P')
emails = KindContactManager('E')
faxes = KindContactManager('F')

class Meta:
verbose_name = 'Contato'
verbose_name_plural = 'Contatos'

class PeriodManager(models.Manager):
midday = datetime.time(12)

def at_morning(self):
qs = self.filter(start_time__lt=self.midday)
qs = self.order_by('start_time')
return qs

def at_afternoon(self):
qs = self.filter(start_time__gt=self.midday)
qs = self.order_by('start_time')
return qs

class Talk(models.Model):
title = models.CharField(max_length=200)
description = models.TextField()
start_time = models.TimeField(blank=True)
speakers = models.ManyToManyField('Speaker', verbose_name=_('palestrante'))

objects = PeriodManager()

class Meta:
verbose_name = 'Palestra'
verbose_name_plural = 'Palestras'

def __unicode__(self):
return unicode(self.title)

class Course(Talk):
slots = models.IntegerField()
notes = models.TextField()

class Meta:
verbose_name = 'Curso'
verbose_name = 'Cursos'




16 changes: 15 additions & 1 deletion core/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# Create your views here.

from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.shortcuts import render_to_response, get_object_or_404
from django.views.generic.simple import direct_to_template
from django.template import RequestContext
from core.models import Talk

def homepage(request):
context = RequestContext(request)
return render_to_response('homepage.html', context)

def speaker(request, slug):
speaker = get_object_or_404(Speaker, slug=slug)
context = RequestContext(request, {'speaker': speaker})
return render_to_response('core/speaker.html', context)

def talks(request):
return direct_to_template(request, 'core/talks.html', {
'morning_talks': Talk.objects.at_morning(),
'afternoon_talks': Talk.objects.at_afternoon(), })



Binary file modified database.db
Binary file not shown.
12 changes: 12 additions & 0 deletions templates/core/speaker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'master.html' %}
{% block content %}

{% if speaker.avatar %}
<p>
<img src="{{ speaker.avatar.url }}" alt="{{ speaker.name }}" />
</p>
{% endif %}
<h4><a href="{{ speaker.url }}">{{ speaker.name }}</a></h4>
<p>{{ speaker.description</p>
{% endblock content %}

17 changes: 17 additions & 0 deletions templates/core/talks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'master.html' %}
{% block content %}
<h3>Manhã</h3>
{% for talk in morning_talks %}
{% include 'core/talks_snippet.html' %}
{% empty %}
<p>Não existem palestras durante a manhã.</p>
{% endfor %}
<hr style="display: block"/>
<h3>Tarde</h3>
{% for talk in afternoon_talks %}
{% include 'core/talks_snippet.html' %}
{% empty %}
<p>Não existem palestras durante a tarde.</p>
{% endfor %}
{% endblock content %}

12 changes: 12 additions & 0 deletions templates/core/talks_snippet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="palestra">
<h4><a href="{% url core:talk_details talk.id %}">
{{ talk.start_time }} - {{ talk.title }}</a></h4>
{% for speaker in talk.speaker.all %}
<h5><a href="{% url core:speaker speaker.slug %}"
title="{{ speaker.description|truncatewords:20 }}">
{{ speaker.name }}
</a></h5>
{% endfor %}
<p>{{ talk.description }}</p>
</div>

1 change: 1 addition & 0 deletions templates/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h1><a href="#">EventeX</a></h1>
<ul>
<li><a href="{% url home %}" class="first">Home</a></li>
<li><a href="{% url subscription:subscribe %}">Inscrições</a></li>
<li><a href="{% url talks %}">Palestras</a></li>
<li><a href="#">Contato</a></li>
</ul>
</div>
Expand Down
4 changes: 4 additions & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)

urlpatterns += patterns('core.views',
url(r'^palestrante/([-\w]+)/$', 'speaker', name='speaker'),
url(r'^palestras/$', 'talks', name='talks'),)

0 comments on commit 7d92839

Please sign in to comment.