def get_serpy_type(model_field_type): model_serpy_map = { models.AutoField: serpy.IntField(required=False), models.BigIntegerField: serpy.IntField(required=False), models.BooleanField: serpy.BoolField(required=False), models.CharField: serpy.StrField(required=False), models.CommaSeparatedIntegerField: serpy.StrField(required=False), models.DateField: serpy.StrField(required=False), models.DateTimeField: serpy.StrField(required=False), models.DecimalField: serpy.FloatField(required=False), models.EmailField: serpy.StrField(required=False), models.Field: serpy.StrField(required=False), models.FileField: serpy.StrField(required=False), models.FloatField: serpy.FloatField(required=False), models.ImageField: serpy.StrField(required=False), models.IntegerField: serpy.IntField(required=False), models.NullBooleanField: serpy.StrField(required=False), models.PositiveIntegerField: serpy.IntField(required=False), models.PositiveSmallIntegerField: serpy.IntField(required=False), models.SlugField: serpy.StrField(required=False), models.SmallIntegerField: serpy.IntField(required=False), models.TextField: serpy.StrField(required=False), models.TimeField: serpy.StrField(required=False), models.URLField: serpy.StrField(required=False), models.GenericIPAddressField: serpy.StrField(required=False), models.FilePathField: serpy.StrField(required=False), models.ForeignKey: ForeignKeyField(), models.fields.reverse_related.ManyToOneRel: ForeignKeyField(), models.OneToOneField: ForeignKeyField(), models.fields.related.ManyToManyField: ForeignKeyField(), JSONField: serpy.StrField(required=False), } return model_serpy_map[model_field_type]
class MetricSerializer_Mapping(MetricSerializer): num_pos = serpy.IntField(required=False) num_maps = serpy.IntField(required=False) num_unmaps = serpy.IntField(required=False) median_cov = serpy.FloatField(required=False) mean_cov = serpy.FloatField(required=False) pc_pos_cov_gte10 = serpy.FloatField(required=False) pc_pos_cov_gte20 = serpy.FloatField(required=False)
class AnimalCaseSerializer(serpy.Serializer): case_count = serpy.IntField() disease = serpy.MethodField() district = serpy.StrField() village = serpy.StrField() morbidity_rate = serpy.FloatField() mortality_rate = serpy.FloatField() fatality_rate = serpy.FloatField() def get_disease(self, obj): return {'name': obj.disease.name, 'urgent': obj.disease.urgent}
class TimeCardsSerializer(serpy.Serializer): id = serpy.IntField() entry_date = CustomDateField() time_in = CustomTimeField() time_out = CustomTimeField() break_time = CustomTimeField() total_time = CustomTimeField() pay = serpy.FloatField()
class SerpyProductSerializer(serpy.Serializer): seller = serpy.StrField() category = serpy.StrField() title = serpy.StrField() price = serpy.FloatField() image = serpy.StrField() description = serpy.StrField() quantity = serpy.IntField() views = serpy.IntField()
class VehicleSalesSerializer(serpy.Serializer): seller_id = serpy.IntField() seller_type = serpy.Field() buyer_id = serpy.IntField() buyer_type = serpy.Field() car_class = serpy.Field() vin = serpy.Field() price = serpy.FloatField() created_at = serpy.Field() id = serpy.IntField() car_class = serpy.MethodField() def get_car_class(self, obj): serialized = CarClassSerializer(obj.car_class) return serialized.data
class CourseSerializer(serpy.Serializer): registrar_id = serpy.StrField() title = serpy.StrField() deptnum = serpy.StrField() rating = serpy.FloatField() # evals = serpy.Field() # removed to avoid serializing description = serpy.StrField() assgts = serpy.StrField() grading = serpy.StrField() prereqs = serpy.StrField() otherinfo = serpy.StrField() otherreq = serpy.StrField() professors = serpy.StrField() area = serpy.StrField() pages = serpy.IntField() pdfable = serpy.BoolField() pdfonly = serpy.BoolField() auditable = serpy.BoolField() pdfaudit = serpy.StrField() meetings = MeetingSerializer(many=True, attr="meetings.all", call=True)
class WagesSerializer(serpy.Serializer): id = serpy.IntField() wage = serpy.FloatField() increase_date = CustomDateFieldTwo() last_date = CustomDateFieldTwo()
class ReviewSerializer(serpy.Serializer): comment = serpy.StrField() score = serpy.FloatField() source = serpy.StrField()
class MetricSerializer_ThresholdCycle(MetricSerializer): min_ct = serpy.FloatField(required=False) max_ct = serpy.FloatField(required=False) records = MetricSerializer_ThresholdCycleRecord(attr='metric_records.all', many=True, call=True)
class MetricSerializer_ThresholdCycleRecord(serpy.Serializer): ct_value = serpy.FloatField(required=False) test_platform = serpy.StrField(required=False) test_target = serpy.StrField(required=False) test_kit = serpy.StrField(required=False)
class HumanCaseSerializer(serpy.Serializer): case_count = serpy.IntField() disease = serpy.MethodField() hospitalization_avg = serpy.FloatField() sampling_avg = serpy.FloatField() laboratory_avg = serpy.FloatField() report_avg = serpy.FloatField() treatment_avg = serpy.FloatField() district = serpy.StrField() village = serpy.StrField() min_age = serpy.FloatField() max_age = serpy.FloatField() age_avg = serpy.FloatField() vaccination_rate = serpy.FloatField() death_rate = serpy.FloatField() recovery_rate = serpy.FloatField() sequela_rate = serpy.FloatField() attack_rate = serpy.FloatField() def get_disease(self, obj): return {'name': obj.disease.name, 'urgent': obj.disease.urgent}