예제 #1
0
def trending(request):
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()
    user_extend = None

    if request.user.is_authenticated():
        user_extend = UserExtend.objects.get(user=request.user)

    query = Post.objects.exclude(status__exact='t').order_by('-comment_count')
    page = request.GET.get('page', 1)

    paginator = Paginator(query, 20, body=5)

    try:
        trending = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        trending = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        trending = paginator.page(paginator.num_pages)

    return render(
        request,
        'main/trending_list.html',
        {
            'trending': trending,
            'sections': sections,
            'post_num': post_num,
            'user_num': user_num,
            'user_extend': user_extend,
        },
    )
예제 #2
0
def myPinnedPost(request):
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()
    user_extend = None

    if request.user.is_authenticated():
        user_extend = UserExtend.objects.get(user=request.user)

    query = user_extend.pin_post.all()
    page = request.GET.get('page', 1)

    paginator = Paginator(query, 20, body=5)

    try:
        pin_post_list = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        pin_post_list = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        pin_post_list = paginator.page(paginator.num_pages)

    return render(
        request,
        'main/myPinnedPost.html',
        {
            'pin_post_list': pin_post_list,
            'sections': sections,
            'post_num': post_num,
            'user_num': user_num,
            'user_extend': user_extend,
            'today': datetime.datetime.now(),
        },
    )
예제 #3
0
def MyMention(request):
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()
    user_extend = None

    if request.GET.has_key('search'):
        form = SearchForm(request.GET)
    else:
        return render(
            request,
            'main/my_mention.html',
            {
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
                'err': 'error'
            },
        )

    if form.is_valid():
        user_extend = form.cleaned_data['search']
        query = Comment.objects.exclude(post__status='t').filter( \
            Q(this_comment_quote__comment_by__user__username__iexact=user_extend) | \
            Q(comment_made__icontains=user_extend) ).order_by('-id')
        page = request.GET.get('page', 1)

        paginator = Paginator(query, 20, body=5)

        try:
            allcomment = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            allcomment = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            allcomment = paginator.page(paginator.num_pages)

        return render(
            request,
            'main/my_mention.html',
            {
                'allcomment': allcomment,
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
                'post_owner': user_extend,
            },
        )
    else:
        return render(
            request,
            'main/my_mention.html',
            {
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
            },
        )
예제 #4
0
def popular(request, slug):
    slug = slug.strip()
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()
    user_extend = None

    try:
        sec_query = Section.objects.get(name=slug)
    except Section.DoesNotExist:
        return render(
            request,
            'main/popular_section.html',
            {
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
                'err': 'error'
            },
        )

    if request.user.is_authenticated():
        user_extend = UserExtend.objects.get(user=request.user)

    if sec_query:

        query = sec_query.post_set.exclude(
            status__exact='t').order_by('-comment_count')
        page = request.GET.get('page', 1)

        paginator = Paginator(query, 20, body=5)

        try:
            section = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            section = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            section = paginator.page(paginator.num_pages)

        return render(
            request,
            'main/popular_section.html',
            {
                'section_name': sec_query,
                'section_list': section,
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
                'user_extend': user_extend,
            },
        )
예제 #5
0
def allMyComment(request, slug):
    slug = slug.strip()
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()
    user_extend = None

    try:
        queryu = User.objects.get(username=slug)
    except User.DoesNotExist:
        return render(
            request,
            'main/allmycomment.html',
            context={
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
            },
        )

    if request.user.is_authenticated():
        user_extend = UserExtend.objects.get(user=request.user)

    query = Comment.objects.exclude(post__status='t').filter(
        comment_by__user=queryu).order_by('-id')
    page = request.GET.get('page', 1)

    paginator = Paginator(query, 20, body=5)

    try:
        allcomment = paginator.page(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        allcomment = paginator.page(1)
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        allcomment = paginator.page(paginator.num_pages)

    return render(
        request,
        'main/allmycomment.html',
        {
            'allcomment': allcomment,
            'sections': sections,
            'post_num': post_num,
            'user_num': user_num,
            'user_extend': user_extend,
            'post_owner': queryu,
        },
    )
예제 #6
0
    def get(self, request, filter_by='all'):
        """docstring

                Note:
                    Do not include the `self` parameter in the ``Args`` section.

                Args:
                    param1: The first parameter.
                    param2: The second parameter.

                Returns:
                    True if successful, False otherwise.

                """
        # todo Finish docstring
        if not request.user.is_authenticated():
            return render(request, 'music/auth/login.html')
        else:
            page = request.GET.get('page', 1)
            try:
                label_ids = []
                labels = []
                for label in Label.objects.all():
                    label_ids.append(label.pk)
                    labels = Label.objects.filter(pk__in=label_ids)
                if filter_by == 'favorites':
                    labels = labels.filter(fav=True)
                paginate_labels = Paginator(labels,
                                            20,
                                            body=3,
                                            margin=1,
                                            tail=1)
                try:
                    labels = paginate_labels.page(page)
                except PageNotAnInteger:
                    labels = paginate_labels.page(1)
                except EmptyPage:
                    labels = paginate_labels.page(paginate_labels.num_pages)
            except Label.DoesNotExist:
                labels = []
            return render(request, 'music/label/labels.html', {
                'label_list': labels,
                'filter_by': filter_by,
            })
예제 #7
0
    def get(self, request, filter_by='all'):
        """docstring

                Note:
                    Do not include the `self` parameter in the ``Args`` section.

                Args:
                    param1: The first parameter.
                    param2: The second parameter.

                Returns:
                    True if successful, False otherwise.

                """
        # todo Finish docstring
        if not request.user.is_authenticated():
            return render(request, 'music/auth/login.html')
        else:
            page = request.GET.get('page', 1)
            try:
                song_ids = []
                for album in Album.objects.filter(user=request.user):
                    for song in album.song_set.all():
                        song_ids.append(song.pk)
                user_songs = Song.objects.filter(pk__in=song_ids)
                if filter_by == 'favorites':
                    user_songs = user_songs.filter(fav=True)
                paginate_songs = Paginator(user_songs,
                                           20,
                                           body=3,
                                           margin=1,
                                           tail=1)
                try:
                    user_songs = paginate_songs.page(page)
                except PageNotAnInteger:
                    user_songs = paginate_songs.page(1)
                except EmptyPage:
                    user_songs = paginate_songs.page(paginate_songs.num_pages)
            except Album.DoesNotExist:
                user_songs = []
            return render(request, 'music/song/songs.html', {
                'song_list': user_songs,
                'filter_by': filter_by,
            })
예제 #8
0
파일: views.py 프로젝트: hanq08/MOOCsite
def indexView(request):
    query = ''
    if 'query' in request.GET:
        query = request.GET['query']
    if not query or query == '':
        courses = Course.objects.all()
    else:
        qset = reduce(operator.__and__, [Q(course_name__icontains=query)])
        #| Q(descriptions__icontains = query) | \Q(provider__provider_name__icontains = query) | Q(school__school_name__icontains = query)])
        courses = Course.objects.filter(qset).distinct()
    provider = request.GET.get('provider')
    filterCourse(courses, provider)
    paginator = Paginator(courses, 7)
    page = request.GET.get('page')
    if (page == None):
        page = 1
    courses = getPaginatedCourses(page, paginator)
    return render(request,
                  'MOOCsite/index_extends.html',
                  context={
                      'courses': courses,
                      'page': page,
                      'queries': query
                  })
예제 #9
0
def page(request, pk, topic):
    sections = Section.objects.all()
    post_num = Post.objects.count()
    user_num = User.objects.filter(is_active=True).count()

    try:
        post_query = Post.objects.get(pk=pk)
    except Post.DoesNotExist:
        return render(
            request,
            'main/post_detail.html',
            {
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
            },
        )

    if slugify(topic) != slugify(post_query.title[0:50]):
        return render(
            request,
            'main/post_detail.html',
            {
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
            },
        )

    if post_query:
        if request.user.is_authenticated():
            hit_count = HitCount.objects.get_for_object(post_query)
            hit_count_response = HitCountMixin.hit_count(request, hit_count)
            userextend_user = UserExtend.objects.get(user=request.user)
            userextend_user.last_seen = timezone.now()
            userextend_user.save(update_fields=['last_seen'])

        query = post_query.comment_set.all()
        page = request.GET.get('page', 1)

        paginator = Paginator(query, 20, body=5)

        try:
            comment = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            comment = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            comment = paginator.page(paginator.num_pages)

        return render(
            request,
            'main/post_detail.html',
            {
                'post': post_query,
                'comment_list': comment,
                'sections': sections,
                'post_num': post_num,
                'user_num': user_num,
            },
        )