from rest_framework import serializers from baselabwatch.models import School from logger.models import Kiosk, PollQuestion, PollChoice from baselabwatch.util.urls import URLResolution resolution = URLResolution(School) resolution2 = URLResolution(Kiosk) class KioskSerializer(serializers.HyperlinkedModelSerializer): "Serializer for profile." school = serializers.HyperlinkedRelatedField( source="school.pk", view_name=resolution.resolve('school-detail'), read_only=True) name = serializers.CharField(help_text="Kiosk Title") auth_code = serializers.CharField( label="Kiosk Code", help_text="A code for quick kiosk access", read_only=True) poll_pk = serializers.HyperlinkedRelatedField( source='poll.pk', view_name=resolution2.resolve('pollquestion-detail'), read_only=True) poll_question = serializers.CharField(source='poll.question_text', label="Poll Question", read_only=True) tb_formatted_pollchoices = serializers.SerializerMethodField( read_only=True) # PrimaryKeyRelatedField(source="poll.pollchoice_set", many=True, queryset=PollChoice.objects.all())
from baselabwatch.models import Student, School from rest_framework import serializers from baselabwatch.util.urls import URLResolution from baselabwatch.util import sanitize_name from rest_framework.validators import UniqueValidator resolution = URLResolution(Student) class StudentSerializer(serializers.HyperlinkedModelSerializer): "Serializer for user." url = serializers.HyperlinkedIdentityField( view_name=resolution.resolve('student-detail')) school = serializers.HyperlinkedRelatedField( source="school.pk", view_name=resolution.resolve('school-detail'), read_only=True) student_id = serializers.IntegerField( label='Student ID', help_text='A unique numerical student identifier.', validators=[UniqueValidator(queryset=Student.objects.all())]) nick_name = serializers.CharField( help_text= 'Should the user forget his/her ID, they can alternatively type in a username or nickname.', style={'placeholder': 'e.g. pengrnor000'}, required=False) class Meta: model = Student fields = ( 'url',
from rest_framework import serializers from baselabwatch.models import School from logger.models import ImageCard from baselabwatch.util.urls import URLResolution resolution = URLResolution(School) class ImageCardSerializer(serializers.HyperlinkedModelSerializer): "Serializer for profile." school = serializers.HyperlinkedRelatedField( source="school.pk", view_name=resolution.resolve('school-detail'), queryset=School.objects.all()) class Meta: model = ImageCard fields = ('school', 'image', 'source')
from django.contrib.auth.models import User from rest_framework import serializers from baselabwatch.models import Profile from baselabwatch.util.urls import URLResolution resolution = URLResolution(Profile) class UserSerializer(serializers.HyperlinkedModelSerializer): "Serializer for user." url = serializers.HyperlinkedIdentityField(view_name=resolution.resolve('user-detail')) profile = serializers.HyperlinkedRelatedField(source="profile.pk", view_name=resolution.resolve('profile-detail'), read_only=True) is_staff = serializers.BooleanField(read_only=True) class Meta: model = User fields = ( 'url', 'username', 'email', 'is_staff', 'profile', )
from baselabwatch.models import Subscription, School from rest_framework import serializers from baselabwatch.util.urls import URLResolution resolution = URLResolution(Subscription) class SubscriptionSerializer(serializers.HyperlinkedModelSerializer): "Serializer for user." url = serializers.HyperlinkedIdentityField(view_name=resolution.resolve("subscription-detail")) school = serializers.HyperlinkedRelatedField(source="school.pk", view_name=resolution.resolve('school-detail'), read_only=True) current_student_ids = serializers.IntegerField(read_only=True) class Meta: model = Subscription fields = ( 'url', 'school', 'expires', 'billing_cycle', 'max_student_ids', 'current_student_ids', 'max_kiosks', 'max_logs', 'student_rewards', 'data_intel', 'percentage_discount', 'numeric_discount' )
from django.contrib.auth.models import User from rest_framework import serializers from logger.models import PollQuestion, PollChoice from baselabwatch.util.urls import URLResolution resolution = URLResolution(PollQuestion) class PollQuestionSerializer(serializers.HyperlinkedModelSerializer): "Serializer for poll questions." class Meta: model = PollQuestion fields = ('pk', 'question_text') class PollChoiceSerializer(serializers.HyperlinkedModelSerializer): "Serializer of poll choices" question = serializers.HyperlinkedRelatedField( source="question.pk", view_name=resolution.resolve("pollquestion-detail"), queryset=PollQuestion.objects.all()) class Meta: model = PollChoice fields = ('pk', 'question', 'choice_text', 'votes')
from rest_framework import serializers from baselabwatch.models import Student from logger.models import StudentSession from baselabwatch.util.urls import URLResolution resolution = URLResolution(StudentSession) resolution2 = URLResolution(Student) class StudentSessionSerializer(serializers.HyperlinkedModelSerializer): "Serializer for profile." url = serializers.HyperlinkedIdentityField( view_name=resolution.resolve('session-detail')) student = serializers.HyperlinkedRelatedField( source="student.pk", view_name=resolution2.resolve('student-detail'), read_only=True) student_id = serializers.IntegerField(source='student.student_id', read_only=True) first_name = serializers.CharField(source='student.first_name', read_only=True) last_name = serializers.CharField(source='student.last_name', read_only=True) teacher = serializers.CharField(source='student.teacher', read_only=True) grade = serializers.CharField(source='student.grade', read_only=True) class Meta: model = StudentSession fields = ( 'url',