-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
406 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ def render(self, data, media_type=None, renderer_context=None): | |
return json.dumps({ | ||
'articles': data | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.contrib import admin | ||
from authors.apps.favorite import models | ||
|
||
# Register your models here. | ||
|
||
admin.site.register(models.Favorite) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error_msgs = { | ||
"article_favorited":"This article is in your favorites", | ||
"favorite_not_found":"That article is not in your favorites" | ||
} | ||
|
||
success_msg = { | ||
"favorite_deleted":"Removed article from your favorites" | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.db import models | ||
from cloudinary.models import CloudinaryField | ||
|
||
from authors.apps.articles.models import Article | ||
from authors.apps.authentication.models import User | ||
|
||
|
||
class Favorite(models.Model): | ||
""" | ||
Favorite model | ||
""" | ||
article_url = models.TextField(null=True) | ||
article_title = models.CharField(max_length=255, null=True) | ||
article_slug = models.CharField(max_length=255, null=True) | ||
user = models.ForeignKey( | ||
User, related_name="favorites", on_delete=models.CASCADE) | ||
favorited_date = models.DateTimeField(auto_now_add=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from rest_framework import serializers | ||
from django.contrib.sites.shortcuts import get_current_site | ||
from django.db.models import Q | ||
|
||
from authors.apps.favorite.models import Favorite | ||
|
||
|
||
class FavoriteSerializer(serializers.ModelSerializer): | ||
""" | ||
Favorite model serializer | ||
""" | ||
article_url = serializers.CharField(required=True) | ||
|
||
class Meta: | ||
model = Favorite | ||
fields = "__all__" | ||
|
||
def create_article_url(self, request, article_slug): | ||
""" | ||
Create the article url | ||
""" | ||
base_url = "http://" + get_current_site(request).domain + "/" | ||
article_url = base_url + "api/v1/articles/" + article_slug + "/" | ||
return article_url | ||
|
||
def check_article(self, slug, user_id): | ||
""" | ||
Check if that article was favorited | ||
""" | ||
favorite = Favorite.objects.filter( | ||
Q(article_slug=slug) & Q(user=user_id) | ||
) | ||
if favorite: | ||
return False | ||
else: | ||
return True | ||
|
||
def get_that_one_favorite(self, slug, user_id): | ||
""" | ||
Get one article from favorites | ||
""" | ||
favorite = Favorite.objects.filter( | ||
Q(article_slug=slug) & Q(user=user_id) | ||
) | ||
if favorite: | ||
return favorite | ||
else: | ||
return False | ||
|
||
def get_all_favorites(self, user): | ||
""" | ||
Get all articles | ||
""" | ||
favorites = Favorite.objects.filter(user=user).all() | ||
return favorites |
Empty file.
Oops, something went wrong.