Exemple #1
0
def forum(request,
          forum_slug,
          topic_type='',
          topic_type2='',
          template_name="lbforum/forum.html"):
    forum = get_object_or_404(Forum, slug=forum_slug)
    topics = forum.topics.all()
    ob = request.GET.get('order_by')
    form = ForumForm(request.GET)
    if not ob:
        if 'order_by' in request.COOKIES:
            ob = request.COOKIES["order_by"]
        else:
            ob = '-last_reply_on'
        form = ForumForm(request.COOKIES)

    if topic_type:
        topic_type2 = topic_type
        topics = topics.filter(
            topic_type__slug=topic_type).order_by(ob).select_related()
        topic_type = ''
    else:
        topics = topics.order_by(ob).select_related()
    ext_ctx = {
        'form': form,
        'forum': forum,
        'topics': topics,
        'topic_type': topic_type,
        'topic_type2': topic_type2
    }
    return render(request, template_name, ext_ctx)
Exemple #2
0
def get_posting_level(request):
    data = {}
    form = ForumForm(request.GET)
    if form.is_valid():
        forum = form.cleaned_data['forum']
        username = request.user.get_profile().forum_nickname
        # iexact doesn't work because MySQL tables are utf8_bin collated...
        try:
            username_cleaned = clean_username(username)
            forum_user = ForumUser.objects.get(username_clean=username_cleaned)
        except ForumUser.DoesNotExist:
            try:
                username_cleaned = clean_username_fallback(username)
                forum_user = ForumUser.objects.get(username_clean=username_cleaned)
            except ForumUser.DoesNotExist:
                # final fallback - try to read the cookie
                uid = request.COOKIES.get(settings.PHPBB_UID_COOKIE)
                forum_user = ForumUser.objects.get(pk=uid)

        # TODO: find a way to cache this... or find it out client side
        num_posts = forum_user.user_posts

        restrictions = ForumPostCountRestriction.objects.filter(forum=forum)
        data['restrictions'] = [restr.posting_level for restr in restrictions if restr.min_posts > num_posts]
    return HttpResponse(json.dumps(data), mimetype="application/json")
Exemple #3
0
def create_forum_submit(request):
    forum = Forum(user=request._user, name="DEFAULT")

    data = ForumForm(request.POST, instance=forum)
    if data.is_valid():
        entity = data.save(commit=False)
        entity.put()
        return HttpResponseRedirect('/')

    return render_to_response('home/create_forum.html', {'forum_form': data})
Exemple #4
0
def forums(request):
    if not request.user.has_perms(['forum.can_views_forums']):
        return HttpResponseForbidden()

    forums = Forum.objects.all()
    if request.method == 'POST':
        if not request.user.has_perms(['forum.add_forum']):
            return HttpResponseForbidden()
        form = ForumForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('forum:frontend:forums')
    else:
        form = ForumForm()


    last_articles_dict = {}
    last_topics_dict = {}
    last_forums_dict = {}
    if request.user.has_perms(['forum.can_hide_articles']):
        last_articles = Article.objects.filter(deleted=False).order_by('-created')[:10]
    else:
        last_articles = Article.objects.filter(public=True, deleted=False).order_by('-created')[:10]

    for last_article in last_articles:
        last_articles_dict[last_article.id] = {'article': last_article}
        last_topics_dict[last_article.topic_id] = None

    topics = Topic.objects.filter(id__in=last_topics_dict.keys())

    for topic in topics:
        last_topics_dict[topic.id] = topic
        last_forums_dict[topic.forum_id] = None

    lforums = Forum.objects.filter(id__in=last_forums_dict.keys())

    for lforum in lforums:
        last_forums_dict[lforum.id] = lforum

    for last_article in last_articles:
        last_articles_dict[last_article.id]['topic']=last_topics_dict[last_article.topic_id]
        last_articles_dict[last_article.id]['forum'] = last_forums_dict[last_topics_dict[last_article.topic_id].forum_id]


    last_articles_list =  []
    for last_article in last_articles:
        last_articles_list.append(last_articles_dict[last_article.id])

    return render(request, 'forum/frontend/forums.html', {
        'forums': forums,
        'form': form,
        'last_articles': last_articles_list
    })
Exemple #5
0
def forum():
    forum = ForumModel.query().get()
    if not forum:
        forum = ForumModel()
    form = ForumForm(request.form, obj=forum)
    if request.method == 'POST' and form.validate():
        forum.date = form.date.data
        forum.address = form.address.data
        forum.registrable = form.registrable.data
        if forum.registrable:
            forum.register_link = form.register_link.data
        forum.put()
    return render_template('admin/forum.html', form=form)
Exemple #6
0
def new_forum(request, pk):
    """Add a new forum for club"""  
    if request.method == 'POST':
        p = request.POST
        form = ForumForm(p)
        if form.is_valid():
            club = Club.objects.get(pk=pk)
            forum = Forum.objects.create(title=p['title'], description=p['description'], club=club)
            return HttpResponseRedirect(reverse('club.views.club_page', args=[pk]))
    else:
        form = ForumForm()
    return render_to_response('forum/new_forum.html', {'form':form}, 
                    context_instance = RequestContext(request))
Exemple #7
0
def create_forum_submit(request):
	forum = Forum(user = request._user, name="DEFAULT")
	
	data = ForumForm(request.POST, instance=forum)
	if data.is_valid():
		entity = data.save(commit=False)
		entity.put()
		return HttpResponseRedirect('/')
	
	return render_to_response('home/create_forum.html',
	{
		'forum_form' : data
	})
Exemple #8
0
def forums(request):
    if not request.user.has_perms(["forum.can_views_forums"]):
        return HttpResponseForbidden()

    forums = Forum.objects.all()
    if request.method == "POST":
        if not request.user.has_perms(["forum.add_forum"]):
            return HttpResponseForbidden()
        form = ForumForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect("forum:frontend:forums")
    else:
        form = ForumForm()

    last_articles_dict = {}
    last_topics_dict = {}
    last_forums_dict = {}
    if request.user.has_perms(["forum.can_hide_articles"]):
        last_articles = Article.objects.filter(deleted=False).order_by("-created")[:10]
    else:
        last_articles = Article.objects.filter(public=True, deleted=False).order_by("-created")[:10]

    for last_article in last_articles:
        last_articles_dict[last_article.id] = {"article": last_article}
        last_topics_dict[last_article.topic_id] = None

    topics = Topic.objects.filter(id__in=last_topics_dict.keys())

    for topic in topics:
        last_topics_dict[topic.id] = topic
        last_forums_dict[topic.forum_id] = None

    lforums = Forum.objects.filter(id__in=last_forums_dict.keys())

    for lforum in lforums:
        last_forums_dict[lforum.id] = lforum

    for last_article in last_articles:
        last_articles_dict[last_article.id]["topic"] = last_topics_dict[last_article.topic_id]
        last_articles_dict[last_article.id]["forum"] = last_forums_dict[
            last_topics_dict[last_article.topic_id].forum_id
        ]

    last_articles_list = []
    for last_article in last_articles:
        last_articles_list.append(last_articles_dict[last_article.id])

    return render(
        request, "forum/frontend/forums.html", {"forums": forums, "form": form, "last_articles": last_articles_list}
    )
Exemple #9
0
def create(request):

  if request.POST:
    form=ArticleForm(request.POST)
    if form.is_valid():
      form.save()
      return HttpResponseRedirect('/forum/all')

  else:
    form=ArticleForm()
    args={}
    args.update(csrf(request))
    args['form']=form
    return render_to_response("create_forum.html",args)
Exemple #10
0
def forum(request,
          forum_slug,
          topic_type='',
          topic_type2='',
          template_name="lbforum/forum.html"):
    forum = get_object_or_404(Forum, slug=forum_slug)
    topics = forum.topic_set.all()
    if topic_type and topic_type != 'good':
        topic_type2 = topic_type
        topic_type = ''
    if topic_type == 'good':
        topics = topics.filter(level__gt=30)
        #topic_type = _("Distillate District")
    if topic_type2:
        topics = topics.filter(topic_type__slug=topic_type2)
    order_by = request.GET.get('order_by', '-last_reply_on')
    topics = topics.order_by('-sticky', order_by).select_related()
    form = ForumForm(request.GET)
    ext_ctx = {
        'form': form,
        'forum': forum,
        'topics': topics,
        'topic_type': topic_type,
        'topic_type2': topic_type2
    }
    return render(request, template_name, ext_ctx)
Exemple #11
0
def new_forum(request, pk):
    """Add a new forum for club"""
    if request.method == 'POST':
        p = request.POST
        form = ForumForm(p)
        if form.is_valid():
            club = Club.objects.get(pk=pk)
            forum = Forum.objects.create(title=p['title'],
                                         description=p['description'],
                                         club=club)
            return HttpResponseRedirect(
                reverse('club.views.club_page', args=[pk]))
    else:
        form = ForumForm()
    return render_to_response('forum/new_forum.html', {'form': form},
                              context_instance=RequestContext(request))
Exemple #12
0
def forums(request):
    if not request.user.has_perms(['forum.can_views_forums']):
        return HttpResponseForbidden()

    forums = Forum.objects.all()
    if request.method == 'POST':
        if not request.user.has_perms(['forum.add_forum']):
            return HttpResponseForbidden()
        form = ForumForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('forum:frontend:forums')
    else:
        form = ForumForm()

    last_articles_dict = {}
    last_topics_dict = {}
    last_forums_dict = {}
    if request.user.has_perms(['forum.can_hide_articles']):
        last_articles = Article.objects.filter(
            deleted=False).order_by('-created')[:10]
    else:
        last_articles = Article.objects.filter(
            public=True, deleted=False).order_by('-created')[:10]

    for last_article in last_articles:
        last_articles_dict[last_article.id] = {'article': last_article}
        last_topics_dict[last_article.topic_id] = None

    topics = Topic.objects.filter(id__in=last_topics_dict.keys())

    for topic in topics:
        last_topics_dict[topic.id] = topic
        last_forums_dict[topic.forum_id] = None

    lforums = Forum.objects.filter(id__in=last_forums_dict.keys())

    for lforum in lforums:
        last_forums_dict[lforum.id] = lforum

    for last_article in last_articles:
        last_articles_dict[last_article.id]['topic'] = last_topics_dict[
            last_article.topic_id]
        last_articles_dict[last_article.id]['forum'] = last_forums_dict[
            last_topics_dict[last_article.topic_id].forum_id]

    last_articles_list = []
    for last_article in last_articles:
        last_articles_list.append(last_articles_dict[last_article.id])

    return render(request, 'forum/frontend/forums.html', {
        'forums': forums,
        'form': form,
        'last_articles': last_articles_list
    })
Exemple #13
0
def recent(request, template_name="index.html"):
    ctx = {}
    ctx['games_qiuhanhua'] = Games.objects.select_related().exclude(
        language='cn').filter(post='1',
                              hh=True).order_by('-week_qiuhanhua_num',
                                                '-qiuhanhua_num',
                                                '-add_time')[:10]
    # games = list(Games.objects.select_related().filter(language='cn', post='1', state='1').order_by('-publish_time', '-add_time')[:5])
    # games.extend(list(Games.objects.select_related().exclude(language='cn').filter(post='1', state='1').order_by('-publish_time', '-add_time')[:5]))
    ctx['games'] = Games.objects.select_related().filter(
        post='1', state='1').order_by('-publish_time', '-add_time')[:10]
    ctx['games_hhing'] = Games.objects.select_related().filter(
        post='1', state='2').order_by('-add_time')[:4]
    ctx['unpost_games'] = Games.objects.select_related().filter(
        post='1', state='0').order_by('publish_time')[:3]
    ctx['wish_games'] = Wish.objects.select_related().filter(
        fin=False).order_by('-add_time')
    ctx['wish_games_fin'] = Wish.objects.select_related().filter(
        fin=True).order_by('-add_time')[:3]
    ctx['pp_rank'] = Profile.objects.select_related().all().order_by(
        '-pp')[:10]
    ctx['super_comment_rank'] = Profile.objects.select_related().all(
    ).order_by('-super_comment')[:10]
    ctx['gifts'] = Gifts.objects.select_related().filter(suggest=True)

    ob = request.GET.get('order_by')
    ctx['form'] = ForumForm(request.GET)
    if not ob:
        if 'order_by' in request.COOKIES:
            ob = request.COOKIES["order_by"]
        else:
            ob = '-last_reply_on'
        ctx['form'] = ForumForm(request.COOKIES)
    ctx['topics'] = Topic.objects.select_related().filter(
        forum__show_in_index=True).order_by('-sticky', ob)
    return render(request, template_name, ctx)
Exemple #14
0
def create_forum(request):
    return render_to_response('home/create_forum.html',
                              {'forum_form': ForumForm()})