Permalink
Browse files

[cpanel/qpool] change endorsed_by to default, show proposed_by on edi…

…ting a proposed question
  • Loading branch information...
1 parent 7d449a5 commit 02bd867ee751bfd614dfa0e920bc4b9d588a537c @alexef committed Nov 10, 2011
@@ -1,4 +1,5 @@
from django import forms
+from django.contrib.auth.models import User
from wouso.core.qpool.models import Question, Answer, Schedule, Category, Tag
class QuestionForm(forms.Form):
@@ -7,7 +8,7 @@ class QuestionForm(forms.Form):
schedule = forms.DateField(required=False, input_formats=['%d.%m.%Y','%Y-%m-%d'], help_text='dd.mm.yyyy')
category = forms.CharField(max_length=50, required=False)
- def __init__(self, data=None, instance=None):
+ def __init__(self, data=None, instance=None, users=True):
super(QuestionForm, self).__init__(data)
if data is not None:
for i in filter(lambda a: a.startswith('answer_'), data.keys()):
@@ -22,6 +23,14 @@ def __init__(self, data=None, instance=None):
widget=forms.SelectMultiple, required=False,
initial=[t.name for t in instance.tags.all()] if instance else {})
self.instance = instance
+ if users:
+ self.fields['endorsed_by'] = forms.ModelChoiceField(queryset=User.objects.all(), required=False,
+ initial=instance.endorsed_by if instance else None)
+ self.fields['proposed_by'] = forms.ModelChoiceField(queryset=User.objects.all(), required=False,
+ initial=instance.proposed_by if instance else None)
+ self.users = True
+ else:
+ self.users = False
def save(self):
data = self.cleaned_data
@@ -47,6 +56,11 @@ def save(self):
self.instance.text = data['text']
self.instance.active = data['active']
+
+ if self.users:
+ self.instance.endorsed_by = data['endorsed_by']
+ self.instance.proposed_by = data['proposed_by']
+
# for qotd, scheduled
if self.instance.category.name == 'qotd':
sched = Schedule.objects.filter(question=self.instance)
@@ -139,19 +139,30 @@ def question_edit(request, id=None):
else:
question = None
+ categs = [(c.name.capitalize(), c.name) for c in Category.objects.all()]
+
if request.method == 'POST':
form = QuestionForm(request.POST, instance=question)
if form.is_valid():
form.save()
- return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.qpool_home'))
+ newq = Question.objects.get(pk=question.id)
+ if (newq.endorsed_by is None):
+ newq.endorsed_by = request.user
+ newq.save()
+ return HttpResponseRedirect(reverse('wouso.interface.cpanel.views.qpool_home', args = (newq.category.name,)))
else:
- form = QuestionForm(instance=question)
+ show_users = False
+ if question.category:
+ if question.category.name == 'proposed':
+ show_users = True
+
+ form = QuestionForm(instance=question, users=show_users)
return render_to_response('cpanel/question_edit.html',
{'question': question,
'form': form,
'module': 'qpool',
- 'categs': CATEGORIES},
+ 'categs': categs},
context_instance=RequestContext(request))
@login_required
@@ -1,11 +1,9 @@
{% extends 'cpanel/index.html' %}
{% block title %}CPanel{% endblock %}
-{% block sectiontitle %}Edit question{% endblock %}
+{% block sectiontitle %}Edit question #{{ question.id }}{% endblock %}
{% block sectioncontent %}
-
-<h2>Edit question #{{ question.id }}</h2>
{% if question %}
<div class="second">
<p>Proposed by: {{ question.proposed_by }}, Endorsed by: {{ question.endorsed_by }}</p>
@@ -61,6 +59,16 @@
</select>
</td></tr>
{% endif %}
+ {% if form.proposed_by %}
+ <tr><td>Proposed by:</td><td>
+ {{ form.proposed_by }}
+ </td></tr>
+ {% endif %}
+ {% if form.endorsed_by %}
+ <tr><td>Endorsed by:</td><td>
+ {{ form.endorsed_by }}
+ </td></tr>
+ {% endif %}
</table>
<div class="actions">
<button onclick="history.back(); return false;">Cancel</button>

0 comments on commit 02bd867

Please sign in to comment.