Skip to content

Commit

Permalink
fix api view teacher courses
Browse files Browse the repository at this point in the history
  • Loading branch information
Re-Krass committed Jun 13, 2018
1 parent e7c088c commit 87bf421
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 433 deletions.
31 changes: 17 additions & 14 deletions djangoblockchained_backend/skbrest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ def create(self, validated_data):
context = {
'user':user.username,
'link':'http://35.185.239.7:2222/api/activate/{}/{}'.format(uid, token),
'expires_in':str(settings.JWT_AUTH['JWT_EXPIRATION_DELTA']) + 'Minutes.',
'logo_img_link':"https://lh3.googleusercontent.com/PL8M-2OhoDITza8WOCdveAax9yQuXzaDakaJHcivO1ZjJg5D1u0eb9gzgx8VSLlfVT4vitIV2GIPkc8OfGJrR6rpko1U8JuV4CAZ2p-gvc4NhVUthlbaEz9HcKwY98UFiwN79pzu=s742-no"
'expires_in':str(settings.JWT_AUTH['JWT_EXPIRATION_DELTA']) + ' Minutes.',
'logo_img_link':"https://lh3.googleusercontent.com/PL8M-2OhoDITza8WOCdveAax9yQuXzaDakaJHcivO1ZjJg5D1u0eb9gzgx8VSLlfVT4vitIV2GIPkc8OfGJrR6rpko1U8JuV4CAZ2p-gvc4NhVUthlbaEz9HcKwY98UFiwN79pzu=s742-no",
'email_sendto':user.email,
'ydl_email':"ydlearning.service@gmail.com",
'ydl_url':"www.ydlearning.ml"
}
html = html_template.render(context)

Expand Down Expand Up @@ -104,24 +107,24 @@ def get_courses(self, obj):
except ObjectDoesNotExist:
pass

if student:
#print("cs", Course.objects.get(id = 1).students.all())
#print("name:", student.user)
#print("stc:", student.course_set.all())
return LongLongSerializer(student).data["course_set"]
#CourseSerializer(student.course_set.all()).data
elif teacher:
return Course.objects.filter(teacher = teacher.id).data
if teacher:
return TeacherSerializer(teacher).data["course_set"]
elif student:
return StudentSerializer(student).data["course_set"] #CourseSerializer(student.course_set.all()).data


class Meta:
model = User
fields = ["username", "first_name", "last_name", "email", "last_login", "date_joined", "courses"]

class LongLongSerializer(serializers.ModelSerializer):
# user = serializers.PrimaryKeyRelatedField(read_only=True)
# user = LongUserSerializer(read_only=True)

class StudentSerializer(serializers.ModelSerializer):

class Meta:
model = Student
fields = ["user", "isEmailActivated", "course_set"]

class TeacherSerializer(serializers.ModelSerializer):

class Meta:
model = Teacher
fields = ["user", "isEmailActivated", "course_set"]
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions djangoblockchained_backend/skbrest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.auth.models import User # If used custom user model
# Our imports
from .models import Course, Student
from .serializers import UserSerializer, CourseSerializer, LongUserSerializer, LongLongSerializer
from .serializers import UserSerializer, CourseSerializer, LongUserSerializer, StudentSerializer

# Email Stuff A
from django.http import HttpResponse
Expand Down Expand Up @@ -84,7 +84,7 @@ def get_queryset(self):

class LonngLongListApiView(ListAPIView):
model = Student
serializer_class = LongLongSerializer
serializer_class = StudentSerializer

queryset = Student.objects.all()

Expand Down

0 comments on commit 87bf421

Please sign in to comment.