Beispiel #1
0
def forum(request, forum_slug):
    lastvisit_control(request)

    forum = get_object_or_404(Forum, slug=forum_slug)
    general_topics = Topic.objects.filter(general=True).order_by(
        '-sticky', 'topic_latest_post')
    topics = forum.topic_set.all().filter(general=False).order_by(
        '-sticky', 'topic_latest_post')

    if request.user.is_authenticated():
        for topic in topics:
            if topic.topic_latest_post.edited > request.session['last_visit'] and\
                    not topic.id in request.session["read_topic_dict"]:
                topic.is_read = False
            elif topic.topic_latest_post.edited < request.session['last_visit'] or\
                    not topic.id in request.session["read_topic_dict"] or\
                    request.session["read_topic_dict"][topic.id] > topic.topic_latest_post.edited:
                topic.is_read = True
            else:
                topic.is_read = False
    abuse_count = 0
    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return customgeneric.object_list(request,
                                     topics,
                                     template_name='forum/forum_detail.html',
                                     template_object_name='topic',
                                     extra_context={
                                         'forum': forum,
                                         'abuse_count': abuse_count,
                                         'general_topic_list': general_topics
                                     },
                                     paginate_by=TOPICS_PER_PAGE,
                                     allow_empty=True)
Beispiel #2
0
def forum(request, forum_slug):
    lastvisit_control(request)

    forum = get_object_or_404(Forum, slug=forum_slug)
    general_topics = Topic.objects.filter(general=True).order_by('-sticky', 'topic_latest_post')
    topics = forum.topic_set.all().filter(general=False).order_by('-sticky', 'topic_latest_post')

    if request.user.is_authenticated():
        for topic in topics:
            if topic.topic_latest_post.edited > request.session['last_visit'] and\
                    not topic.id in request.session["read_topic_dict"]:
                topic.is_read = False
            elif topic.topic_latest_post.edited < request.session['last_visit'] or\
                    not topic.id in request.session["read_topic_dict"] or\
                    request.session["read_topic_dict"][topic.id] > topic.topic_latest_post.edited:
                topic.is_read = True
            else:
                topic.is_read = False
    abuse_count = 0
    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    return customgeneric.object_list(request, topics,
                       template_name = 'forum/forum_detail.html',
                       template_object_name = 'topic',
                       extra_context = {'forum': forum, 'abuse_count': abuse_count, 'general_topic_list': general_topics},
                       paginate_by = TOPICS_PER_PAGE,
                       allow_empty = True)
Beispiel #3
0
def latest_topics(request):
    lastvisit_control(request)
    topics = Topic.objects.filter(topic_latest_post__hidden=False, forum__is_published=True, forum__hidden=False).order_by("topic_latest_post").distinct()[:NUMBER_OF_LATEST_TOPICS]

    if request.user.is_authenticated():
        for topic in topics:
            if topic.topic_latest_post.edited > request.session['last_visit'] and\
                    not topic.id in request.session["read_topic_dict"]:
                topic.is_read = False
            elif topic.topic_latest_post.edited < request.session['last_visit'] or\
                    not topic.id in request.session["read_topic_dict"] or\
                    request.session["read_topic_dict"][topic.id] > topic.topic_latest_post.edited:
                topic.is_read = True
            else:
                topic.is_read = False
    abuse_count = 0
    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    forum = Forum(
            name = u"Güncellenen Başlıklar",
            slug = "guncellenen-basliklar",
            )

    return customgeneric.object_list(request, topics,
                       template_name = 'forum/forum_detail.html',
                       template_object_name = 'topic',
                       extra_context = {'forum': forum, 'abuse_count': abuse_count},
                       paginate_by = TOPICS_PER_PAGE,
                       allow_empty = True)
Beispiel #4
0
def latest_topics(request):
    lastvisit_control(request)
    topics = Topic.objects.filter(
        topic_latest_post__hidden=False,
        forum__is_published=True,
        forum__hidden=False).order_by(
            "topic_latest_post").distinct()[:NUMBER_OF_LATEST_TOPICS]

    if request.user.is_authenticated():
        for topic in topics:
            if topic.topic_latest_post.edited > request.session['last_visit'] and\
                    not topic.id in request.session["read_topic_dict"]:
                topic.is_read = False
            elif topic.topic_latest_post.edited < request.session['last_visit'] or\
                    not topic.id in request.session["read_topic_dict"] or\
                    request.session["read_topic_dict"][topic.id] > topic.topic_latest_post.edited:
                topic.is_read = True
            else:
                topic.is_read = False
    abuse_count = 0
    if request.user.has_perm("forum.can_change_abusereport"):
        abuse_count = AbuseReport.objects.count()

    forum = Forum(
        name=u"Güncellenen Başlıklar",
        slug="guncellenen-basliklar",
    )

    return customgeneric.object_list(request,
                                     topics,
                                     template_name='forum/forum_detail.html',
                                     template_object_name='topic',
                                     extra_context={
                                         'forum': forum,
                                         'abuse_count': abuse_count
                                     },
                                     paginate_by=TOPICS_PER_PAGE,
                                     allow_empty=True)
Beispiel #5
0
def list(request, field="", filter_slug=""):
    ideas = Idea.objects.filter(is_hidden=False, status__is_invalid=False).order_by("-vote_count", "-id")
    if field == 'kategori':
        category_id = get_object_or_404(Category, slug = filter_slug)
        ideas = ideas.filter(category=category_id)
        page_title = "%s kategorisindeki fikirler" % category_id
    elif field == 'etiket':
        ideas = ideas.filter(tags__name__exact=filter_slug)
        page_title = "%s etiketli fikirler" % filter_slug
    elif field == 'ilgili':
        related_id = get_object_or_404(Related, name=filter_slug)
        ideas = ideas.filter(related_to=related_id)
        page_title = "%s ile ilgili fikirler" % filter_slug
    elif field == 'ekleyen':
        submitter_id = get_object_or_404(User, username=filter_slug)
        ideas = ideas.filter(submitter=submitter_id)
        page_title = "%s tarafından eklenen fikirler" % filter_slug
    elif field == 'populer':
        if filter_slug == 'bugun':
            ideas = ideas.filter(submitted_date__gt=datetime.datetime.now()-datetime.timedelta(1))
            page_title = "Bugünkü popüler fikirler"
        elif filter_slug == 'buhafta':
            ideas = ideas.filter(submitted_date__gt=datetime.datetime.now()-datetime.timedelta(7))
            page_title = "Bu haftaki popüler fikirler"
        elif filter_slug == 'buay':
            ideas = ideas.filter(submitted_date__gt=datetime.datetime.now()-datetime.timedelta(30))
            page_title = "Bu ayki popüler fikirler"
        elif filter_slug == 'tumzamanlar':
            page_title = "Tüm zamanların popüler fikirleri"
    elif field == 'son':
        if filter_slug == 'yorumlar':
            ideas = ideas.order_by("topic__topic_latest_post").filter(topic__posts__gt=1)
            page_title = "En son yorum alan iletiler"
        if filter_slug == 'eklenen':
            ideas = ideas.order_by("-submitted_date")
            page_title = "Son eklenen fikirler"
    elif field == 'durum':
        if filter_slug == "cozum-surecinde":
            s = Status.objects.get(name="Çözüm Sürecinde")
            ideas = ideas.filter(status=s)
            page_title = "Çözüme kavuşmuş fikirler"
        if filter_slug == "cozuldu":
            s = Status.objects.get(name="Çözüldü")
            ideas = ideas.filter(status=s)
            page_title = "Çözüme kavuşmuş fikirler"
        if filter_slug == "gonullu_araniyor":
            s = Status.objects.get(name="Gönüllü Aranıyor")
            ideas = ideas.filter(status=s)
            page_title = "Gönüllü arayan fikirler"
        if filter_slug == "gecersiz":
            ideas = Idea.objects.filter(is_hidden=False, status__is_invalid=True).order_by("-vote_count", "-id")
            page_title = "Geçersiz Fikirler"
    elif field == 'favori' and filter_slug == 'fikirler':
        page_title = "Favori fikirleriniz"
        try:
            favorites = Favorite.objects.filter(user=request.user.id)
            ideas = []
            i = 0
            for idea_id in favorites:
                ideas.append(favorites[i].idea)
                i += 1
        except ObjectDoesNotExist:
            pass
    else:
        page_title = "Son iki günün popüler fikirleri"
        ideas = ideas.filter(submitted_date__gt=datetime.datetime.now()-datetime.timedelta(2))
        if ideas.count() < 5:
            ideas = Idea.objects.filter(is_hidden=False, status__is_invalid=False).order_by("-submitted_date")[:5]
            page_title = "Son beş fikir"
    categories = Category.objects.order_by('name')
    if request.user.is_authenticated():
        if request.GET.has_key("page"):
            page = int(request.GET["page"])
        else:
            page = 1
        for idea in ideas[(page-1)*IDEAS_PER_PAGE:page*IDEAS_PER_PAGE]:
            try:
                f = Favorite.objects.get(user=request.user.id, idea=idea.id)
                idea.is_favorited = True
            except ObjectDoesNotExist:
                idea.is_favorited = False
            try:
                v = Vote.objects.get(user=request.user.id, idea=idea.id)
                idea.user_vote = v.vote
            except ObjectDoesNotExist:
                pass
            try:
                topic = Topic.objects.filter(title=idea.title)[0]
                idea.comment_count = topic.posts - 1
                idea.comment_url = topic.get_latest_post_url()
            except:
                idea.comment_count = 0
    return object_list(request, ideas,
            paginate_by=IDEAS_PER_PAGE,
            template_name="idea_list.html",
            extra_context={"page_title":page_title},
            )