-
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from nitely/future
v0.1.2
- Loading branch information
Showing
202 changed files
with
10,722 additions
and
1,643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,6 @@ htmlcov/ | |
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
|
||
# Mr Developer | ||
.mr.developer.cfg | ||
.project | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#-*- coding: utf-8 -*- | ||
|
||
# MINIMAL CONFIGURATION FOR PRODUCTION ENV | ||
|
||
DEBUG = False | ||
|
||
TEMPLATE_DEBUG = False | ||
|
||
# https://docs.djangoproject.com/en/dev/ref/settings/#admins | ||
ADMINS = (('John', '[email protected]'), ) | ||
|
||
# Secret key generator: https://djskgen.herokuapp.com/ | ||
SECRET_KEY = '' | ||
|
||
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts | ||
ALLOWED_HOSTS = ['.example.com', ] | ||
|
||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases | ||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
'NAME': 'mydatabase', | ||
'USER': 'mydatabaseuser', | ||
'PASSWORD': 'mypassword', | ||
'HOST': '127.0.0.1', | ||
'PORT': '5432', | ||
} | ||
} | ||
|
||
# These are all the languages Spirit provides. | ||
# https://www.transifex.com/projects/p/spirit/ | ||
gettext_noop = lambda s: s | ||
LANGUAGES = ( | ||
('de', gettext_noop('German')), | ||
('en', gettext_noop('English')), | ||
('es', gettext_noop('Spanish')), | ||
('sv', gettext_noop('Swedish')), | ||
) | ||
|
||
# Default language | ||
LANGUAGE_CODE = 'en' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from settings import * | ||
from local_settings_sample import * | ||
from local_settings_sample_dev import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
setup( | ||
name='django-spirit', | ||
version='0.1.1', | ||
version='0.1.2', | ||
description='Spirit is a Python based forum powered by Django.', | ||
author='Esteban Castro Borsani', | ||
author_email='[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.1.1' | ||
__version__ = '0.1.2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#-*- coding: utf-8 -*- | ||
|
||
from django import forms | ||
from django.forms.models import inlineformset_factory, BaseInlineFormSet | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from spirit.models.topic_poll import TopicPollChoice, TopicPoll, TopicPollVote | ||
|
||
|
||
class TopicPollForm(forms.ModelForm): | ||
|
||
class Meta: | ||
model = TopicPoll | ||
fields = ['choice_limit', ] | ||
|
||
def __init__(self, topic=None, *args, **kwargs): | ||
super(TopicPollForm, self).__init__(*args, **kwargs) | ||
self.topic = topic | ||
|
||
def clean_choice_limit(self): | ||
choice_limit = self.cleaned_data['choice_limit'] | ||
|
||
if choice_limit < 1: | ||
raise forms.ValidationError(_("This must be greater than zero")) | ||
|
||
return choice_limit | ||
|
||
def save(self, commit=True): | ||
if not self.instance.pk: | ||
self.instance.topic = self.topic | ||
|
||
return super(TopicPollForm, self).save(commit) | ||
|
||
|
||
class TopicPollChoiceInlineFormSet(BaseInlineFormSet): | ||
|
||
def is_filled(self): | ||
for form in self.forms: | ||
description = form.cleaned_data.get('description') | ||
is_marked_as_delete = form.cleaned_data.get('DELETE', False) | ||
|
||
if description and not is_marked_as_delete: | ||
return True | ||
|
||
return False | ||
|
||
|
||
# TODO: use min_num and validate_min in Django 1.7 | ||
TopicPollChoiceFormSet = inlineformset_factory(TopicPoll, TopicPollChoice, | ||
formset=TopicPollChoiceInlineFormSet, fields=('description', ), | ||
extra=2, max_num=20, validate_max=True) | ||
|
||
|
||
class TopicPollVoteManyForm(forms.Form): | ||
""" | ||
This special form allows single vote and multi vote as well. | ||
Its beauty is that it doesn't care if the choice_limit is increased or decreased later. | ||
""" | ||
def __init__(self, user=None, poll=None, *args, **kwargs): | ||
super(TopicPollVoteManyForm, self).__init__(*args, **kwargs) | ||
self.user = user | ||
self.poll = poll | ||
choices = TopicPollChoice.objects.filter(poll=poll) | ||
|
||
if poll.choice_limit > 1: | ||
self.fields['choices'] = forms.ModelMultipleChoiceField(queryset=choices, | ||
widget=forms.CheckboxSelectMultiple, | ||
label=_("Poll choices")) | ||
else: | ||
self.fields['choices'] = forms.ModelChoiceField(queryset=choices, | ||
empty_label=None, | ||
widget=forms.RadioSelect, | ||
label=_("Poll choices")) | ||
|
||
def load_initial(self): | ||
selected_choices = TopicPollChoice.objects.filter(poll=self.poll, votes__user=self.user) | ||
|
||
if self.poll.choice_limit == 1: | ||
try: | ||
selected_choices = selected_choices[0] | ||
except IndexError: | ||
selected_choices = None | ||
|
||
self.initial = {'choices': selected_choices, } | ||
|
||
def clean_choices(self): | ||
choices = self.cleaned_data['choices'] | ||
|
||
if self.poll.choice_limit > 1: | ||
if len(choices) > self.poll.choice_limit: | ||
raise forms.ValidationError(_("Too many selected choices. Limit is %s") | ||
% self.poll.choice_limit) | ||
|
||
return choices | ||
|
||
def clean(self): | ||
cleaned_data = super(TopicPollVoteManyForm, self).clean() | ||
|
||
if self.poll.is_closed: | ||
raise forms.ValidationError(_("This poll is closed")) | ||
|
||
return cleaned_data | ||
|
||
def save_m2m(self): | ||
choices = self.cleaned_data['choices'] | ||
|
||
if self.poll.choice_limit == 1: | ||
choices = [choices, ] | ||
|
||
TopicPollVote.objects.filter(user=self.user, choice__poll=self.poll)\ | ||
.delete() | ||
|
||
return TopicPollVote.objects.bulk_create([TopicPollVote(user=self.user, choice=choice) | ||
for choice in choices]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.