Skip to content

Commit

Permalink
Sprint 4
Browse files Browse the repository at this point in the history
  • Loading branch information
mvfaria committed Jul 18, 2012
1 parent 9012d02 commit a217eab
Show file tree
Hide file tree
Showing 17 changed files with 707 additions and 147 deletions.
8 changes: 8 additions & 0 deletions src/.idea/dictionaries/viniciusfaria.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

311 changes: 171 additions & 140 deletions src/.idea/workspace.xml

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/core/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# coding: utf-8
__author__ = 'viniciusfaria'

from django.contrib import admin
from .models import Speaker, Contact, Media, Talk


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


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


class MediaInline(admin.TabularInline):
model = Media
extra = 1


class TalkAdmin(admin.ModelAdmin):
list_display = ('title','description','start_time')
inlines = [MediaInline,]


admin.site.register(Speaker, SpeakerAdmin)
admin.site.register(Talk, TalkAdmin)
99 changes: 98 additions & 1 deletion src/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,100 @@
# coding: utf-8
from django.db import models
from django.utils.translation import ugettext_lazy as _
from datetime import time


class Speaker(models.Model):
name = models.CharField(_('Nome'), max_length=255)
slug = models.SlugField(_('Slug'), unique=True)
url = models.URLField(_('Url'))
description = models.TextField(_(u'Descrição'), blank=True)
avatar = models.FileField(_('Avatar'), upload_to='palestrantes', blank=True, null=True)

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 = 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(_('Tipo'), max_length=1, choices=KINDS)
value = models.CharField(_('Valor'), max_length=255)

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


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

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

def at_afternoon(self):
qs = self.filter(start_time__gte=self.midday)
qs = qs.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()

def __unicode__(self):
return self.title

@property
def slides(self):
return self.media_set.filter(type="SL")

@property
def videos(self):
return self.media_set.filter(type="YT")


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

objects = PeriodManager()


class Media(models.Model):
MEDIAS = (
('SL', 'SlideShare'),
('YT', 'Youtube'),
)

talk = models.ForeignKey('Talk')
type = models.CharField(max_length=2, choices=MEDIAS)
title = models.CharField(u'Título', max_length=255)
media_id = models.CharField(max_length=255)

def __unicode__(self):
return u'%s - %s' % (self.talk.title, self.title)

# Create your models here.
9 changes: 9 additions & 0 deletions src/core/templates/core/speaker_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends 'base.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 %}
19 changes: 19 additions & 0 deletions src/core/templates/core/talk_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'base.html' %}
{% load slideshare %}
{% load youtube %}

{% block content %}
<h4>{{ talk.title }}</h4>
{% for speaker in talk.speaker.all %}
<h5><a href="{% url core:speaker_detail speaker.slug %}"
title="{{ speaker.description|truncatewords:20 }}">{{ speaker.name }}</a></h5>
{% endfor %}
<p>{{ talk.description }}</p>
{% for slide in talk.slides %}
<p>{% slideshare slide.media_id slide.title %}</p>
{% endfor %}
{% for video in talk.videos %}
<p>{% youtube video.media_id %}</p>
{% endfor %}
<p><a href="{% url core:talks %}">voltar</a></p>
{% endblock content %}
17 changes: 17 additions & 0 deletions src/core/templates/core/talks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'base.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 %}
11 changes: 11 additions & 0 deletions src/core/templates/core/talks_snippet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="palestra">
<h4><a href="{% url core:talk_detail talk.id %}">
{{ talk.start_time }} - {{ talk.title }}</a></h4>
{% for speaker in talk.speaker.all %}
<h5><a href="{% url core:speaker_detail speaker.slug %}"
title="{{ speaker.description|truncatewords:20 }}">
{{ speaker.name }}
</a></h5>
{% endfor %}
<p>{{ talk.description }}</p>
</div>
Empty file.
57 changes: 57 additions & 0 deletions src/core/templatetags/slideshare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# coding: utf-8
__author__ = 'viniciusfaria'

from django import template
from django.template import Context, Template, Node


TEMPLATE = """
<object id="__sse{{ id }}" width="425" height="355">
<param name="movie"
value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc={{ doc }}" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/>
<embed name="__sse{{ id }}"
src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc={{ doc }}"
type="application/x-shockwave-flash"
allowscriptaccess="always"
allowfullscreen="true"
width="425"
height="355">
</embed>
</object>
"""


def do_slideshare(parser, token):
try:
# split_contents() knows not to split quoted strings.
tag_name, id_, doc = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires 2 arguments" % token.contents.split()[0]
return SlideShareNode(id_, doc)


class SlideShareNode(Node):
def __init__(self, id_, doc):
self.id = template.Variable(id_)
self.doc = template.Variable(doc)

def render(self, context):
try:
actual_id = self.id.resolve(context)
except template.VariableDoesNotExist:
actual_id = self.id

try:
actual_doc = self.doc.resolve(context)
except template.VariableDoesNotExist:
actual_doc = self.doc

t = Template(TEMPLATE)
c = Context({'id': actual_id, 'doc': actual_doc}, autoescape=context.autoescape)
return t.render(c)


register = template.Library()
register.tag('slideshare', do_slideshare)
50 changes: 50 additions & 0 deletions src/core/templatetags/youtube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# coding: utf-8
__author__ = 'viniciusfaria'

from django import template
from django.template import Context, Template, Node


TEMPLATE = """
<object width="480" height="385">
<param name="movie" value="http://www.youtube.com/v/{{ id }}" />
<param name="allowFullScreen" value="true" />
<param name="allowscriptaccess" value="always" />
<embed src="http://www.youtube.com/v/{{ id }}"
type="application/x-shockwave-flash"
allowscriptaccess="always"
allowfullscreen="true"
width="480"
height="385">
</embed>
</object>
"""


def do_youtube(parser, token):
try:
# split_contents() knows not to split quoted strings.
tag_name, id_ = token.split_contents()
except ValueError:
msg = "%r tag requires 1 argument" % token.contents.split()[0]
raise template.TemplateSyntaxError, msg
return YoutubeNode(id_)


class YoutubeNode(Node):
def __init__(self, id_):
self.id = template.Variable(id_)

def render(self, context):
try:
actual_id = self.id.resolve(context)
except template.VariableDoesNotExist:
actual_id = self.id

t = Template(TEMPLATE)
c = Context({'id': actual_id}, autoescape=context.autoescape)
return t.render(c)


register = template.Library()
register.tag('youtube', do_youtube)
Loading

0 comments on commit a217eab

Please sign in to comment.