Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: sirrice/moose
base: e6cc120576
...
head fork: sirrice/moose
compare: c9a9e66213
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 16 additions and 14 deletions.
  1. +10 −10 moose/forms.py
  2. +6 −4 moose/views.py
View
20 moose/forms.py
@@ -5,17 +5,17 @@
class AddQuestionForm(forms.ModelForm):
class Meta:
model = Question
- exclude = ['date']
+ exclude = ['user', 'date']
- # def clean_shortname(self):
- # sname = self.cleaned_data['shortname'].strip()
- # try:
- # q = Question.objects.get(shortname = sname)
- # except:
- # q = None
- # if q:
- # raise forms.ValidationError("duplicate short name found")
- # return sname
+ def clean_shortname(self):
+ sname = self.cleaned_data['shortname'].strip()
+ try:
+ q = Question.objects.get(shortname = sname)
+ except:
+ q = None
+ if not q:
+ raise forms.ValidationError("That name is already in use. Try another?")
+ return sname
View
10 moose/views.py
@@ -1,4 +1,5 @@
import random
+from django.contrib.auth.decorators import login_required
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext, loader
@@ -40,6 +41,7 @@ def feedback(request, qid=None):
'q' : q },
context_instance=RequestContext(request))
+@login_required
def question(request, qid=None):
if request.method == 'GET' and qid is not None:
try:
@@ -55,14 +57,14 @@ def question(request, qid=None):
q = None
return home(request)
-
if request.method == 'POST':
form = AddQuestionForm(request.POST)
if form.is_valid():
- form.save()
+ q = form.save(commit=False)
+ q.user = request.user
+ q.save()
messages.success(request, "added your question!")
- # save it
- pass
+ return redirect('home')
else:
form = AddQuestionForm()
return render_to_response('addquestion.html',

No commit comments for this range

Something went wrong with that request. Please try again.