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})
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")
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})
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 })
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")
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})
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})
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))
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 })