Skip to content

Commit

Permalink
[MODIFIED] added video count, course section obj on video
Browse files Browse the repository at this point in the history
  • Loading branch information
vianhazman committed Dec 10, 2019
1 parent 52e9f28 commit a76225f
Show file tree
Hide file tree
Showing 25 changed files with 97 additions and 347 deletions.
2 changes: 1 addition & 1 deletion config/nginx/django.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ server {

location /static/ {
autoindex on;
alias /contentcs_service/staticfiles/;
alias /static/;
}

location /media/ {
Expand Down
2 changes: 1 addition & 1 deletion contentcs_service/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
# Heroku
STATIC_URL = '/static/'
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT= os.path.join(PROJECT_ROOT,'staticfiles/')
STATIC_ROOT= os.path.join(BASE_DIR,'static/')
MEDIA_URL = '/src/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Expand Down
46 changes: 0 additions & 46 deletions objects/migrations/0001_initial.py

This file was deleted.

28 changes: 0 additions & 28 deletions objects/migrations/0002_auto_20191005_1036.py

This file was deleted.

18 changes: 0 additions & 18 deletions objects/migrations/0003_auto_20191012_0807.py

This file was deleted.

18 changes: 0 additions & 18 deletions objects/migrations/0004_auto_20191012_0820.py

This file was deleted.

18 changes: 0 additions & 18 deletions objects/migrations/0005_auto_20191012_1116.py

This file was deleted.

31 changes: 0 additions & 31 deletions objects/migrations/0006_auto_20191103_1344.py

This file was deleted.

30 changes: 0 additions & 30 deletions objects/migrations/0007_auto_20191103_1345.py

This file was deleted.

24 changes: 0 additions & 24 deletions objects/migrations/0008_auto_20191111_0917.py

This file was deleted.

30 changes: 0 additions & 30 deletions objects/migrations/0009_auto_20191111_1606.py

This file was deleted.

Empty file removed objects/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
48 changes: 9 additions & 39 deletions objects/serializers.py → objects/serializers/course.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,27 @@
from rest_framework import serializers

from objects.serializers.section import SectionSerializer
from userauth.models import UserProfile
from .models import Course, Section, Video
from objects.models import Course, Section, Video
from userauth.serializers import UserProfileSerializers
from django.forms.models import model_to_dict
from userauth.constants import getAdminUser

class VideoSerializer(serializers.ModelSerializer):

created_by_profile = serializers.SerializerMethodField('handle_admin', read_only=True)

def handle_admin(self, obj):
user = UserProfile.objects.filter(user=obj.created_by)
if user.count() == 1:
return UserProfileSerializers(user[0]).data
return getAdminUser(obj.created_by.id)

class Meta:
model = Video
fields = '__all__'

def create(self, validated_data):
return Video.objects.create(**validated_data)


class SectionSerializer(serializers.ModelSerializer):
videos = VideoSerializer(many=True, read_only=True, allow_null=True)
created_by_profile = serializers.SerializerMethodField('handle_admin', read_only=True)

def handle_admin(self, obj):
user = UserProfile.objects.filter(user=obj.created_by)
if user.count() == 1:
return UserProfileSerializers(user[0]).data
return getAdminUser(obj.created_by.id)

class Meta:
model = Section
fields = '__all__'

def create(self, validated_data):
return Section.objects.create(**validated_data)
from django.shortcuts import get_list_or_404, get_object_or_404

class CourseSerializer(serializers.ModelSerializer):
created_by_profile = serializers.SerializerMethodField('handle_admin',read_only=True)
no_of_videos = serializers.SerializerMethodField('get_video_count',read_only=True)

def handle_admin(self, obj):
user = UserProfile.objects.filter(user=obj.created_by)
if user.count() == 1:
return UserProfileSerializers(user[0]).data
return getAdminUser(obj.created_by.id)

def get_video_count(self,obj):
section = obj.sections.all()
count = sum([i.videos.count() for i in section])
return count
class Meta:
model = Course
fields = '__all__'
Expand All @@ -72,6 +44,4 @@ class Meta:
fields = '__all__'

def create(self, validated_data):
return Course.objects.create(**validated_data)


return Course.objects.create(**validated_data)
24 changes: 24 additions & 0 deletions objects/serializers/section.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from rest_framework import serializers

from objects.serializers.video import VideoSerializer
from userauth.models import UserProfile
from objects.models import Section
from userauth.serializers import UserProfileSerializers
from userauth.constants import getAdminUser

class SectionSerializer(serializers.ModelSerializer):
videos = VideoSerializer(many=True, read_only=True, allow_null=True)
created_by_profile = serializers.SerializerMethodField('handle_admin', read_only=True)

def handle_admin(self, obj):
user = UserProfile.objects.filter(user=obj.created_by)
if user.count() == 1:
return UserProfileSerializers(user[0]).data
return getAdminUser(obj.created_by.id)

class Meta:
model = Section
fields = '__all__'

def create(self, validated_data):
return Section.objects.create(**validated_data)
Loading

0 comments on commit a76225f

Please sign in to comment.