Esempio n. 1
0
 def test_create_photographer(self):
     UserProfile.objects.create_photographer(**self.user_info)
     photographer = UserProfile.objects.filter(
         user__username=self.user_info['username']).first()
     self.assertTrue(
         get_user_role(photographer.user) ==
         UserProfileGenerator.PHOTOGRAPHER)
Esempio n. 2
0
 def test_create_photographer(self):
     UserProfile.objects.create_photographer(**self.user_info)
     photographer = UserProfile.objects.filter(
         user__username=self.user_info['username']).first()
     self.assertTrue(
         get_user_role(
             photographer.user) == UserProfileGenerator.PHOTOGRAPHER)
Esempio n. 3
0
    def get_object(self):
        _raise_denied_if_has_no_perm(self.request.user, 'see_orders')

        instance = super(OrderView, self).get_object()
        user_role = get_user_role(self.request.user)
        if (user_role not in ('manager', 'superuser') and
                self._is_executors_demo_date(instance)):
            instance.address = self._trim_address(instance.address)
        return instance
Esempio n. 4
0
 def get_serializer(self, *args, **kwargs):
     user_role = get_user_role(self.request.user)
     if (user_role not in ('manager', 'superuser') and
             self._is_executors_demo_date(self.get_object())):
         kwargs.update({'required_fields': [
             'id', 'celebrate_date', 'celebrate_time', 'program', 'duration',
             'address', 'celebrate_place', 'executor_comment',
             'additional_services_executors'
         ]})
     return super(OrderView, self).get_serializer(*args, **kwargs)
Esempio n. 5
0
 def get_serializer(self, *args, **kwargs):
     user_role = get_user_role(self.request.user)
     if user_role not in ('manager', 'superuser'):
         if not self.request.query_params.get('full_data', False):
             kwargs.update({'required_fields': [
                 'id', 'celebrate_date', 'celebrate_time', 'program',
                 'duration', 'is_only_service_executor'
             ]})
     elif self.request.query_params.get('date_range'):
         if not self.request.query_params.get('full_data'):
             kwargs.update({'required_fields': [
                 'client', 'program', 'celebrate_date']})
     return super(OrderListView, self).get_serializer(*args, **kwargs)
Esempio n. 6
0
    def _user_fields_initial(self, user):
        from orders_manager.models import User

        if isinstance(user, User):
            user = user.profile

        return {
            'first_name': user.get_first_name(),
            'last_name': user.get_last_name(),
            'phone': user.get_phone(),
            'address': user.get_address(),
            'role': get_user_role(user.user).get_name()
        }
Esempio n. 7
0
    def _user_fields_initial(self, user):
        from orders_manager.models import User

        if isinstance(user, User):
            user = user.profile

        return {
            'first_name': user.get_first_name(),
            'last_name': user.get_last_name(),
            'phone': user.get_phone(),
            'address': user.get_address(),
            'role': get_user_role(user.user).get_name()
        }
Esempio n. 8
0
    def get_is_only_service_executor(self, obj):
        from orders_manager.roles import get_user_role

        request = self.context.get('request')
        if request:
            user = request.user
            role = get_user_role(user)
            if role in ['superuser', 'manager']:
                return False
            if user.id not in [i.user.id for i in obj.program_executors.all()]:
                for service_to_executor in obj.additional_services_executors.all():
                    if service_to_executor.executor.user.id == user.id:
                        return True
        return False
Esempio n. 9
0
    def get_is_only_service_executor(self, obj):
        from orders_manager.roles import get_user_role

        request = self.context.get('request')
        if request:
            user = request.user
            role = get_user_role(user)
            if role in ['superuser', 'manager']:
                return False
            if user.id not in [i.user.id for i in obj.program_executors.all()]:
                for service_to_executor in obj.additional_services_executors.all(
                ):
                    if service_to_executor.executor.user.id == user.id:
                        return True
        return False
Esempio n. 10
0
    def test_create_animator(self):
        UserProfile.objects.create_animator(**self.user_info)
        animator = UserProfile.objects.filter(
            user__username=self.user_info['username']).first()
        self.assertEqual(self.user_info.get('username'),
                         animator.get_username())
        self.assertEqual(self.user_info.get('first_name'),
                         animator.get_first_name())
        self.assertEqual(self.user_info.get('last_name'),
                         animator.get_last_name())
        self.assertEqual(self.user_info.get('email'), animator.get_email())
        self.assertEqual(self.user_info.get('phone'), animator.get_phone())
        self.assertEqual(self.user_info.get('address'), animator.get_address())
        self.assertTrue(
            get_user_role(animator.user) == UserProfileGenerator.ANIMATOR)

        for perm in Animator.available_permissions:
            self.assertTrue(animator.user.has_perm('orders_manager.%s' % perm))
Esempio n. 11
0
    def test_create_animator(self):
        UserProfile.objects.create_animator(**self.user_info)
        animator = UserProfile.objects.filter(
            user__username=self.user_info['username']).first()
        self.assertEqual(self.user_info.get('username'),
                         animator.get_username())
        self.assertEqual(self.user_info.get('first_name'),
                         animator.get_first_name())
        self.assertEqual(self.user_info.get('last_name'),
                         animator.get_last_name())
        self.assertEqual(self.user_info.get('email'), animator.get_email())
        self.assertEqual(self.user_info.get('phone'), animator.get_phone())
        self.assertEqual(self.user_info.get('address'), animator.get_address())
        self.assertTrue(
            get_user_role(animator.user) == UserProfileGenerator.ANIMATOR)

        for perm in Animator.available_permissions:
            self.assertTrue(animator.user.has_perm('orders_manager.%s' % perm))
Esempio n. 12
0
    def get_queryset(self):
        import datetime
        from django.db.models import Q

        _raise_denied_if_has_no_perm(self.request.user, 'see_orders')

        user_role = get_user_role(self.request.user)
        if user_role in ('manager', 'superuser'):
            if self.request.query_params.get('date_range'):
                date_range = self.request.query_params.get('date_range')
                if not date_range == 'None':
                    import json
                    date_range = json.loads(date_range)
                    period = (date_range.get('start'), date_range.get('end'))
                    return Order.objects.get_order_list_for_period(*period)
            return Order.objects.all()
        else:
            return Order.objects.filter(
                (
                    Q(program_executors__user_id=self.request.user.id) |
                    Q(additional_services_executors__executor_id=self.request.user.id)
                )
                & Q(celebrate_date__gte=datetime.date.today())
            ).distinct('id')
Esempio n. 13
0
 def test_create_manager(self):
     UserProfile.objects.create_manager(**self.user_info)
     manager = UserProfile.objects.filter(
         user__username=self.user_info['username']).first()
     self.assertTrue(
         get_user_role(manager.user) == UserProfileGenerator.MANAGER)
Esempio n. 14
0
 def get_role_name(self):
     role_code = get_user_role(self.user)
     return {key: val for key, val in ROLES}[role_code]
Esempio n. 15
0
 def test_create_manager(self):
     UserProfile.objects.create_manager(**self.user_info)
     manager = UserProfile.objects.filter(
         user__username=self.user_info['username']).first()
     self.assertTrue(
         get_user_role(manager.user) == UserProfileGenerator.MANAGER)
Esempio n. 16
0
 def get_role_name(self):
     role_code = get_user_role(self.user)
     return {key: val for key, val in ROLES}[role_code]
Esempio n. 17
0
 def get_queryset(self):
     from orders_manager.models import get_user_role
     if get_user_role(self.request.user) in ('manager', 'superuser'):
         return DayOff.objects.all()
     else:
         return self.request.user.profile.days_off.all()