# Path: apps/submission/models.py
# class Talk(TimeStampedModel):
#     TYPES = (
#         ('talk', _(u'Palestras')),
#         ('tutorial', _(u'Tutoriais')),
#         ('light', _(u'Palestras Relâmpago')),
#     )
# 
#     LEVELS = (
#         ('beginner', _(u'Iniciante')),
#         ('intermediate', _(u'Intermediário')),
#         ('advanced', _(u'Avançado')),
#     )
# 
#     BOOL = (
#         (False, _(u'Não')),
#         (True, _(u'Sim')),
#     )
# 
#     THEMES = (
#         ('web', _(u'Desenvolvimento Web')),
#         ('sci', _(u'Desenvolvimento Científico')),
#         ('mobile', _(u'Mobile')),
#         ('edu', _(u'Educação')),
#         ('emp', _(u'Empreendedorismo')),
#         ('adm', _(u'Administraçao de Sistemas')),
#         ('hardware', _(u'Hardware, Robótica')),
#         ('utils', _(u'Software Utilitários')),
#         ('core', _(u'Core Python')),
#         ('other', _(u'Outro')),
#     )
# 
#     name = models.CharField(_(u'Nome'), max_length=150)
#     email = models.EmailField(_(u'E-Mail'), max_length=254)
#     phone = models.CharField(_(u'Telefone'), max_length=14)
#     talk_once = models.BooleanField(_(u'Já palestrou'), choices=BOOL)
#     macro_theme = models.CharField(
#         _(u'MacroTema'), max_length=80, choices=THEMES,
#     )
#     title = models.CharField(_(u'Título'), max_length=80)
#     type = models.CharField(_(u'Tipo'), max_length=20, choices=TYPES)
#     level = models.CharField(_(u'Nível'), max_length=20, choices=LEVELS)
#     summary = models.TextField(_(u'Resumo'))
# 
#     class Meta:
#         verbose_name = _(u'Palestra')
#         verbose_name_plural = _(u'Palestras')
# 
#     def __unicode__(self):
#         return u'{0} | {1}'.format(self.name, self.title)
# 
#     def _gravatar_url(self, size=110):
#         hash = hashlib.md5(self.email).hexdigest()
#         return 'http://gravatar.com/avatar/{0}?s={1}'.format(hash, size)
# 
#     @property
#     def gravatar(self):
#         return self._gravatar_url(97)
# 
#     def get_type(self):
#         return dict(self.TYPES)[self.type]
# 
#     def get_level(self):
#         return dict(self.LEVELS)[self.level]
# 
#     def get_macro_theme(self):
#         return dict(self.THEMES)[self.macro_theme]
# 
#     def _form(self, type):
#         from .forms import VoteForm
#         return VoteForm(initial={'talk': self.pk, 'type': type})
# 
#     def like_form(self):
#         return self._form('like')
# 
#     def dislike_form(self):
#         return self._form('dislike')
# 
# class Vote(TimeStampedModel):
#     TYPES = (
#         (u'like', _(u'Gostei')),
#         (u'dislike', _(u'Não gostei')),
#     )
# 
#     email = models.ForeignKey('emails.Email')
#     talk = models.ForeignKey('submission.Talk')
#     type = models.CharField(max_length=15, choices=TYPES)
# 
#     def __unicode__(self):
#         return u'{0}; {1}; {2}'.format(self.email, self.talk.id, self.type)


from django import forms
from django.utils.translation import ugettext_lazy as _
from .models import Talk, Vote
from events.models import EventTalk


class TalkForm(forms.ModelForm):
    class Meta:
        model = Talk

    def __init__(self, *args, **kwargs):
        self.event = kwargs.pop('event')
        super(TalkForm, self).__init__(*args, **kwargs)
        for key, field in self.fields.items():
            if isinstance(field.widget, forms.Textarea):
                field.widget.attrs['class'] = 'input-xxlarge'
            else:
                field.widget.attrs['class'] = 'input-xlarge'

    def save(self, *args, **kwargs):
        # Criar EventTalk, para já constar no admin e facilmente ser ativado
        # caso a palestra seja aprovada
        talk = super(TalkForm, self).save(*args, **kwargs)
        EventTalk.objects.create(talk=talk, event=self.event)

        return talk


class VoteForm(forms.Form):
    talk = forms.Field(widget=forms.HiddenInput)
    type = forms.Field(widget=forms.HiddenInput)

    def save(self, email):
        talk = self.cleaned_data['talk']

# Path: apps/submission/models.py
# class Talk(TimeStampedModel):
#     TYPES = (
#         ('talk', _(u'Palestras')),
#         ('tutorial', _(u'Tutoriais')),
#         ('light', _(u'Palestras Relâmpago')),
#     )
# 
#     LEVELS = (
#         ('beginner', _(u'Iniciante')),
#         ('intermediate', _(u'Intermediário')),
#         ('advanced', _(u'Avançado')),
#     )
# 
#     BOOL = (
#         (False, _(u'Não')),
#         (True, _(u'Sim')),
#     )
# 
#     THEMES = (
#         ('web', _(u'Desenvolvimento Web')),
#         ('sci', _(u'Desenvolvimento Científico')),
#         ('mobile', _(u'Mobile')),
#         ('edu', _(u'Educação')),
#         ('emp', _(u'Empreendedorismo')),
#         ('adm', _(u'Administraçao de Sistemas')),
#         ('hardware', _(u'Hardware, Robótica')),
#         ('utils', _(u'Software Utilitários')),
#         ('core', _(u'Core Python')),
#         ('other', _(u'Outro')),
#     )
# 
#     name = models.CharField(_(u'Nome'), max_length=150)
#     email = models.EmailField(_(u'E-Mail'), max_length=254)
#     phone = models.CharField(_(u'Telefone'), max_length=14)
#     talk_once = models.BooleanField(_(u'Já palestrou'), choices=BOOL)
#     macro_theme = models.CharField(
#         _(u'MacroTema'), max_length=80, choices=THEMES,
#     )
#     title = models.CharField(_(u'Título'), max_length=80)
#     type = models.CharField(_(u'Tipo'), max_length=20, choices=TYPES)
#     level = models.CharField(_(u'Nível'), max_length=20, choices=LEVELS)
#     summary = models.TextField(_(u'Resumo'))
# 
#     class Meta:
#         verbose_name = _(u'Palestra')
#         verbose_name_plural = _(u'Palestras')
# 
#     def __unicode__(self):
#         return u'{0} | {1}'.format(self.name, self.title)
# 
#     def _gravatar_url(self, size=110):
#         hash = hashlib.md5(self.email).hexdigest()
#         return 'http://gravatar.com/avatar/{0}?s={1}'.format(hash, size)
# 
#     @property
#     def gravatar(self):
#         return self._gravatar_url(97)
# 
#     def get_type(self):
#         return dict(self.TYPES)[self.type]
# 
#     def get_level(self):
#         return dict(self.LEVELS)[self.level]
# 
#     def get_macro_theme(self):
#         return dict(self.THEMES)[self.macro_theme]
# 
#     def _form(self, type):
#         from .forms import VoteForm
#         return VoteForm(initial={'talk': self.pk, 'type': type})
# 
#     def like_form(self):
#         return self._form('like')
# 
#     def dislike_form(self):
#         return self._form('dislike')
# 
# class Vote(TimeStampedModel):
#     TYPES = (
#         (u'like', _(u'Gostei')),
#         (u'dislike', _(u'Não gostei')),
#     )
# 
#     email = models.ForeignKey('emails.Email')
#     talk = models.ForeignKey('submission.Talk')
#     type = models.CharField(max_length=15, choices=TYPES)
# 
#     def __unicode__(self):
#         return u'{0}; {1}; {2}'.format(self.email, self.talk.id, self.type)


# Path: apps/submission/forms.py
from django import forms
from django.utils.translation import ugettext_lazy as _
from .models import Talk, Vote
from events.models import EventTalk



class TalkForm(forms.ModelForm):
    class Meta:
        model = Talk

    def __init__(self, *args, **kwargs):
        self.event = kwargs.pop('event')
        super(TalkForm, self).__init__(*args, **kwargs)
        for key, field in self.fields.items():
            if isinstance(field.widget, forms.Textarea):
                field.widget.attrs['class'] = 'input-xxlarge'
            else:
                field.widget.attrs['class'] = 'input-xlarge'

    def save(self, *args, **kwargs):
        # Criar EventTalk, para já constar no admin e facilmente ser ativado
        # caso a palestra seja aprovada
        talk = super(TalkForm, self).save(*args, **kwargs)
        EventTalk.objects.create(talk=talk, event=self.event)

        return talk


class VoteForm(forms.Form):
    talk = forms.Field(widget=forms.HiddenInput)
    type = forms.Field(widget=forms.HiddenInput)

    def save(self, email):
        talk = self.cleaned_data['talk']

        talk = Talk.objects.get(pk=talk)