Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sachith Fernando
2020-101
Commits
903fb6f8
Commit
903fb6f8
authored
Dec 29, 2020
by
I.K Seneviratne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Committing the modifications of saving the student lecture video details through REST API.
parent
c465c70a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
8 deletions
+107
-8
FirstApp/api.py
FirstApp/api.py
+33
-5
FirstApp/serializers.py
FirstApp/serializers.py
+65
-0
FirstApp/templates/FirstApp/template.html
FirstApp/templates/FirstApp/template.html
+9
-3
No files found.
FirstApp/api.py
View file @
903fb6f8
...
@@ -140,13 +140,41 @@ class LectureVideoViewSet(APIView):
...
@@ -140,13 +140,41 @@ class LectureVideoViewSet(APIView):
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
def
post
(
self
,
request
):
def
post
(
self
,
request
):
# get the request data
# data = request.data
#
# # retrieve the last lecture video details
# last_lec_video = LectureVideo.objects.order_by('lecture_video_id').last()
# # create the next lecture video id
# new_lecture_video_id = ig.generate_new_id(last_lec_video.lecture_video_id)
#
# # create the new lecture video
# LectureVideo(
# lecture_video_id=new_lecture_video_id,
# lecturer_id=data['lecturer_id'],
# subject_id=data['subject_id'],
# video_name=data['video_name'],
# video_length=data['video_length'],
# date=data['date']
# ).save()
#
# # return the successful response
# return Response({
# "response": "Successfully created",
#
# }, status=status.HTTP_201_CREATED)
serializer
=
LectureVideoSerializer
(
data
=
request
.
data
)
serializer
=
LectureVideoSerializer
(
data
=
request
.
data
)
if
serializer
.
is_valid
(
raise_exception
=
ValueError
):
serializer
.
create
(
validated_data
=
request
.
data
)
serializer
.
create
(
validated_data
=
request
.
data
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
return
Response
(
serializer
.
error_messages
,
# if serializer.is_valid(raise_exception=ValueError):
status
=
status
.
HTTP_400_BAD_REQUEST
)
# serializer.create(validated_data=request.data)
# return Response(serializer.error_messages,
# status=status.HTTP_400_BAD_REQUEST)
# this API will retrieve a lecture video details
# this API will retrieve a lecture video details
...
...
FirstApp/serializers.py
View file @
903fb6f8
...
@@ -18,8 +18,12 @@ there are two fields inside "Meta" class, as follows.
...
@@ -18,8 +18,12 @@ there are two fields inside "Meta" class, as follows.
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
djongo
import
models
from
.MongoModels
import
*
from
.MongoModels
import
*
from
.
models
import
VideoMeta
from
.
models
import
VideoMeta
from
.logic
import
id_generator
as
ig
# from datetime import datetime as dt
import
datetime
# lecture serializer
# lecture serializer
...
@@ -191,6 +195,67 @@ class LectureVideoSerializer(serializers.ModelSerializer):
...
@@ -191,6 +195,67 @@ class LectureVideoSerializer(serializers.ModelSerializer):
fields
=
'__all__'
fields
=
'__all__'
# this method will override the 'create' method
def
create
(
self
,
validated_data
):
lecturer
=
None
subject
=
None
lecturer_data
=
validated_data
.
pop
(
'lecturer'
)
subject_data
=
validated_data
.
pop
(
'subject'
)
# serialize the lecturer data
lecturer
=
Lecturer
.
objects
.
filter
(
id
=
lecturer_data
)
subject
=
Subject
.
objects
.
filter
(
id
=
subject_data
)
# retrieve the last lecture video details
last_lec_video
=
LectureVideo
.
objects
.
order_by
(
'lecture_video_id'
)
.
last
()
# create the next lecture video id
new_lecture_video_id
=
ig
.
generate_new_id
(
last_lec_video
.
lecture_video_id
)
# if both subject and lecturer details are available
if
len
(
lecturer
)
==
1
&
len
(
subject
)
==
1
:
str_video_length
=
validated_data
.
pop
(
'video_length'
)
video_length_parts
=
str_video_length
.
split
(
':'
)
video_length
=
datetime
.
timedelta
(
minutes
=
int
(
video_length_parts
[
0
]),
seconds
=
int
(
video_length_parts
[
1
]),
milliseconds
=
int
(
video_length_parts
[
2
]))
lecture_video
,
created
=
LectureVideo
.
objects
.
update_or_create
(
lecture_video_id
=
new_lecture_video_id
,
lecturer
=
lecturer
[
0
],
subject
=
subject
[
0
],
date
=
validated_data
.
pop
(
'date'
),
video_name
=
validated_data
.
pop
(
'video_name'
),
video_length
=
video_length
)
# faculty_data = validated_data.pop('faculty')
# serialized_faculty = FacultySerializer(data=faculty_data)
#
# if (serialized_faculty.is_valid()):
# # faculty, faculty_created = Faculty.objects.get_or_create(defaults={}, faculty_id=serialized_faculty.data['faculty_id'])
# faculty = Faculty.objects.filter(faculty_id=serialized_faculty.data['faculty_id'])
#
# if (len(faculty) == 1):
# lecturer, created = Lecturer.objects.update_or_create(
# faculty=faculty[0],
# lecturer_id=validated_data.pop('lecturer_id'),
# fname=validated_data.pop('fname'),
# lname=validated_data.pop('lname'),
# email=validated_data.pop('email'),
# telephone=validated_data('telephone')
# )
#
# return lecturer
#
return
lecture_video
return
None
# lecture video time landmarks serializer
# lecture video time landmarks serializer
class
LectureVideoTimeLandmarksSerializer
(
serializers
.
ModelSerializer
):
class
LectureVideoTimeLandmarksSerializer
(
serializers
.
ModelSerializer
):
...
...
FirstApp/templates/FirstApp/template.html
View file @
903fb6f8
...
@@ -49,15 +49,21 @@
...
@@ -49,15 +49,21 @@
{#
<div
class=
"sidebar-brand-icon rotate-n-15"
>
#}
{#
<div
class=
"sidebar-brand-icon rotate-n-15"
>
#}
{#
<i
class=
"fas fa-laugh-wink"
></i>
#}
{#
<i
class=
"fas fa-laugh-wink"
></i>
#}
{#
</div>
#}
{#
</div>
#}
{#
<div
class=
"sidebar-brand-icon"
>
#}
{#
<i
class=
"fas fa-chalkboard-teacher"
></i>
#}
{#
</div>
#}
{% if request.session.user_type == "Lecturer" %}
<div
class=
"sidebar-brand-icon"
>
<div
class=
"sidebar-brand-icon"
>
<i
class=
"fas fa-chalkboard-teacher"
></i>
<i
class=
"fas fa-chalkboard-teacher"
></i>
</div>
</div>
{% if request.session.user_type == "Lecturer" %}
<div
class=
"sidebar-brand-text mx-3"
>
SLPES Lecturer
</div>
<div
class=
"sidebar-brand-text mx-3"
>
SLPES Lecturer
</div>
{% endif %}
{% endif %}
{% if request.session.user_type == "Admin" %}
{% if request.session.user_type == "Admin" %}
<div
class=
"sidebar-brand-icon"
>
<i
class=
"fa fa-user"
aria-hidden=
"true"
></i>
</div>
<div
class=
"sidebar-brand-text mx-3"
>
SLPES Admin
</div>
<div
class=
"sidebar-brand-text mx-3"
>
SLPES Admin
</div>
{% endif %}
{% endif %}
</a>
</a>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment