Skip to content

Instantly share code, notes, and snippets.

@badescunicu
Last active December 20, 2015 01:19
Show Gist options
  • Save badescunicu/6048317 to your computer and use it in GitHub Desktop.
Save badescunicu/6048317 to your computer and use it in GitHub Desktop.
@permission_required('config.change_setting')
def qpool_tag_questions(request):
class TagForm(forms.Form):
questions = forms.MultipleChoiceField(choices=[(q.pk, q.text) for q in Question.objects.all()])
tag = forms.ChoiceField(choices=[(t.pk, t.name) for t in Tag.objects.all().exclude(name__in=['qotd', 'quest', 'challenge'])])
if request.method == 'POST':
form = TagForm(request.POST)
if form.is_valid():
q_pks = form.cleaned_data['questions']
tag_pk = form.cleaned_data['tag']
tag = Tag.objects.get(pk=tag_pk)
for pk in q_pks:
q = Question.objects.get(pk=pk)
q.tags.add(tag)
q.save()
return render_to_response('cpanel/tagged.html',
{'nr': len(q_pks)},
context_instance=RequestContext(request))
else:
form = TagForm()
return render_to_response('cpanel/tag_questions.html',
{'form': form},
context_instance=RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment