Пример #1
0
class UserSerializer(Serializer):
    id = IntField(required=True)
    name = StrField(required=True)
    email = StrField(required=True)
    github_username = StrField(required=True)
    image = StrField(required=True)
    global_gems = IntField(required=True)
    last_seen = MethodField("serialize_last_seen")

    def serialize_last_seen(self, user):
        if not user.last_seen:
            return None
        return user.last_seen.isoformat()
Пример #2
0
class ClassroomSerializer(Serializer):
    id = IntField(required=True)
    name = StrField(required=True)
    date_start = StrField(required=True)
    date_end = StrField(required=True)
    class_code = StrField(required=True)
    teacher = MethodField("serialize_teacher")
    students = MethodField("serialize_students")
    modules = MethodField("serialize_modules")

    def serialize_teacher(self, classroom):
        if not classroom.teacher:
            return {}
        return {"id": classroom.teacher_id}

    def serialize_students(self, classroom):
        if not classroom.students:
            return []
        return student_schemas.StudentRelSerializer(classroom.students,
                                                    many=True).data

    def serialize_modules(self, classroom):
        if not classroom.modules:
            return []
        return [("id", module.id) for module in classroom.modules]
Пример #3
0
class TeacherSerializer(Serializer):
    id = IntField(required=True)
    classrooms = MethodField("serialize_classrooms")

    def serialize_classrooms(self, teacher):
        if not teacher.classrooms:
            return []
        return ClassroomSerializer(teacher.classrooms, many=True).data
Пример #4
0
class OrderLineSerializer(Serializer):
    # destination_code references an address from the Addresses collection
    line_number = IntField(label='LineNo')
    destination_code = IntField(label='DestinationCode')
    origin_code = IntField(label='OriginCode')
    # not required by avalara but I think this should be required for us
    item_code = NullableStrField(label='ItemCode')
    tax_code = NullableStrField(label='TaxCode')
    customer_usage_type = NullableStrField(label='CustomerUsageType')
    business_identification_number = NullableStrField(
        label='BusinessIdentificationNo', )
    description = NullableStrField(label='Description')
    qty = IntField(label='Qty')
    amount = DecimalField(label='Amount')
    discounted = BoolField(label='Discounted')
    tax_included = BoolField(label='TaxIncluded')
    ref_1 = NullableStrField(label='Ref1')
    ref_2 = NullableStrField(label='Ref2')
Пример #5
0
class TopicSerializer(Serializer):
    id = IntField(required=True)
    name = StrField(required=True)
    description = StrField(required=True)
    image = StrField(required=True)
    modules = MethodField("module_serializer")

    def module_serializer(self, topic):
        if not topic.modules:
            return []
        return [{"id": module.id} for module in topic.modules]
Пример #6
0
class AddressSerializer(Serializer):
    address_code = IntField(label='AddressCode')
    address1 = NullableStrField(label='Line1')
    address2 = NullableStrField(label='Line2')
    address3 = NullableStrField(label='Line3')
    # City name, required unless PostalCode is specified and/or Latitude and Longitude are provided.
    city = NullableStrField(label='City')
    # State, province, or region name. Required unless City is specified and/or Latitude and Longitude are provided. length 3
    state = NullableStrField(label='Region')
    # Country code. If not provided, will default to 'US'.  Max. Length: 2
    country = NullableStrField(label='Country')
    # Postal or ZIP code, Required unless City and Region are specified, and/or Latitude and Longitude are provided. length 11
    postal_code = NullableStrField(label='PostalCode')
    latitude = DecimalField(label='Latitude')
    longitude = DecimalField(label='Longitude')
    tax_region_id = DecimalField(label='TaxRegionId')
Пример #7
0
class ActivityProgressSubmissionSerializer(Serializer):
    student_id = IntField(required=True)
    user_id = MethodField("serialized_user_id")
    activity = ActivityRelSerializer()
    checkpoints = MethodField("serialize_checkpoints")

    def serialize_checkpoints(self, activity_prog):
        if not activity_prog:
            return []
        return CheckpointProgressSerializer(activity_prog.checkpoints,
                                            many=True).data

    def serialized_user_id(self, actvity_prog):
        if not actvity_prog:
            return None
        return actvity_prog.student.meta.user.id
Пример #8
0
class MetaSerializer(Serializer):
    id = IntField(required=True, label="meta_id")
    roles = StrField(required=True)
    user_id = MethodField("serialize_user")
    student_id = MethodField("serialize_student")
    teacher_id = MethodField("serialize_teacher")

    def serialize_user(self, meta):
        if not meta.user:
            return None
        return meta.user.id

    def serialize_student(self, meta):
        if not meta.student:
            return None
        return meta.student.id

    def serialize_teacher(self, meta):
        if not meta.teacher:
            return None
        return meta.teacher.id
Пример #9
0
class StudentSerializer(Serializer):
    id = IntField(required=True)
    classes = MethodField("serialize_classes", attr="classrooms")
    current_activities = MethodField("serialize_current_activities")
    completed_modules = MethodField("serialize_completed_modules")
    inprogress_modules = MethodField("serialize_inprogress_modules")
    incomplete_modules = MethodField("serialize_incomplete_modules")

    def serialize_classes(self, student):
        if not student.classes:
            return []
        return class_schemas.ClassroomRelSerializer(student.classes,
                                                    many=True).data

    def serialize_current_activities(self, student):
        if not student.current_activities:
            return []
        return activity_schemas.ActivityRelSerializer(
            student.current_activities, many=True).data

    def serialize_completed_modules(self, student):
        if not student.completed_modules:
            return []
        return module_schemas.ModuleRelSerializer(student.completed_modules,
                                                  many=True).data

    def serialize_inprogress_modules(self, student):
        if not student.inprogress_modules:
            return []
        return module_schemas.ModuleRelSerializer(student.inprogress_modules,
                                                  many=True).data

    def serialize_incomplete_modules(self, student):
        if not student.incomplete_modules:
            return []
        return module_schemas.ModuleRelSerializer(student.incomplete_modules,
                                                  many=True).data
Пример #10
0
class ModuleRelSerializer(Serializer):
    id = IntField(required=True)
    name = StrField(required=True)
Пример #11
0
class StudentRelSerializer(Serializer):
    id = IntField(required=True)
Пример #12
0
class CheckpointRelSerializer(Serializer):
    id = IntField(required=True)
Пример #13
0
class CardSerializer(Serializer):
    id = IntField(required=True)
Пример #14
0
class ClassroomRelSerializer(Serializer):
    id = IntField(required=True)