コード例 #1
0
ファイル: DetailView.py プロジェクト: sawrozpdl/Koora
    def get(self, request, slug):

        raw_response = api_call(method='get',
                                request=request,
                                reverse_for="articles-api:detail",
                                reverse_kwargs={'slug': slug})

        response = raw_response.json()

        message = get_message_or_default(request, {})

        if response['status'] == 200:
            article = response['data']['article']
            template = loader.get_template("articles/article.html")
            content = {
                "page_name": "articles",
                "article": article,
                "message": message,
                "comments": article['comments']
            }
            return HttpResponse(template.render(content, request))
        else:
            return suitableRedirect(response=raw_response,
                                    reverse_name="articles:detail",
                                    reverse_kwargs={"slug": slug})
コード例 #2
0
ファイル: CreateView.py プロジェクト: sawrozpdl/Koora
    def post(self, request):

        raw_response = api_call(method='post',
                                request=request,
                                reverse_for="articles-api:list",
                                data=request.POST.dict(),
                                files=request.FILES.dict())

        response = raw_response.json()

        if response['status'] == 200:
            if response['data']['article']['is_drafted']:
                return HttpResponseRedirect(
                    generate_url_for(
                        'articles:create',
                        query={
                            "type":
                            "success",
                            "content":
                            "Article Drafted, to publish it, go to your profile"
                        }))
            else:
                return HttpResponseRedirect(
                    response['data']['article']['absolute_url'])
        else:
            return suitableRedirect(response=raw_response,
                                    reverse_name="articles:create")
コード例 #3
0
    def get(self, request, slug):

        raw_response = api_call(method='get',
                                request=request,
                                reverse_for="articles-api:detail",
                                reverse_kwargs={'slug': slug})

        response = raw_response.json()

        message = get_message_or_default(
            request, {
                "type":
                "warning",
                "content":
                "Change required field and Press Update to Publish the new verson of your Article"
            })

        if response['status'] == 200:
            return HttpResponse(
                loader.get_template('articles/post_article.html').render(
                    {
                        "page_name": "articles",
                        "message": message,
                        "article": response['data']['article'],
                        "update_mode": True,
                        "tags": response['data']['article']['tag_string']
                    }, request))
        else:
            return suitableRedirect(response=raw_response,
                                    reverse_name="articles:update",
                                    reverse_kwargs={"slug": slug})
コード例 #4
0
ファイル: DetailView.py プロジェクト: sawrozpdl/Koora
    def get(self, request, model, slug):

        raw_response = api_call(method='get',
                                request=request,
                                reverse_for="comments-api:detail",
                                reverse_kwargs={'slug': slug})

        response = raw_response.json()

        message = get_message_or_default(request, {})

        template = loader.get_template("comments/comment_thread.html")

        if response['status'] == 200:
            content = {
                "page_name": model,
                "comment": response['data']['comment'],
                "message": message
            }
            return HttpResponse(template.render(content, request))
        else:
            return suitableRedirect(response=raw_response,
                                    reverse_name="comments:detail",
                                    reverse_kwargs={
                                        "slug": slug,
                                        "model": model
                                    })
コード例 #5
0
ファイル: ListView.py プロジェクト: sawrozpdl/Koora
    def get(self, request):

        params = request.GET.dict()

        raw_response = api_call(
            method='get',
            request=request,
            reverse_for="articles-api:list",
            reverse_params=params,
        )

        response = raw_response.json()

        message = get_message_or_default(request, {})

        template = loader.get_template('articles/articles.html')

        if response['status'] == 200:
            content = {
                "page_name": "articles",
                "message" : message,
                "page" : response['data']['page'],
                "page_range" : response['data']['page_range'],
                "query" : response['data']['query'],
                "hasResults" : response['data']['hasResults']
            }
            return HttpResponse(template.render(content, request))
        else:
            return suitableRedirect(response=raw_response, reverse_name="articles:list")
            
コード例 #6
0
ファイル: DetailView.py プロジェクト: sawrozpdl/Koora
    def post(self, request, slug):

        deleteMode = request.POST.get('deletemode', False)

        if deleteMode:

            raw_response = api_call(method='delete',
                                    request=request,
                                    reverse_for="articles-api:detail",
                                    reverse_kwargs={'slug': slug})

            response = raw_response.json()

            if response['status'] == 200:
                return HttpResponseRedirect(
                    generate_url_for("articles:list",
                                     query={
                                         "type": "success",
                                         "content":
                                         "Article deletion successful!"
                                     }))
            else:
                return suitableRedirect(response=raw_response,
                                        reverse_name="articles:list")

        else:

            raw_response = api_call(method='post',
                                    request=request,
                                    reverse_for="articles-api:detail",
                                    reverse_kwargs={'slug': slug},
                                    data=request.POST.dict())

            response = raw_response.json()

            if response['status'] == 200:
                return HttpResponseRedirect(
                    generate_url_for("articles:detail",
                                     kwargs={"slug": slug},
                                     query={
                                         "type": "success",
                                         "content": "Comment Added!"
                                     }))
            else:
                return suitableRedirect(response=raw_response,
                                        reverse_name="articles:detail",
                                        reverse_kwargs={"slug": slug})
コード例 #7
0
    def post(self, request, slug):

        raw_response = api_call(method='put',
                                request=request,
                                reverse_for="articles-api:detail",
                                reverse_kwargs={'slug': slug},
                                data=request.POST.dict(),
                                files=request.FILES.dict())

        response = raw_response.json()

        if response['status'] == 200:
            return HttpResponseRedirect(
                response['data']['article']['absolute_url'])
        else:
            return suitableRedirect(response=raw_response,
                                    reverse_name="articles:update",
                                    reverse_kwargs={"slug": slug})
コード例 #8
0
ファイル: ProfileView.py プロジェクト: sawrozpdl/Koora
    def get(self, request, username=None):

        message = get_message_or_default(request, {})

        user = User.objects.get(
            username=username) if username else request.user

        content = {"page_name": "profile", "message": message, "user": user}

        params = request.GET.dict()

        params['atype'] = "public"
        params['size'] = 3

        if username:
            params['uid'] = user.id

        raw_response = api_call(
            method='get',
            request=request,
            reverse_for="articles-api:list",
            reverse_params=params,
        )

        response = raw_response.json()

        if response['status'] == 200:
            content = {
                **content, "page": response['data']['page'],
                "page_range": response['data']['page_range'],
                "query": response['data']['query'],
                "hasResults": response['data']['hasResults']
            }

        return HttpResponse(
            loader.get_template('user/profile.html').render(content, request))
コード例 #9
0
ファイル: DetailView.py プロジェクト: sawrozpdl/Koora
    def post(self, request, model, slug):

        delete_mode = request.POST.get('delete_mode', False)

        if not delete_mode:

            response = api_call(method='post',
                                request=request,
                                reverse_for="comments-api:detail",
                                reverse_kwargs={
                                    'slug': slug
                                },
                                data=request.POST.dict()).json()

            if response['status'] == 200:
                return HttpResponseRedirect(
                    generate_url_for("comments:detail",
                                     kwargs={
                                         "model": model,
                                         "slug": slug
                                     },
                                     query={
                                         'type': 'success',
                                         'content': 'Reply Added!'
                                     }))
            else:
                return suitableRedirect(response=response,
                                        reverse_name="comments:detail",
                                        reverse_kwargs={
                                            "slug": slug,
                                            "model": model
                                        })

        else:

            response = api_call(method='delete',
                                request=request,
                                reverse_for="comments-api:detail",
                                reverse_kwargs={
                                    'slug': slug
                                }).json()

            togo = model

            if response['status'] == 200:
                kwargs = {'slug': response['data']['parent_slug']}
                query = {'type': 'success', 'content': 'Comment Removed!'}
                if not response['data']['is_parent']:
                    togo = "comments"
                    kwargs['model'] = model
                    query = {'type': 'success', 'content': 'Reply Removed!'}
                return HttpResponseRedirect(
                    generate_url_for("{}:detail".format(togo),
                                     kwargs=kwargs,
                                     query=query))
            else:
                return suitableRedirect(response=response,
                                        reverse_name="comments:detail",
                                        reverse_kwargs={
                                            "slug": slug,
                                            "model": model
                                        })