Merge remote-tracking branch 'origin/master' into twitter_api

# Conflicts:
#	backend/app_be/apps.py
#	backend/app_be/models.py
#	backend/app_be/urls.py
This commit is contained in:
Manuel Hude
2021-05-02 21:52:39 +02:00
14 changed files with 212 additions and 129 deletions
+7 -3
View File
@@ -1,7 +1,7 @@
from django.core.validators import URLValidator, FileExtensionValidator
from django.db import models
# Create your models here.
class User(models.Model):
pass
@@ -11,11 +11,15 @@ class Icon(models.Model):
class Feed(models.Model):
url = models.CharField(max_length=100)
url = models.TextField(blank=False, null=False, validators=[URLValidator(['http', 'https'])])
active = models.BooleanField()
icon = models.FileField(upload_to='feed-icons', blank=True, null=True,
validators=[FileExtensionValidator(['png', 'svg'])])
keywords = models.TextField(blank=False, null=False)
class FeedEntry(models.Model):
feed = models.ForeignKey(Feed, on_delete=models.CASCADE)
tweeted = models.BooleanField()
@@ -23,4 +27,4 @@ class Tweet(models.Model):
icon = models.ForeignKey(Icon, on_delete=models.CASCADE,null=True)
text = models.CharField(max_length=137)
date_time = models.DateTimeField()
url = models.CharField(max_length=100)
url = models.CharField(max_length=100)
+25 -2
View File
@@ -1,3 +1,26 @@
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework.serializers import ModelSerializer
# add serializer here
from app_be.models import Feed
class FeedSerializer(ModelSerializer):
class Meta:
model = Feed
fields = '__all__'
def validate_icon(self, value):
if value is not None and value.size > 10240:
raise ValidationError("Invalid icon: Maximum size is 10KB")
return value
def validate_keywords(self, value):
split = [x.strip() for x in value.split(',')]
if len(split) > 3:
raise ValidationError("Invalid keywords: No more than three entries")
elif len(split) == 0:
raise ValidationError("Invalid keywords: Need at least one entry")
for entry in split:
if len(entry) < 3:
raise ValidationError("Invalid keywords: Keywords have to be of length greater than 2")
return value
+3
View File
@@ -161,6 +161,9 @@ STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, 'static'),
]
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
MEDIA_URL = '/media/'
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
+2 -1
View File
@@ -23,9 +23,10 @@ urlpatterns = [
path('admin/', admin.site.urls),
url(r'^api/login', LoginClass.login),
url(r'^getSixTweets', TwitterClass.getLastSixTweets),
url(r'^getTwelveTweets',TwitterClass.getLastSixTweets)
url(r'^getTwelveTweets', TwitterClass.getLastSixTweets)
]
router = DefaultRouter()
router.register(r'feeds', FeedViewSet, basename='feeds')
urlpatterns.extend(router.urls)
+14 -2
View File
@@ -2,9 +2,14 @@ import logging
from django.http import JsonResponse
from rest_framework.decorators import api_view
from py_jwt_validator import PyJwtValidator, PyJwtException
from rest_framework.decorators import api_view
from rest_framework.viewsets import ModelViewSet
from app_be.models import Feed
from app_be.serializers import FeedSerializer
logger = logging.getLogger(__name__)
@@ -51,8 +56,15 @@ class LoginClass:
return JsonResponse({'user': user_sub}, safe=False, status=200)
class TwitterClass:
@staticmethod
@api_view(['GET'])
def getLastSixTweets():
return JsonResponse({[{"asdf","asdf","sdfasdf","asdf"},{"asdf","asdf","sdfasdf","asdf"}]}, safe=False, status=200)
return JsonResponse({[{"asdf", "asdf", "sdfasdf", "asdf"}, {"asdf", "asdf", "sdfasdf", "asdf"}]}, safe=False,
status=200)
class FeedViewSet(ModelViewSet):
queryset = Feed.objects.all()
serializer_class = FeedSerializer