summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askbot/const/__init__.py42
-rw-r--r--askbot/forms.py41
-rw-r--r--askbot/models/widgets.py93
-rw-r--r--askbot/views/widgets.py18
4 files changed, 100 insertions, 94 deletions
diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py
index dfb6995a..44de03af 100644
--- a/askbot/const/__init__.py
+++ b/askbot/const/__init__.py
@@ -403,5 +403,47 @@ AVATAR_STATUS_CHOICE = (
('a', _('Uploaded Avatar')),#avatar uploaded locally - with django-avatar app
)
+SEARCH_ORDER_BY = (
+ ('-added_at', _('date descendant')),
+ ('added_at', _('date ascendant')),
+ ('-last_activity_at', _('activity descendant')),
+ ('last_activity_at', _('activity ascendant')),
+ ('-answer_count', _('answers descendant')),
+ ('answer_count', _('answers ascendant')),
+ ('-score', _('votes descendant')),
+ ('score', _('votes ascendant')),
+ )
+
+DEFAULT_QUESTION_STYLE = '''
+@import url('http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:300,400,700');
+body {
+ overflow: hidden;
+}
+
+#container {
+ width: 200px;
+ height: 350px;
+}
+ul {
+ list-style: none;
+ padding: 5px;
+ margin: 5px;
+}
+li {
+ border-bottom: #CCC 1px solid;
+ padding-bottom: 5px;
+ padding-top: 5px;
+}
+li:last-child {
+ border: none;
+}
+a {
+ text-decoration: none;
+ color: #464646;
+ font-family: 'Yanone Kaffeesatz', sans-serif;
+ font-size: 15px;
+}
+'''
+
#an exception import * because that file has only strings
from askbot.const.message_keys import *
diff --git a/askbot/forms.py b/askbot/forms.py
index 2711d9fa..70d70448 100644
--- a/askbot/forms.py
+++ b/askbot/forms.py
@@ -12,6 +12,7 @@ from django.contrib.auth.models import User
from django_countries import countries
from askbot.utils.forms import NextUrlField, UserNameField
from askbot.mail import extract_first_email_address
+from askbot.models.tag import get_groups
from recaptcha_works.fields import RecaptchaField
from askbot.conf import settings as askbot_settings
from askbot.conf import get_tag_display_filter_strategy_choices
@@ -896,6 +897,7 @@ ASK_BY_EMAIL_SUBJECT_HELP = _(
'[tag1, tag2, tag3,...] question title'
)
+#widgetforms
class AskWidgetForm(forms.Form, FormWithHideableFields):
'''Simple form with just the title to ask a question'''
@@ -921,6 +923,45 @@ class AskWidgetForm(forms.Form, FormWithHideableFields):
else:
self.fields['text'].min_length = askbot_settings.MIN_QUESTION_BODY_LENGTH
+class CreateAskWidgetForm(forms.Form, FormWithHideableFields):
+ title = forms.CharField(max_length=100)
+
+ inner_style = forms.CharField(
+ widget=forms.Textarea,
+ required=False
+ )
+ outer_style = forms.CharField(
+ widget=forms.Textarea,
+ required=False
+ )
+
+ def __init__(self, *args, **kwargs):
+ from askbot.models import Tag
+ super(CreateAskWidgetForm, self).__init__(*args, **kwargs)
+ self.fields['group'] = forms.ModelChoiceField(queryset=get_groups().exclude(
+ name__startswith='_internal'), required=False)
+ self.fields['tag'] = forms.ModelChoiceField(queryset=Tag.objects.get_content_tags(),
+ required=False)
+ if not askbot_settings.GROUPS_ENABLED:
+ self.hide_field('group')
+
+class CreateQuestionWidgetForm(forms.Form, FormWithHideableFields):
+ title = forms.CharField(max_length=100)
+ question_number = forms.CharField(initial='7')
+ tagnames = forms.CharField(label=_('tags'), max_length=50)
+ search_query = forms.CharField(max_length=50, required=False)
+ order_by = forms.ChoiceField(choices=const.SEARCH_ORDER_BY,
+ initial='-addet_at')
+ style = forms.CharField(widget=forms.Textarea,
+ initial=const.DEFAULT_QUESTION_STYLE,
+ required=False)
+
+ def __init__(self, *args, **kwargs):
+ super(CreateQuestionWidgetForm, self).__init__(*args, **kwargs)
+ self.fields['tagnames'] = TagNamesField()
+ self.fields['group'] = forms.ModelChoiceField(queryset=get_groups().exclude(name__startswith='_internal'),
+ required=False)
+
class AskByEmailForm(forms.Form):
""":class:`~askbot.forms.AskByEmailForm`
validates question data, where question was posted
diff --git a/askbot/models/widgets.py b/askbot/models/widgets.py
index 80d55144..eaf2b214 100644
--- a/askbot/models/widgets.py
+++ b/askbot/models/widgets.py
@@ -2,59 +2,24 @@ from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from askbot.conf import settings as askbot_settings
-from askbot.models import Tag
+from askbot.models import Tag, Group
from askbot.models.tag import get_groups
from askbot.forms import FormWithHideableFields, TagNamesField
from askbot.conf import settings as askbot_settings
from django import forms
-
-DEFAULT_INNER_STYLE = ''
-
-DEFAULT_OUTER_STYLE = ''
-
-DEFAULT_QUESTION_STYLE = '''
-@import url('http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:300,400,700');
-body {
- overflow: hidden;
-}
-
-#container {
- width: 200px;
- height: 350px;
-}
-ul {
- list-style: none;
- padding: 5px;
- margin: 5px;
-}
-li {
- border-bottom: #CCC 1px solid;
- padding-bottom: 5px;
- padding-top: 5px;
-}
-li:last-child {
- border: none;
-}
-a {
- text-decoration: none;
- color: #464646;
- font-family: 'Yanone Kaffeesatz', sans-serif;
- font-size: 15px;
-}
-'''
-
+from askbot.const import DEFAULT_QUESTION_STYLE, SEARCH_ORDER_BY
class AskWidget(models.Model):
'''stores widgets styles and options'''
title = models.CharField(max_length=100)
- group = models.ForeignKey(Tag, null=True, blank=True,
+ group = models.ForeignKey(Group, null=True, blank=True,
related_name='groups')
tag = models.ForeignKey(Tag, null=True, blank=True)
include_text_field = models.BooleanField(default=False, blank=True)
- inner_style = models.TextField(default=DEFAULT_INNER_STYLE, blank=True)
- outer_style= models.TextField(default=DEFAULT_OUTER_STYLE, blank=True)
+ inner_style = models.TextField(blank=True)
+ outer_style = models.TextField(blank=True)
def get_related_questions(self):
if self.tag:
@@ -68,16 +33,6 @@ class AskWidget(models.Model):
def __unicode__(self):
return "Widget: %s" % self.title
-SEARCH_ORDER_BY = (
- ('-added_at', _('date descendant')),
- ('added_at', _('date ascendant')),
- ('-last_activity_at', _('activity descendant')),
- ('last_activity_at', _('activity ascendant')),
- ('-answer_count', _('answers descendant')),
- ('answer_count', _('answers ascendant')),
- ('-score', _('votes descendant')),
- ('score', _('votes ascendant')),
- )
class QuestionWidget(models.Model):
title = models.CharField(max_length=100)
@@ -93,40 +48,4 @@ class QuestionWidget(models.Model):
default=DEFAULT_QUESTION_STYLE, blank=True)
class Meta:
- app_label = 'askbot'
-
-#FORMS
-class CreateAskWidgetForm(forms.ModelForm, FormWithHideableFields):
- inner_style = forms.CharField(
- widget=forms.Textarea,
- required=False,
- initial=DEFAULT_INNER_STYLE
- )
- outer_style = forms.CharField(
- widget=forms.Textarea,
- required=False,
- initial=DEFAULT_OUTER_STYLE
- )
-
- group = forms.ModelChoiceField(queryset=get_groups().exclude(name__startswith='_internal'),
- required=False)
- tag = forms.ModelChoiceField(queryset=Tag.objects.get_content_tags(),
- required=False)
-
- def __init__(self, *args, **kwargs):
- super(CreateAskWidgetForm, self).__init__(*args, **kwargs)
- if not askbot_settings.GROUPS_ENABLED:
- self.hide_field('group')
-
- class Meta:
- model = AskWidget
-
-class CreateQuestionWidgetForm(forms.ModelForm, FormWithHideableFields):
- group = forms.ModelChoiceField(queryset=get_groups().exclude(name__startswith='_internal'),
- required=False)
-
- def __init__(self, *args, **kwargs):
- self.fields['tagnames'] = TagNamesField()
-
- class Meta:
- model = QuestionWidget
+ app_label = 'askbot' \ No newline at end of file
diff --git a/askbot/views/widgets.py b/askbot/views/widgets.py
index d0707a73..281c4cf9 100644
--- a/askbot/views/widgets.py
+++ b/askbot/views/widgets.py
@@ -22,8 +22,8 @@ WIDGETS_MODELS = {
}
WIDGETS_FORMS = {
- 'ask': models.widgets.CreateAskWidgetForm,
- 'question': models.widgets.CreateQuestionWidgetForm,
+ 'ask': forms.CreateAskWidgetForm,
+ 'question': forms.CreateQuestionWidgetForm,
}
def _get_model(key):
@@ -154,10 +154,12 @@ def list_widgets(request, model):
@decorators.admins_only
def create_widget(request, model):
form_class = _get_form(model)
+ model_class = _get_model(model)
if request.method == 'POST':
form = form_class(request.POST)
if form.is_valid():
- form.save()
+ instance = model_class(**form.cleaned_data)
+ instance.save()
return redirect('list_widgets', model=model)
else:
form = form_class()
@@ -174,13 +176,15 @@ def edit_widget(request, model, widget_id):
form_class = _get_form(model)
widget = get_object_or_404(model_class, pk=widget_id)
if request.method == 'POST':
- form = form_class(request.POST,
- instance=widget)
+ form = form_class(request.POST)
if form.is_valid():
- form.save()
+ instance = model_class(**form.cleaned_data)
+ instance.save()
return redirect('list_widgets', model=model)
else:
- form = form_class(instance=widget)
+ initial_dict = dict.copy(widget.__dict__)
+ del initial_dict['_state']
+ form = form_class(initial=initial_dict)
data = {'form': form,
'action': 'edit',