Esempio n. 1
0
class SubjectSerializer(rest.ModelSerializer):
    pertain_info = rest.SerializerMethodField()
    last_version = rest.SerializerMethodField()

    def get_last_version(self, obj):
        if obj := obj.versionmanagement_set.all().order_by('-create'):
            return obj.first().version
Esempio n. 2
0
class MonthlyReportSerializer(rest.ModelSerializer):
    submitter = rest.SerializerMethodField()
    department_name = rest.SerializerMethodField()

    def get_department_name(self, obj):
        if obj.person and (department := obj.person.department):
            return department.name
        return ''
Esempio n. 3
0
class DepartmentSerializer(rest.ModelSerializer):
    count = rest.SerializerMethodField()
    leader = rest.SerializerMethodField()
    work_management = rest.SerializerMethodField()
    leader_id = rest.SerializerMethodField()

    def get_leader_id(self, obj):
        if obj := obj.usermodel_set.filter(
                head_of_department__exact=True).first():
            return obj.id
Esempio n. 4
0
class UserSerializerL(rest.ModelSerializer):
    department = rest.SerializerMethodField()
    role = rest.SerializerMethodField()

    def get_department(self, obj):
        if obj.department: return obj.department.name

    def get_role(self, obj):
        if obj := obj.role: return obj.name

    class Meta:
        model = UserModel
        fields = ('id', 'get_full_name', 'username', 'email', 'is_active',
                  'department', 'date_joined', 'role')
Esempio n. 5
0
class ReportSerializer(rest.ModelSerializer):
    person = rest.SerializerMethodField()

    def get_person(self, obj):
        if username := obj.person:
            return f'{username.get_full_name()} ({username.username})'
        return ''
Esempio n. 6
0
class UserSerializerR(rest.ModelSerializer):
    workplace = rest.SerializerMethodField()
    role = rest.IntegerField(source='role_id')

    def get_workplace(self, obj):
        obj = obj.workplace
        if not obj: return ''
        a, b = obj.split('/')
        workplace = get_workplace(f=True)
        return f'{workplace.get(a, {}).get("name")} / {workplace.get(a, {}).get("children", {}).get(b, {}).get("name")}'

    class Meta:
        model = UserModel
        fields = (
            'id',
            'get_full_name',
            'username',
            'email',
            'phone',
            'is_active',
            'department',
            'date_joined',
            'title',
            'workplace',
            'head_of_department',
            'work_management',
            'role',
        )
Esempio n. 7
0
class AtLeaderSerializer(rest.ModelSerializer):
    name = rest.SerializerMethodField()

    def get_name(self, obj):
        return f'{obj.get_full_name()}({obj.username})'

    class Meta:
        model = UserModel
        fields = ('name', 'id')
Esempio n. 8
0
class RoleSerializer(rest.ModelSerializer):
    role = rest.SerializerMethodField(source='role')

    def get_role(self, obj):
        return json.loads(obj.role)

    class Meta:
        model = RoleModel
        fields = ('id', 'role', 'name', 'admin')
        read_only_fields = ('id', 'role', 'admin')
Esempio n. 9
0
class SubmitProcessSerializerL(rest.ModelSerializer):
    organizer = rest.CharField(source='organizer.get_full_name')
    content = rest.SerializerMethodField(read_only=True)
    at_leader = rest.SerializerMethodField(read_only=True)

    def get_at_leader(self, obj):
        result = ''
        for i in UserModel.objects.filter(
                id__in=re.findall(r'"(\d+)"', obj.at_leader)):
            result += (i.get_full_name() + '、')
        return result[:-1]

    def get_content(self, obj):
        result = list()
        for i, value in enumerate(json.loads(obj.content)):
            if user := UserModel.objects.filter(id__exact=value[0]).first():
                username = f'{user.get_full_name()} ({user.username})'
            else:
                username = '******'
            result.append([username, value[1], value[2], i])
        return result