Esempio n. 1
0
    def get(self, request, category_id=None, year=None):
        if category_id:
            posts = self.model.objects.filter(category=category_id,
                                              is_publish=True)
        else:
            posts = self.model.objects.filter(is_publish=True)
        if year:
            posts = posts.filter(published_date__year=year)

        important_posts = posts.filter(
            is_important=True).order_by('published_date').reverse()[:3]

        page = request.GET.get('page')
        posts = PaginatorMixin.get_page(posts, 5, page)

        categories = Category.objects.all()

        return render(
            request, self.template_name, {
                'posts': posts,
                'important_posts': important_posts,
                'categories': categories,
                'current_category': category_id,
                'page': page
            })
Esempio n. 2
0
    def get(self, request, user, obj, current_page=None):
        page = request.GET.get('page')

        obj = PaginatorMixin.get_page(obj, 3, page)

        return render(request, self.template_name, {'user': user,
                                                    'objs': obj,
                                                    'page': page,
                                                    'current_page': current_page})
Esempio n. 3
0
    def get(self, request, user_id):
        user = self.model.objects.get(pk=user_id)
        comments = user.comments.all()
        page = request.GET.get('page')
        comments = PaginatorMixin.get_page(comments, 3, page)

        return render(request, self.template_name, {'user': user,
                                                    'comments': comments,
                                                    'page': page,
                                                    'current': 'comments'})
Esempio n. 4
0
    def get(self, request, user_id):
        user = self.model.objects.get(pk=user_id)
        saved_posts = user.posts.filter(is_publish=False)
        page = request.GET.get('page')
        saved_posts = PaginatorMixin.get_page(saved_posts, 3, page)

        return render(request, self.template_name, {'user': user,
                                                    'saved_posts': saved_posts,
                                                    'current': 'saved_posts',
                                                    'page': page})
Esempio n. 5
0
    def get(self, request, filter_name=None, filter_value=None):
        users = self.filter_results(filter_name, filter_value)
        page = request.GET.get('page')
        users = PaginatorMixin.get_page(users, 10, page)

        groups = Group.objects.all()
        return render(request, self.template_name, {'users': users,
                                                    'list_display': self.list_display,
                                                    'groups': groups,
                                                    'current_filter': filter_name,
                                                    'filter_value': filter_value,
                                                    'page': page})
Esempio n. 6
0
    def get(self, request, filter_name=None, filter_value=None):
        posts = self.filter_result(filter_name, filter_value)
        categories = Category.objects.all()
        page = request.GET.get('page')
        posts = PaginatorMixin.get_page(posts, 10, page)

        return render(
            request, self.template_name, {
                'posts': posts,
                'list_display': self.list_display,
                'categories': categories,
                'current_filter': filter_name,
                'filter_value': filter_value,
                'page': page
            })
Esempio n. 7
0
    def get(self, request, category_id=None):
        form = CategoryForm()
        if category_id:
            category = Category.objects.get(pk=category_id)
            form = self.form(instance=category)

        categories = Category.objects.all()
        page = request.GET.get('page')
        categories = PaginatorMixin.get_page(categories, 10, page)

        return render(
            request, self.template_name, {
                'categories': categories,
                'list_display': self.list_display,
                'page': page,
                'form': form
            })
Esempio n. 8
0
    def get(self, request, group_id=None):
        groups = Group.objects.all()
        page = request.GET.get('page')
        groups = PaginatorMixin.get_page(groups, 10, page)
        group = None
        group_permissions = None

        permissions = Permission.objects.all()

        if group_id:
            group = self.model.objects.get(pk=group_id)
            group_permissions = group.permissions.all()
            permissions = [perm for perm in permissions if perm not in group_permissions]

        return render(request, self.template_name, {'groups': groups,
                                                    'list_display': self.list_display,
                                                    'page': page,
                                                    'group': group,
                                                    'group_permissions': group_permissions,
                                                    'permissions': permissions})