Пример #1
0
 class Meta:
     model = PurchaseOrder
     company = CompanySerializer()
     product = ProductSerializer(read_only=True)
     fields = [
         'id', 'po', 'companyName', 'productname', 'quantity', 'totalPrice'
     ]
class EmployerSerializer(serializers.ModelSerializer):
    user = UserPublicSerializer(read_only=True)
    company = CompanySerializer(read_only=True)

    class Meta:
        model = Employer
        fields = '__all__'
Пример #3
0
class VacancySerializer(serializers.ModelSerializer):
    company_id = serializers.IntegerField(write_only=True)
    experience_type_id = serializers.IntegerField(write_only=True)
    business_type_id = serializers.IntegerField(write_only=True)

    company = CompanySerializer(read_only=True)
    experience_type = ExperienceTypeSerializer(read_only=True)
    business_type = BusinessTypeSerializer(read_only=True)
    responsibilities = ResponsibilitySerializer(read_only=True, many=True)
    requirements = RequirementSerializer(read_only=True, many=True)
    conditions = ConditionSerializer(read_only=True, many=True)

    class Meta:
        model = Vacancy
        fields = (
            'id',
            'name',
            'experience_type_id',
            'experience_type',
            'business_type_id',
            'business_type',
            'responsibilities',
            'requirements',
            'conditions',
            'company_id',
            'company',
        )
class OwnerSerializer(ModelSerializer):
    companies = CompanySerializer(many=True, required=False)

    class Meta:
        model = OwnerModel
        fields = ['id', 'name', 'surname', 'capital', 'email', 'password',  'is_superuser',
                  'companies']
        extra_kwargs = {
            'id': {'read_only': True},
            'is_superuser': {'read_only': True}
        }

    def create(self, validated_data):
        owner = OwnerModel.objects.create_standard_owner(**validated_data)
        owner.save()
        return owner

    def update(self, instance, validated_data):
        instance.name = validated_data.get('name', instance.name)
        instance.surname = validated_data.get('surname', instance.surname)
        instance.capital = validated_data.get('capital', instance.capital)
        instance.email = validated_data.get('email', instance.email)
        new_password = validated_data.get('password')
        if new_password:
            instance.set_password(new_password)
        instance.save()
        return instance
Пример #5
0
    def list(self, request, *args, **kwargs):

        queryset = self.filter_queryset(self.get_queryset())

        serializer = self.get_serializer(queryset, many=True)

        data = serializer.data

        # Attempt to add extra context information to the historical data
        for item in data:
            deltas = item['deltas']

            if not deltas:
                deltas = {}

            # Add location detail
            if 'location' in deltas:
                try:
                    location = StockLocation.objects.get(pk=deltas['location'])
                    serializer = StockSerializers.LocationSerializer(location)
                    deltas['location_detail'] = serializer.data
                except:
                    pass

            # Add stockitem detail
            if 'stockitem' in deltas:
                try:
                    stockitem = StockItem.objects.get(pk=deltas['stockitem'])
                    serializer = StockSerializers.StockItemSerializer(
                        stockitem)
                    deltas['stockitem_detail'] = serializer.data
                except:
                    pass

            # Add customer detail
            if 'customer' in deltas:
                try:
                    customer = Company.objects.get(pk=deltas['customer'])
                    serializer = CompanySerializer(customer)
                    deltas['customer_detail'] = serializer.data
                except:
                    pass

            # Add purchaseorder detail
            if 'purchaseorder' in deltas:
                try:
                    order = PurchaseOrder.objects.get(
                        pk=deltas['purchaseorder'])
                    serializer = POSerializer(order)
                    deltas['purchaseorder_detail'] = serializer.data
                except:
                    pass

        if request.is_ajax():
            return JsonResponse(data, safe=False)
        else:
            return Response(data)
class RecordSalaryEmployeeSerializer(serializers.ModelSerializer):
    user = UserLimitedSerializer()
    company = CompanySerializer()
    report = ReportSerializer()

    class Meta:
        model = Record
        fields = [
            'user', 'id', 'date_paid', 'payperiod_start', 'payperiod_end',
            'company', 'report'
        ]
Пример #7
0
class PositionDetailSerializer(serializers.ModelSerializer):
    # job = JobPositionSerializer(many=False, read_only=False)
    state = StateSerializer(many=False, read_only=True)
    country = CountrySerializer(many=False, read_only=True)
    company = CompanySerializer(many=False, read_only=True)

    def create(self, validated_data):
        return PositionDetail.objects.create(**validated_data)

    class Meta:
        model = PositionDetail
        fields = ('__all__')
class UserProfileTypeSerializer(serializers.ModelSerializer):
    registration = RegistrationProfileTypeSerializer()
    company = CompanySerializer()
    salary = SalarySerializer()

    class Meta:
        model = User
        fields = [
            'salary', 'company', 'registration', 'id', 'email', 'first_name',
            'last_name', 'bank_name', 'ahv', 'iban', 'house_number', 'street',
            'city', 'postal_code', 'country', 'phone'
        ]
Пример #9
0
class UserProfileSerializer(serializers.ModelSerializer):
    department = DepartmentSerializer(read_only=True)
    company = CompanySerializer(read_only=True)

    #avatar = serializers.ImageField(validators=[validate_image])

    class Meta:
        model = User
        fields = [
            'id', 'username', 'email', 'parent', 'company', 'department',
            'status', 'conference', 'first_name', 'last_name', 'midname',
            'phone', 'last_seen', 'city', 'avatar', 'is_active', 'is_staff'
        ]
Пример #10
0
class OrderReadSerializer(serializers.ModelSerializer):
    # situation = serializers.SerializerMethodField()
    company = CompanySerializer(read_only=True)
    address = AddressSerializer(read_only=True)
    items = ProductItemSerializer(many=True, read_only=True)

    class Meta:
        model = Order
        depth = 1
        fields = ('id', 'user', 'company', 'billing_name', 'billing_number',
                  'billing_cpf', 'billing_expiration', 'billing_cvc',
                  'situation', 'payment_type', 'total', 'status', 'address',
                  'items', 'purchase_time')
Пример #11
0
class UserSerializer(ModelSerializer):
    companies = CompanySerializer(many=True, required=False)

    class Meta:
        model = UserModel
        fields = [
            'id', 'email', 'password', 'is_superuser', 'is_staff', 'is_active',
            'companies'
        ]
        extra_kwargs = {'password': {'write_only': True}}

    def create(self, validated_data):
        user = UserModel.objects.create_user(**validated_data)
        return user
Пример #12
0
class EmployeeSerializer(ModelSerializer):
    company = CompanySerializer(many=True, required=False)

    class Meta:
        model = EmployeeModel
        fields = [
            'id', 'email', 'password', 'name', 'surname', 'age', 'profession',
            'company'
        ]
        extra_kwargs = {'password': {'write_only': True}}

    def create(self, validated_data):

        employee = EmployeeModel.objects.create_employee(**validated_data)
        return employee
Пример #13
0
class ScholarshipSerializer(serializers.ModelSerializer):
    company = CompanySerializer(read_only=True)
    accepted_degrees = DegreeSerializer(read_only=True, many=True)
    tags = TagSerializer(read_only=True, many=True)
    is_liked = serializers.SerializerMethodField()

    def get_is_liked(self, obj):
        user = None
        request = self.context.get("request")
        if request and hasattr(request, "user"):
            user = request.user
        return LikedScholarships.objects.filter(scholarship_id=obj.id,
                                                candidate__user=user).exists()

    class Meta:
        model = ScholarshipPost
        fields = '__all__'
Пример #14
0
def company_list(request):
    """
    List all companies or create a new company
    """
    if request.method == 'GET':
        company = Company.objects.all()
        serializer = CompanySerializer(company, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = CompanySerializer(data=request.data)
        if serializer.is_valid():
            print('$$$$$$$')
            serializer.save()
            print('$$$$$$$$$$', serializer)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #15
0
class UserCreateSerializer(ModelSerializer):

    company = CompanySerializer()
    full_name = CharField(label=_('Full Name'), max_length=255)

    class Meta:
        model = User
        fields = (
            'id',
            'full_name',
            'phone',
            'email',
            'password',
            'company',
        )
        read_only_fields = ('id', )

    def create_client(self, user, company):
        Client.objects.create(user=user, company=company)

    def create(self, validated_data):

        company_data = validated_data.pop('company')
        company = Company.objects.create(**company_data)

        full_name = validated_data.pop('full_name')
        full_name = full_name.split()
        first_name = full_name[0]
        try:
            last_name = full_name[1]
        except IndexError:
            raise ValidationError('Por favor informe seu nome completo')
        phone = validated_data.pop('phone')
        user = User.objects.create_user(**validated_data)
        user.full_name = first_name + ' ' + last_name
        user.first_name = first_name
        user.last_name = last_name
        user.phone = phone
        user.company = company_data
        user.save()
        self.create_client(user, company)
        return user
Пример #16
0
class ProductReadSerializer(serializers.ModelSerializer):
    distance = serializers.SerializerMethodField()
    company = CompanySerializer(read_only=True)

    class Meta:
        model = Product
        depth = 2
        fields = ('id', 'name', 'company', 'price', 'manufacturer',
                  'available', 'obs', 'image', 'active', 'distance')

    def get_distance(self, obj):
        lat = self.context['request'].GET.get('lat')
        lon = self.context['request'].GET.get('lon')
        if lat and lon:
            mobile_point = GEOSGeometry('SRID=4326;POINT(%s %s)' % (lat, lon))
            company_point = GEOSGeometry('SRID=4326;POINT(%s %s)' %
                                         (obj.company.address.location.x,
                                          obj.company.address.location.y))
            distance = mobile_point.distance(company_point) * 100
            return "%.2f" % distance
        return None
Пример #17
0
class JobSerializer(serializers.ModelSerializer):
    company = CompanySerializer(read_only=True)
    accepted_locations = CitySerializer(read_only=True,
                                        many=True,
                                        source='locations')
    degrees = DegreeSerializer(read_only=True,
                               many=True,
                               source='accepted_degrees')
    tags = TagSerializer(read_only=True, many=True)
    is_liked = serializers.SerializerMethodField()

    def get_is_liked(self, obj):
        user = None
        request = self.context.get("request")
        if request and hasattr(request, "user"):
            user = request.user
        return LikedJobs.objects.filter(job_post__id=obj.id,
                                        candidate__user=user).exists()

    class Meta:
        model = JobPost
        exclude = ('locations', 'accepted_degrees')
Пример #18
0
 def get_company_object(self, obj):
     context = self.context
     context['position'] = obj.position
     return CompanySerializer(instance=obj.company_object, many=False, context=context).data
Пример #19
0
def reviews(request):
    body = request.data
    user = request.user
    if 'recaptcha_token' in body and utils.verify_recaptcha(
            user, body['recaptcha_token'],
            'review') == ResponseCodes.verify_recaptcha_failed:
        return JsonResponse(create_response(
            data=None,
            success=False,
            error_code=ResponseCodes.verify_recaptcha_failed),
                            safe=False)
    if request.method == "GET" and user.user_type.name == 'Career Service':
        reviews_list = Review.objects.filter(is_published=False,
                                             is_rejected=False,
                                             user__college=user.college)
        return JsonResponse(create_response(
            data=ReviewSerializer(instance=reviews_list, many=True).data),
                            safe=False)
    elif request.method == "PATCH":
        if request.user.user_type.name == 'Career Service':
            body = request.data
            review = Review.objects.get(pk=body['review_id'])
            approved = body['approved']
            review.is_published = approved
            review.is_rejected = not approved
            review.save()
            return JsonResponse(create_response(data=None), safe=False)
        else:
            return JsonResponse(create_response(
                data=None,
                success=False,
                error_code=ResponseCodes.not_supported_user),
                                safe=False)
    elif request.method == "GET":
        company_id = request.GET.get('company_id')
        position_id = request.GET.get('position_id')
        all_reviews = get_boolean_from_request(request, 'all_reviews')
        review_id = request.GET.get('review_id')
        if review_id is not None:
            reviews_list = Review.objects.filter(pk=review_id,
                                                 user=request.user)
            if reviews_list.count() == 0:
                return JsonResponse(create_response(
                    data=None,
                    success=False,
                    error_code=ResponseCodes.record_not_found),
                                    safe=False)
            return JsonResponse(create_response(data=ReviewSerializer(
                instance=reviews_list[0], many=False).data),
                                safe=False)
        elif company_id is None and position_id is None:
            return JsonResponse(create_response(
                data=None,
                success=False,
                error_code=ResponseCodes.invalid_parameters),
                                safe=False)
        if company_id is None:
            reviews_list = Review.objects.filter(Q(is_published=True)
                                                 | Q(user=request.user),
                                                 position__pk=position_id)
        elif position_id is None:
            reviews_list = Review.objects.filter(Q(is_published=True)
                                                 | Q(user=request.user),
                                                 company__pk=company_id)
        else:
            if all_reviews:
                reviews_list = Review.objects.filter(is_published=True,
                                                     position__pk=position_id,
                                                     company__pk=company_id)
            else:
                reviews_list = Review.objects.filter(user=request.user,
                                                     position__pk=position_id,
                                                     company__pk=company_id)
                if reviews_list.count() > 0:
                    return JsonResponse(create_response(data=ReviewSerializer(
                        instance=reviews_list[0], many=False).data),
                                        safe=False)
                else:
                    return JsonResponse(create_response(data=None), safe=False)
        return JsonResponse(create_response(
            data=ReviewSerializer(instance=reviews_list, many=True).data),
                            safe=False)
    else:
        if 'company_id' not in body or 'position_id' not in body:
            return JsonResponse(create_response(
                data=None,
                success=False,
                error_code=ResponseCodes.invalid_parameters),
                                safe=False)

        company = Company.objects.get(pk=body['company_id'])
        position = JobPosition.objects.get(pk=body['position_id'])
        if request.method == "PUT":
            review = Review.objects.get(pk=body['review_id'])
            if review.user.pk != user.pk:
                return JsonResponse(create_response(
                    data=None,
                    success=False,
                    error_code=ResponseCodes.record_not_found),
                                    safe=False)
            review.update_date = timezone.now()
        elif request.method == "POST":
            review = Review()
        review.company = company
        review.position = position
        review.user = request.user
        if 'pros' in body:
            review.pros = body['pros']
        if 'cons' in body:
            review.cons = body['cons']
        if 'interview_notes' in body:
            review.interview_notes = body['interview_notes']
        if 'overall_company_experience' in body:
            review.overall_company_experience = body[
                'overall_company_experience']
        if 'interview_difficulty' in body:
            review.interview_difficulty = body['interview_difficulty']
        if 'overall_interview_experience' in body:
            review.overall_interview_experience = body[
                'overall_interview_experience']
        if 'anonymous' in body:
            review.anonymous = body['anonymous']
        if 'emp_auths' in body:
            for a in body['emp_auths']:
                if 'value' in a:
                    auth = EmploymentAuth.objects.get(pk=a['id'])
                    review.save()
                    if CompanyEmploymentAuth.objects.filter(
                            review=review, employment_auth=auth).count() == 0:
                        c_auth = CompanyEmploymentAuth(review=review,
                                                       employment_auth=auth,
                                                       value=a['value'])
                        c_auth.save()
                    else:
                        c_auth = CompanyEmploymentAuth.objects.get(
                            review=review, employment_auth=auth)
                        c_auth.value = a['value']
                        c_auth.save()
        if 'emp_status_id' in body:
            review.emp_status = EmploymentStatus.objects.get(
                pk=body['emp_status_id'])
        if 'source_type_id' in body:
            review.source_type = SourceType.objects.get(
                pk=body['source_type_id'])

        # publish review if there is no content to approve
        if 'pros' not in body and 'cons' not in body and 'interview_notes' not in body:
            review.is_published = True
        else:
            review.is_published = False
            send_notification_email_to_admins('review', review.user.college.id)

        review.save()
        response = {
            'review':
            ReviewSerializer(instance=review, many=False).data,
            'company':
            CompanySerializer(instance=company,
                              many=False,
                              context={
                                  'user': request.user,
                                  'position': position
                              }).data
        }
        return JsonResponse(create_response(data=response), safe=False)
Пример #20
0
 def list(self, request, *args, **kwargs):
     queryset = Company.objects.filter(parent=None)
     serializer = CompanySerializer(queryset, many=True)
     return Response(serializer.data)