示例#1
0
def forum_draad(request, draad_id):
  draad = ForumDraad.objects.prefetch_related('forum').get(pk=draad_id)
  fresh_form = ForumPostForm(initial={'draad': draad})

  # make sure the user can view the forum draad
  deny_on_fail(request.user.has_perm('forum.view_forumdeel', draad.forum))
  can_post = request.user.has_perm('forum.post_in_forumdeel', draad.forum)

  if request.method == 'POST':
    # if the user is posting, make sure he has the permissions to post here
    deny_on_fail(can_post)

    # initiate the filled in form
    form = ForumPostForm(request.POST, user=request.user)

    if form.is_valid():
      form.save()

      # use a fresh form for the next page
      return HttpResponseRedirect(reverse('forum.draad', args=[draad_id]))
  else:
    form = fresh_form

  posts = ForumPost.objects.all()\
    .filter(draad_id=draad_id)\
    .order_by('datum_tijd')

  return render_with_layout(request, 'forum_draad.html', title="Forum draad %s" % draad.titel, ctx={
    'draad': draad,
    'posts': posts,
    'new_post_form': form,
    'can_post': can_post
  })
示例#2
0
def forum_root(request):
  # find the forumdelen that may be seen by the user
  delen = list(ForumDeel.get_viewable_by(request.user))
  queryset = ForumDraad.objects.filter(forum__in=delen)

  # filter on forum deel
  if 'forum' in request.GET:
    titel = ForumDeel.objects.get(pk=request.GET['forum']).titel + " Reformaforum"
    queryset = queryset.filter(forum_id=request.GET['forum'])
  else:
    titel = "Reformaforum"

  table = ForumMostRecentTable(queryset)
  table.paginate(page=request.GET.get('page', 1), per_page=25)

  cats = grouped_dict(map(lambda d: (d.categorie, d), delen))

  return render_with_layout(request, 'forum_main.html', title=titel, ctx={
    'categories': cats,
    'posts': table
  })