コード例 #1
0
ファイル: views.py プロジェクト: Mytheny/modelbrouwers
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")
コード例 #2
0
ファイル: views.py プロジェクト: reaandrew/GAE-Examples
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})
コード例 #3
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
    })
コード例 #4
0
ファイル: views.py プロジェクト: isergey/chel
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
    })
コード例 #5
0
ファイル: views.py プロジェクト: reemachugani/eca-life
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))
コード例 #6
0
ファイル: views.py プロジェクト: REAANDREW/GAE-Examples
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
	})
コード例 #7
0
ファイル: views.py プロジェクト: VBelozyorov/libcms
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}
    )
コード例 #8
0
ファイル: views.py プロジェクト: Gautam023/tutorialsite
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)
コード例 #9
0
ファイル: views.py プロジェクト: reemachugani/eca-life
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))