def create(self, validated_data):
     user = self.context.get('request').user
     employee_data = validated_data.pop('employee')
     if employee_data.get('is_reusable') == True:
         email = employee_data.pop('email')
         employee, created = Employee.objects.get_or_create(user=user,
                                                            email=email,
                                                            is_reusable=True,
                                                            defaults=employee_data)
         if not created:
             for attr, value in employee_data.iteritems():
                 setattr(employee, attr, value)
             employee.save()
             logger.info(_('Update reusable employee'), extra=get_extra(self.context.get('request'),
                                                                        object=employee))
         else:
             logger.info(_('Create reusable employee'), extra=get_extra(self.context.get('request'),
                                                                        object=employee))
     else:
         employee = Employee.objects.create(user=user, **employee_data)
         logger.info(_('Create not reusable employee'), extra=get_extra(self.context.get('request'),
                                                                        object=employee))
     relocation = EmployeeRelocation.objects.create(user=user, employee=employee, **validated_data)
     logger.info(_('Create employee relocation request'), extra=get_extra(self.context.get('request'),
                                                                          object=relocation))
     return relocation
Exemplo n.º 2
0
 def deposite(self, user, licenses, request):
     user_departments = Department.objects.filter(users=user)
     subscriptions = self.model.objects\
         .filter(suspended=False)\
         .filter(payment_date__gte=now())\
         .filter(contract_expired_date__gte=now())\
         .filter(Q(company=user.company) | Q(departments=user_departments))\
         .order_by('-payment_date')\
         .all()
     if not subscriptions:
         raise SubscriptionNotFound
     if sum(map(lambda s: s.assigned, subscriptions)) < licenses:
         raise SubscriptionNotFound
     for subscribe in subscriptions:
         if licenses == 0:
             break
         if subscribe.assigned >= licenses:
             subscribe.assigned -= licenses
             subscribe.save()
             logger.info(_('Deposit %d licenses' % licenses),
                         extra=get_extra(request, object=subscribe))
             break
         else:
             licenses -= subscribe.assigned
             logger.info(_('Deposit %d licenses' % subscribe.assigned),
                         extra=get_extra(request, object=subscribe))
             subscribe.assigned = 0
             subscribe.save()
 def update(self, instance, validated_data):
     password = validated_data.pop('password', None)
     for attr, value in validated_data.iteritems():
         setattr(instance, attr, value)
     logger.info(_('Update user profile'), extra=get_extra(self.context.get('request'),
                                                           object=instance))
     if password:
         instance.set_password(password)
         logger.info(_('Update user password'), extra=get_extra(self.context.get('request'),
                                                                object=instance))
         update_session_auth_hash(self.context.get('request'), instance)
     instance.save()
     return instance
Exemplo n.º 4
0
 def create(self, validated_data):
     request = self.context.get('request')
     user = request.user
     feedback = Feedback.objects.create(user=user, **validated_data)
     logger.info(_('Make feedback'),
                 extra=get_extra(request, object=feedback))
     return feedback
Exemplo n.º 5
0
 def process_response(self, request, response):
     if hasattr(request, 'user') and request.user.is_authenticated():
         if KEEP_ADMIN_LOGS is False:
             if 'admin' in resolve(request.path).namespaces:
                 return response
         logger.info(_('Enter on page'), extra=get_extra(request))
     return response
 def create(self, validated_data):
     user = self.context.get('request').user
     employee = Employee.objects.create(user=user, **validated_data)
     logger.info(_('Create employee'), extra=get_extra(
                                                         self.context.get('request'),
                                                         object=employee)
                                                     )
Exemplo n.º 7
0
 def withdrawal(self, user, licenses, request):
     user_departments = Department.objects.filter(users=user)
     subscriptions = self.model.objects\
         .filter(suspended=False)\
         .filter(payment_date__gte=now())\
         .filter(contract_expired_date__gte=now())\
         .filter(Q(company=user.company) | Q(departments=user_departments))\
         .order_by('payment_date')\
         .all()
     exclude = []
     subscription_have_company = False
     total_available_licenses = 0
     for subscription in subscriptions:
         departments = filter(lambda d: d in user_departments,
                              subscription.departments.all())
         if subscription.company:
             subscription_have_company = True
         for department in departments:
             available_licenses = self.get_available_licenses(subscription, department)
             if subscription.assigned > available_licenses:
                 exclude.append(subscription.pk)
             else:
                 total_available_licenses += (available_licenses - subscription.assigned)
     subscriptions = subscriptions.exclude(pk__in=exclude)
     if not subscriptions:
         raise PaymentRequired
     if total_available_licenses < licenses and not subscription_have_company:
         raise PaymentRequired
     if sum(map(lambda s: s.licenses-s.assigned, subscriptions)) < licenses:
         raise PaymentRequired
     for subscribe in subscriptions:
         if licenses == 0:
             break
         available_licenses = self.get_available_licenses(subscribe)-subscribe.assigned
         if available_licenses >= licenses:
             subscribe.assigned += licenses
             subscribe.save()
             logger.info(_('Wwithdrawal %d licenses' % licenses),
                         extra=get_extra(request, object=subscribe))
             break
         else:
             subscribe.assigned += available_licenses
             subscribe.save()
             licenses -= available_licenses
             logger.info(_('Wwithdrawal %d licenses' % available_licenses),
                         extra=get_extra(request, object=subscribe))
 def update(self, instance, validated_data):
     employee = validated_data.pop('employee')
     # We dont give permission to modify email here
     if employee.get('is_reusable') == True:
         employee.pop('email')
     for attr, value in employee.iteritems():
         setattr(instance.employee, attr, value)
     instance.employee.save()
     for attr, value in validated_data.iteritems():
         setattr(instance, attr, value)
     instance.save()
     logger.info(_('Update employee relocation request'), extra=get_extra(self.context.get('request'),
                                                                          object=instance))
     return instance
 def create(self, validated_data):
     request = self.context.get('request')
     user = request.user
     relocations = EmployeeRelocation.objects.filter(user=user,
         status=EmployeeRelocation.STATUS_CHOICE.INITIAL)
     if not relocations:
         raise NotFound
     # raise PaymentRequired if user didn't have linceses
     Subscription.objects.withdrawal(user, len(relocations), request)
     self.send_email(relocations, user)
     for relocation in relocations:
         logger.info(_('Send relocation request'), extra=get_extra(request,
                                                                   object=relocation))
     relocations.update(status=EmployeeRelocation.STATUS_CHOICE.RECEIVED)
     return relocations
Exemplo n.º 10
0
 def save(self):
     super(PasswordResetConfirmSerializer, self).save()
     user = authenticate(username=self.user.email,
                         password=self.set_password_form.cleaned_data['new_password1'])
     login(self.context.get('request'), user)
     logger.info(_('Password reset confirm'), extra=get_extra(self.context.get('request')))