Example #1
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, {})

        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})
Example #2
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})
Example #3
0
    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
                                    })
Example #4
0
    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")
            
Example #5
0
 def get(self, request):
     if request.method == "GET":
         message = get_message_or_default(request, {})
         buffer = request.GET.dict()
         return HttpResponse(
             loader.get_template("accounts/register.html").render(
                 {
                     "message": message,
                     "buffer": buffer
                 }, request))
Example #6
0
    def get(self, request):

        message = get_message_or_default(request, {})

        return HttpResponse(
            loader.get_template('user/settings.html').render(
                {
                    "page_name": "settings",
                    "message": message
                }, request))
Example #7
0
    def get(self, request):

        if request.method == "GET":

            message = get_message_or_default(request, {})

            buffer = request.GET.dict()

            return HttpResponse(
                loader.get_template("accounts/login.html").render(
                    {
                        'message': message,
                        'buffer': buffer
                    }, request))
Example #8
0
    def get(self, request):

        message = get_message_or_default(
            request, {
                "type":
                "warning",
                "content":
                "Fill up your article and Click Post to publish and Draft to save it as a Draft"
            })

        return HttpResponse(
            loader.get_template('articles/post_article.html').render(
                {
                    "page_name": "create_article",
                    "message": message
                }, request))
Example #9
0
    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))