Exemplo n.º 1
0
def new_discussion(request):
  form=DiscussionForm(initial={'owner':request.user})
  if request.method == 'POST':
      if form.validate(request.form):
          form.save(crud=CRUD.Create)
          return redirect(url_for('tasteofhome/forum.discussions'))
  return render_to_response('tasteofhome/new_discussion.html', {'form': form.as_widget()})
Exemplo n.º 2
0
def discussion_form_view(request, school_name):
    form_msg = {}

    if request.method == 'POST':
        user = request.user
        forum = Forum.objects.get(school=request.user.school)
        ip = request.META.get('REMOTE_ADDR', None)

        post_form_kwargs = {"user": user, "forum": forum, "ip": ip}

        discussionForm = DiscussionForm(request.POST, **post_form_kwargs)

        if discussionForm.is_valid():
            print discussionForm.cleaned_data
            discussionForm.save()

            url = "/%s/discussion/%s/%s" % (
                school_name, discussionForm.post.id,
                convert_from_space_to_dash(discussionForm.post.post_topic))
            print url
            form_msg['redirect_url'] = url
        else:
            print discussionForm.errors
            form_msg['errors'] = discussionForm.errors

        jsonCtx = json.dumps(form_msg)
        return HttpResponse(jsonCtx, mimetype='application/json')

    else:
        discussionForm = DiscussionForm()

        ctx = {'discussionForm': discussionForm}
        return render_to_response(
            'discussion/postDiscussion.html', ctx, context_instance=RequestContext(request))
Exemplo n.º 3
0
def update_discussion(request, discussion_id=None):
    discussion = get_object_or_404(Discussion, id=discussion_id)
    if request.POST:
        if request.user == discussion.author or request.user.is_staff() or request.user.is_superuser:
            form = DiscussionForm(request.POST, instance=discussion)
            if form.is_valid():
                discussion = form.save()
                discussion.author = request.user
                discussion.save()

                return redirect(discussion)
Exemplo n.º 4
0
def create_discussion(request):
	if request.POST:
		form = DiscussionForm(request.POST,request.FILES)
		if form.is_valid():
			form.save()			
			return HttpResponseRedirect('/appwptn/all/discussion')
	else:
		form = DiscussionForm()
	args = {}
	args.update(csrf(request))
	args['form'] = form
	return render_to_response('create_discussion.html',args)	
Exemplo n.º 5
0
def post_discussion(request):
    if request.POST:
        form = DiscussionForm(request.POST)
        if form.is_valid():
            discussion = form.save()
            discussion.author = request.user
            discussion.save()

            user = request.user
            user.discussion_count += 1
            user.save()

            return redirect(discussion)
    else:
        form = DiscussionForm()

    variables = {
        'pagetitle': 'Ny diskusjon',
        'form': form,
    }

    return render(request, 'discussion_form.html', variables)
Exemplo n.º 6
0
def discussions_all():
	form = DiscussionForm()
	
	if request.method=='POST':
		if form.validate_on_submit():
			ChallengeName = request.form['ChallengeName']
			Topic = form.Topic.data
			Description = form.Description.data
			
			CreatorID = g.user.get_id()
			DateCreated = datetime.datetime.now()
			
			discussion = Discussion(ChallengeName, Topic, CreatorID, DateCreated, Description)
			
			commit_to_db(discussion)
			
			return redirect(url_for('discussions_all'))
		else:
			flash("Could not start your new discussion")
			return redirect(url_for('discussions_all'))
			
	if request.method=='GET':
		return render_template('discussions_all.html', challenges = get_challenges(), form = form)