def process_roles(person): """ Get all the roles of a person in convenient list format :param person: the person whose roles are being retrieved :return: the roles of the person as a list """ roles = get_all_roles(person) roles = [{ 'role': key, 'activeStatus': str(roles[key]['activeStatus']), 'data': switcher.load_serializer('kernel', key)(roles[key]['instance'], excluded_fields=[ 'person', ]).data } for key in roles] return roles
class JointFacultySerializer(BaseJointFacultySerializer): """ Serializer for JointFaculty objects """ memberships = switcher.load_serializer('kernel', 'JointFacultyMembership')(many=True) class Meta: """ Meta class for JointFacultySerializer """ model = swapper.load_model('kernel', 'JointFaculty') fields = [ 'id', 'person', 'memberships', 'employee_id', ]
class BiologicalInformationView(generics.RetrieveUpdateAPIView): """ View for RU operations on biological information """ permission_classes = [ permissions.IsAuthenticated, ] serializer_class = load_serializer('kernel', 'BiologicalInformation') def get_object(self): """ Return the biological information of the person currently logged in :return: the biological information of the person currently logged in """ person = self.request.person try: return person.biologicalinformation except AttributeError: raise NotFound( detail='Associated biological information not found.')
import swapper from rest_framework import status, generics, response from omniport.utils import switcher from session_auth.models import SessionMap from session_auth.serializers.login import LoginSerializer Person = swapper.load_model('kernel', 'Person') AvatarSerializer = switcher.load_serializer('kernel', 'Person', 'Avatar') class Login(generics.GenericAPIView): """ This view takes the username and password and if correct, logs the user in via cookie-based session authentication """ serializer_class = LoginSerializer def post(self, request, *args, **kwargs): """ View to serve POST requests :param request: the request that is to be responded to :param args: arguments :param kwargs: keyword arguments :return: the response for request """ # Reject authenticated users, right off the gate if request.user.is_authenticated:
import swapper from formula_one.serializers.base import ModelSerializer from omniport.utils import switcher DegreeSerializer = switcher.load_serializer('kernel', 'Degree') DepartmentSerializer = switcher.load_serializer('kernel', 'Department') class BranchSerializer(ModelSerializer): """ Serializer for Branch objects """ degree = DegreeSerializer( read_only=True, ) department = DepartmentSerializer( read_only=True, ) class Meta: """ Meta class for BranchSerializer """ model = swapper.load_model('kernel', 'Branch') fields = [ 'id', 'code',
import swapper from django.db import ProgrammingError from rest_framework import serializers from formula_one.serializers.base import ModelSerializer from omniport.utils import switcher ResidentialInformation = swapper.load_model('kernel', 'ResidentialInformation') Residence = swapper.load_model('kernel', 'Residence') ResidenceSerializer = switcher.load_serializer('kernel', 'Residence') class ResidentialInformationSerializer(ModelSerializer): """ Serializer for ResidentialInformation objects """ def __init__(self, *args, **kwargs): """ Add the residence ChoiceField on the serializer based on the existence of Residence models :param args: arguments :param kwargs: keyword arguments """ super().__init__(*args, **kwargs) try: residences = Residence.objects.all() except ProgrammingError: residences = list()
import swapper from kernel.serializers.roles.base import RoleSerializer from omniport.utils import switcher BranchSerializer = switcher.load_serializer('kernel', 'Branch') class StudentSerializer(RoleSerializer): """ Serializer for Student objects """ branch = BranchSerializer( read_only=True, ) class Meta: """ Meta class for StudentSerializer """ model = swapper.load_model('kernel', 'Student') fields = [ 'id', 'person', 'branch', 'current_year', 'current_semester', ]
from rest_framework import serializers from omniport.utils import switcher from maintainer_site.models import Hit MaintainerSerializer = switcher.load_serializer('kernel', 'Maintainer') class HitSerializer(serializers.ModelSerializer): """ Serializer for hit model """ maintainer_name = serializers.CharField( source='maintainer_information.maintainer.person.full_name', read_only=True, ) class Meta: """ Meta class for HitSerializer """ model = Hit fields = [ 'maintainer_name', 'maintainer_information', 'views', ] read_only_fields = ['views']