Exemplo n.º 1
0
    def update(self, instance, validated_data):
        """
        Override this function to include extra functionality.
        """
        # For debugging purposes only.
        # print(validated_data)

        #-------------------------------------
        # Bugfix: Created `SharedUser` object.
        #-------------------------------------
        if instance.owner is None:
            owner = SharedUser.objects.filter(email=instance.email).first()
            if owner:
                instance.owner = owner
                instance.save()
                logger.info("BUGFIX: Attached existing shared user to staff.")
            else:
                instance.owner = SharedUser.objects.create(
                    first_name=instance.given_name,
                    last_name=instance.last_name,
                    email=instance.email,
                    is_active=True,
                    franchise=self.context['franchise'],
                    was_email_activated=True
                )
                instance.save()
                logger.info("BUGFIX: Created shared user and attached to staff.")

        # Update the account.
        if instance.email:
            instance.owner.email = instance.email
            instance.owner.username = get_unique_username_from_email(instance.email)
        instance.owner.first_name = validated_data.get('given_name', instance.owner.first_name)
        instance.owner.last_name = validated_data.get('last_name', instance.owner.last_name)
        instance.owner.save()
        logger.info("Updated the shared user.")

        #---------------------------
        # Update `Staff` object.
        #---------------------------
        # Address
        instance.address_country=validated_data.get('address_country', None)
        instance.address_locality=validated_data.get('address_locality', None)
        instance.address_region=validated_data.get('address_region', None)
        instance.post_office_box_number=validated_data.get('post_office_box_number', None)
        instance.postal_code=validated_data.get('postal_code', None)
        instance.street_address=validated_data.get('street_address', None)
        instance.street_address_extra=validated_data.get('street_address_extra', None)

        # Misc
        instance.last_modified_by = self.context['last_modified_by']
        instance.last_modified_from = self.context['last_modified_from']
        instance.last_modified_from_is_public = self.context['last_modified_from_is_public']

        # Save our instance.
        instance.save()
        logger.info("Updated the staff member.")

        # Return our updated object.
        return instance
Exemplo n.º 2
0
    def update(self, instance, validated_data):
        """
        Override this function to include extra functionality.
        """
        # For debugging purposes only.
        # print(validated_data)

        # Get our inputs.
        email = validated_data.get('email', instance.email)
        personal_email = validated_data.get('personal_email', None)

        #-------------------------------------
        # Bugfix: Created `SharedUser` object.
        #-------------------------------------
        if instance.owner is None:
            owner = SharedUser.objects.filter(email=email).first()
            if owner:
                instance.owner = owner
                instance.save()
                logger.info("BUGFIX: Attached existing shared user to staff.")
            else:
                instance.owner = SharedUser.objects.create(
                    first_name=validated_data['given_name'],
                    last_name=validated_data['last_name'],
                    email=email,
                    is_active=validated_data['is_active'],
                    franchise=self.context['franchise'],
                    was_email_activated=True
                )
                instance.save()
                logger.info("BUGFIX: Created shared user and attached to staff.")

        #---------------------------
        # Update `SharedUser` object.
        #---------------------------
        # Update the password if required.
        password = validated_data.get('password', None)
        if password:
            instance.owner.set_password(password)
            logger.info("Updated the password.")

        # Update the account.
        if email:
            instance.owner.email = email
            instance.owner.username = get_unique_username_from_email(email)
        instance.owner.first_name = validated_data.get('given_name', instance.owner.first_name)
        instance.owner.last_name = validated_data.get('last_name', instance.owner.last_name)
        instance.owner.is_active = validated_data.get('is_active', instance.owner.is_active)
        instance.owner.save()
        logger.info("Updated the shared user.")

        # Attach the user to the `group` group.
        account_type = validated_data.get('account_type', None)
        if account_type != "NaN":
            account_type = int(account_type)
            instance.owner.groups.set([account_type])
            logger.info("Updated the group membership.")

        #---------------------------
        # Update `Staff` object.
        #---------------------------
        # Person
        instance.description=validated_data.get('description', None)
        instance.given_name=validated_data.get('given_name', None)
        instance.last_name=validated_data.get('last_name', None)
        instance.middle_name=validated_data.get('middle_name', None)
        instance.birthdate=validated_data.get('birthdate', None)
        instance.join_date=validated_data.get('join_date', None)
        instance.gender=validated_data.get('gender', None)

        # Misc
        instance.hourly_salary_desired=validated_data.get('hourly_salary_desired', 0.00)
        instance.limit_special=validated_data.get('limit_special', None)
        instance.dues_date=validated_data.get('dues_date', None)
        instance.commercial_insurance_expiry_date=validated_data.get('commercial_insurance_expiry_date', None)
        instance.police_check=validated_data.get('police_check', None)
        instance.drivers_license_class=validated_data.get('drivers_license_class', None)
        # instance.how_hear=validated_data.get('how_hear', None)
        instance.last_modified_by = self.context['last_modified_by']
        instance.last_modified_from = self.context['last_modified_from']
        instance.last_modified_from_is_public = self.context['last_modified_from_is_public']
        # 'organizations', #TODO: IMPLEMENT.

        # Contact Point
        instance.area_served=validated_data.get('area_served', None)
        instance.available_language=validated_data.get('available_language', None)
        instance.contact_type=validated_data.get('contact_type', None)
        instance.email=email
        instance.personal_email=personal_email
        instance.fax_number=validated_data.get('fax_number', None)
        # 'hours_available', #TODO: IMPLEMENT.
        instance.telephone=validated_data.get('telephone', None)
        instance.telephone_extension=validated_data.get('telephone_extension', None)
        instance.telephone_type_of=validated_data.get('telephone_type_of', None)
        instance.other_telephone=validated_data.get('other_telephone', None)
        instance.other_telephone_extension=validated_data.get('other_telephone_extension', None)
        instance.other_telephone_type_of=validated_data.get('other_telephone_type_of', None)

        # Postal Address
        instance.address_country=validated_data.get('address_country', None)
        instance.address_locality=validated_data.get('address_locality', None)
        instance.address_region=validated_data.get('address_region', None)
        instance.post_office_box_number=validated_data.get('post_office_box_number', None)
        instance.postal_code=validated_data.get('postal_code', None)
        instance.street_address=validated_data.get('street_address', None)
        instance.street_address_extra=validated_data.get('street_address_extra', None)

        # Geo-coordinate
        instance.elevation=validated_data.get('elevation', None)
        instance.latitude=validated_data.get('latitude', None)
        instance.longitude=validated_data.get('longitude', None)
        # 'location' #TODO: IMPLEMENT.

        # Emergency contact.
        instance.emergency_contact_name=validated_data.get('emergency_contact_name', None)
        instance.emergency_contact_relationship=validated_data.get('emergency_contact_relationship', None)
        instance.emergency_contact_telephone=validated_data.get('emergency_contact_telephone', None)
        instance.emergency_contact_alternative_telephone=validated_data.get('emergency_contact_alternative_telephone', None)

        # Save our instance.
        instance.save()
        logger.info("Updated the staff member.")

        #------------------------
        # Set our `Tag` objects.
        #------------------------
        tags = validated_data.get('tags', None)
        if tags is not None:
            if len(tags) > 0:
                instance.tags.set(tags)

        #---------------------------
        # Attach our comment.
        #---------------------------
        extra_comment = validated_data.get('extra_comment', None)
        if extra_comment is not None:
            comment = Comment.objects.create(
                created_by=self.context['last_modified_by'],
                last_modified_by=self.context['last_modified_by'],
                text=extra_comment,
                created_from = self.context['last_modified_from'],
                created_from_is_public = self.context['last_modified_from_is_public']
            )
            staff_comment = StaffComment.objects.create(
                staff=instance,
                comment=comment,
            )

        #---------------------------
        # Update validation data.
        #---------------------------
        # validated_data['comments'] = StaffComment.objects.filter(staff=instance)
        validated_data['last_modified_by'] = self.context['last_modified_by']
        # validated_data['extra_comment'] = None

        # Return our validated data.
        return validated_data
Exemplo n.º 3
0
    def update(self, instance, validated_data):
        """
        Override this function to include extra functionality.
        """
        # Get our inputs.
        email = validated_data.get('email', instance.email)
        type_of_customer = validated_data.get('type_of', UNASSIGNED_CUSTOMER_TYPE_OF_ID)

        #-----------------------------------------------------------
        # Bugfix: Created `SharedUser` object if not created before.
        #-----------------------------------------------------------
        if instance.owner is None and email:
            owner = SharedUser.objects.filter(email=email).first()
            if owner:
                instance.owner = owner
                instance.save()
                logger.info("BUGFIX: Attached existing shared user to staff.")
            else:
                instance.owner = SharedUser.objects.create(
                    first_name=validated_data['given_name'],
                    last_name=validated_data['last_name'],
                    email=email,
                    is_active=True,
                    franchise=self.context['franchise'],
                    was_email_activated=True
                )
                instance.save()
                logger.info("BUGFIX: Created shared user and attached to staff.")

        #---------------------------
        # Update `SharedUser` object.
        #---------------------------
        if instance.owner:
            # Update details.
            instance.owner.first_name = validated_data.get('given_name', instance.owner.first_name)
            instance.owner.last_name = validated_data.get('last_name', instance.owner.last_name)

            if email:
                instance.owner.email = email
                instance.owner.username = get_unique_username_from_email(email)

            # Update the password.
            password = validated_data.get('password', None)
            instance.owner.set_password(password)

            # Save the model to the database.
            instance.owner.save()
            logger.info("Updated shared user.")

        #---------------------------
        # Update `Customer` object.
        #---------------------------
        # Update email instance.
        instance.description = validated_data.get('description', instance.description)
        if email:
            instance.email = email

        # Profile
        instance.given_name = validated_data.get('given_name', instance.given_name)
        instance.middle_name = validated_data.get('middle_name', instance.middle_name)
        instance.last_name = validated_data.get('last_name', instance.last_name)
        instance.last_modified_by = self.context['last_modified_by']
        instance.birthdate = validated_data.get('birthdate', instance.birthdate)
        instance.join_date = validated_data.get('join_date', instance.join_date)
        instance.gender = validated_data.get('gender', instance.gender)

        # Misc (Read/Write)
        instance.is_ok_to_email = validated_data.get('is_ok_to_email', instance.is_ok_to_email)
        instance.is_ok_to_text = validated_data.get('is_ok_to_text', instance.is_ok_to_text)
        instance.is_senior = validated_data.get('is_ok_to_text', instance.is_ok_to_text)
        instance.is_senior = validated_data.get('is_senior', instance.is_senior)
        instance.is_support = validated_data.get('is_support', instance.is_support)
        instance.job_info_read = validated_data.get('job_info_read', instance.job_info_read)
        instance.how_hear = validated_data.get('how_hear', instance.how_hear)
        instance.how_hear_other = validated_data.get('how_hear_other', instance.how_hear_other)
        instance.type_of=validated_data.get('type_of', instance.type_of)

        # # Misc (Read Only)
        instance.last_modified_by = self.context['last_modified_by']
        instance.last_modified_from = self.context['last_modified_from']
        instance.last_modified_from_is_public = self.context['last_modified_from_is_public']
        # 'organizations', #TODO: FIX

        # Contact Point
        instance.area_served = validated_data.get('area_served', instance.area_served)
        instance.available_language = validated_data.get('available_language', instance.available_language)
        instance.contact_type = validated_data.get('contact_type', instance.contact_type)
        instance.email = validated_data.get('email', instance.contact_type)
        instance.fax_number = validated_data.get('fax_number', instance.fax_number)
        # 'hours_available', #TODO: FIX
        instance.telephone=validated_data.get('telephone', None)
        instance.telephone_extension=validated_data.get('telephone_extension', None)
        instance.telephone_type_of=validated_data.get('telephone_type_of', None)
        instance.other_telephone=validated_data.get('other_telephone', None)
        instance.other_telephone_extension=validated_data.get('other_telephone_extension', None)
        instance.other_telephone_type_of=validated_data.get('other_telephone_type_of', None)

        # Postal Address
        instance.address_country = validated_data.get('address_country', instance.address_country)
        instance.address_locality = validated_data.get('address_locality', instance.address_locality)
        instance.address_region = validated_data.get('address_region', instance.address_region)
        instance.post_office_box_number = validated_data.get('post_office_box_number', instance.post_office_box_number)
        instance.postal_code = validated_data.get('postal_code', instance.postal_code)
        instance.street_address = validated_data.get('street_address', instance.street_address)
        instance.street_address_extra = validated_data.get('street_address_extra', instance.street_address_extra)

        # Geo-coordinate
        instance.elevation = validated_data.get('elevation', instance.elevation)
        instance.latitude = validated_data.get('latitude', instance.latitude)
        instance.longitude = validated_data.get('longitude', instance.longitude)
        # 'location' #TODO: FIX

        # Save
        instance.save()
        logger.info("Updated the customer.")

        #------------------------
        # Set our `Tag` objects.
        #------------------------
        tags = validated_data.get('tags', instance.tags)
        if tags is not None:
            if len(tags) > 0:
                instance.tags.set(tags)

        #---------------------------
        # Attach our comment.
        #---------------------------
        extra_comment = validated_data.get('extra_comment', None)
        if extra_comment is not None:
            comment = Comment.objects.create(
                created_by=self.context['last_modified_by'],
                last_modified_by=self.context['last_modified_by'],
                text=extra_comment,
                created_from = self.context['last_modified_from'],
                created_from_is_public = self.context['last_modified_from_is_public']
            )
            CustomerComment.objects.create(
                about=instance,
                comment=comment,
            )

        #----------------------------------------
        # Update or create `Organization` object.
        #----------------------------------------
        if type_of_customer == COMMERCIAL_CUSTOMER_TYPE_OF_ID:
            logger.info("Detected commercial customer...")

            organization_name = validated_data.get('organization_name', None)
            organization_type_of = validated_data.get('organization_type_of', None)
            organization_address_country = validated_data.get('organization_address_country', None)
            organization_address_locality = validated_data.get('organization_address_locality', None)
            organization_address_region = validated_data.get('organization_address_region', None)
            organization_post_office_box_number = validated_data.get('organization_post_office_box_number', None)
            organization_postal_code = validated_data.get('organization_postal_code', None)
            organization_street_address = validated_data.get('organization_street_address', None)
            organization_street_address_extra = validated_data.get('organization_street_address_extra', None)

            if organization_name and organization_type_of:
                organization, created = Organization.objects.update_or_create(
                    name=organization_name,
                    type_of=organization_type_of,
                    defaults={
                        'type_of': organization_type_of,
                        'name': organization_name,
                        'address_country': organization_address_country,
                        'address_locality': organization_address_locality,
                        'address_region': organization_address_region,
                        'post_office_box_number': organization_post_office_box_number,
                        'postal_code': organization_postal_code,
                        'street_address': organization_street_address,
                        'street_address_extra': organization_street_address_extra,
                    }
                )
                logger.info("Created organization.")
                if created:
                    logger.info("Created organization.")
                    organization.owner = instance.owner
                    organization.save()

                instance.organization = organization
                instance.save()
                logger.info("Attached created organization to customer.")

        #---------------------------
        # Update validation data.
        #---------------------------
        # validated_data['comments'] = CustomerComment.objects.filter(customer=instance)
        validated_data['last_modified_by'] = self.context['last_modified_by']
        validated_data['extra_comment'] = None

        # Return our validated data.
        return validated_data
Exemplo n.º 4
0
    def update(self, instance, validated_data):
        """
        Override this function to include extra functionality.
        """
        # # For debugging purposes only.
        # print(validated_data)

        # Get our inputs.
        work_email = validated_data.get('work_email', instance.email)
        personal_email = validated_data.get('personal_email', None)

        #-------------------------------------
        # Bugfix: Created `SharedUser` object.
        #-------------------------------------
        if instance.owner is None:
            owner = SharedUser.objects.filter(email=work_email).first()
            if owner:
                instance.owner = owner
                instance.save()
                logger.info("BUGFIX: Attached existing shared user to staff.")
            else:
                instance.owner = SharedUser.objects.create(
                    first_name=validated_data['given_name'],
                    last_name=validated_data['last_name'],
                    email=work_email,
                    is_active=True,
                    franchise=self.context['franchise'],
                    was_email_activated=True)
                instance.save()
                logger.info(
                    "BUGFIX: Created shared user and attached to staff.")

        #---------------------------
        # Update `SharedUser` object.
        #---------------------------
        # Update the account.
        if work_email:
            instance.owner.email = work_email
            instance.owner.username = get_unique_username_from_email(
                work_email)
        instance.owner.first_name = validated_data.get(
            'given_name', instance.owner.first_name)
        instance.owner.last_name = validated_data.get('last_name',
                                                      instance.owner.last_name)
        instance.owner.save()
        logger.info("Updated the shared user.")

        #---------------------------
        # Update `Staff` object.
        #---------------------------
        # Person
        instance.given_name = validated_data.get('given_name', None)
        instance.last_name = validated_data.get('last_name', None)
        instance.middle_name = validated_data.get('middle_name', None)
        # Misc
        instance.last_modified_by = self.context['last_modified_by']
        instance.last_modified_from = self.context['last_modified_from']
        instance.last_modified_from_is_public = self.context[
            'last_modified_from_is_public']

        # Contact Point
        instance.area_served = validated_data.get('area_served', None)
        instance.available_language = validated_data.get(
            'available_language', None)
        instance.contact_type = validated_data.get('contact_type', None)
        instance.email = work_email
        instance.personal_email = personal_email
        # 'hours_available', #TODO: IMPLEMENT.
        instance.telephone = validated_data.get('telephone', None)
        # instance.telephone_extension=validated_data.get('telephone_extension', None)
        instance.telephone_type_of = validated_data.get(
            'telephone_type_of', None)
        instance.other_telephone = validated_data.get('other_telephone', None)
        # instance.other_telephone_extension=validated_data.get('other_telephone_extension', None)
        instance.other_telephone_type_of = validated_data.get(
            'other_telephone_type_of', TELEPHONE_CONTACT_POINT_TYPE_OF_ID)

        # Save our instance.
        instance.save()
        logger.info("Updated the staff member.")

        # Return our validated data.
        return instance
Exemplo n.º 5
0
    def update(self, instance, validated_data):
        """
        Override this function to include extra functionality.
        """
        # For debugging purposes only.
        # print(validated_data)

        #-------------------------------------
        # Bugfix: Created `SharedUser` object.
        #-------------------------------------
        if instance.owner is None:
            owner = SharedUser.objects.filter(email=instance.email).first()
            if owner:
                instance.owner = owner
                instance.save()
                logger.info("BUGFIX: Attached existing shared user to staff.")
            else:
                instance.owner = SharedUser.objects.create(
                    first_name=instance.given_name,
                    last_name=instance.last_name,
                    email=instance.mail,
                    is_active=True,
                    franchise=self.context['franchise'],
                    was_email_activated=True)
                instance.save()
                logger.info(
                    "BUGFIX: Created shared user and attached to staff.")

        #---------------------------
        # Update `SharedUser` object.
        #---------------------------
        # Update the account.
        if instance.email:
            instance.owner.email = instance.email
            instance.owner.username = get_unique_username_from_email(
                instance.email)
        instance.owner.first_name = validated_data.get(
            'given_name', instance.owner.first_name)
        instance.owner.last_name = validated_data.get('last_name',
                                                      instance.owner.last_name)
        instance.owner.is_active = validated_data.get('is_active',
                                                      instance.owner.is_active)
        instance.police_check = validated_data.get('police_check',
                                                   instance.police_check)
        instance.owner.save()
        logger.info("Updated the shared user.")

        # Attach the user to the `group` group.
        account_type = validated_data.get('account_type', None)
        if account_type != "NaN" and account_type != None:
            account_type = int(account_type)
            instance.owner.groups.set([account_type])
            logger.info("Updated the group membership.")

        #---------------------------
        # Update `Staff` object.
        #---------------------------

        # Misc
        instance.last_modified_by = self.context['last_modified_by']
        instance.last_modified_from = self.context['last_modified_from']
        instance.last_modified_from_is_public = self.context[
            'last_modified_from_is_public']

        # Emergency contact.
        instance.description = validated_data.get('description', None)
        instance.emergency_contact_name = validated_data.get(
            'emergency_contact_name', None)
        instance.emergency_contact_relationship = validated_data.get(
            'emergency_contact_relationship', None)
        instance.emergency_contact_telephone = validated_data.get(
            'emergency_contact_telephone', None)
        instance.emergency_contact_alternative_telephone = validated_data.get(
            'emergency_contact_alternative_telephone', None)

        # Save our instance.
        instance.save()
        logger.info("Updated the staff member.")

        #------------------------
        # Set our `Tag` objects.
        #------------------------
        tags = validated_data.get('tags', None)
        if tags is not None:
            if len(tags) > 0:
                instance.tags.set(tags)

        # Return our validated data.
        return instance
    def update(self, instance, validated_data):
        """
        Override this function to include extra functionality.
        """
        # Get our inputs.
        email = validated_data.get('email', instance.email)

        #-----------------------------------------------------------
        # Bugfix: Created `SharedUser` object if not created before.
        #-----------------------------------------------------------
        if instance.owner is None and email:
            owner = SharedUser.objects.filter(email=email).first()
            if owner:
                instance.owner = owner
                instance.save()
                logger.info("BUGFIX: Attached existing shared user to staff.")
            else:
                instance.owner = SharedUser.objects.create(
                    first_name=validated_data['given_name'],
                    last_name=validated_data['last_name'],
                    email=email,
                    is_active=True,
                    franchise=self.context['franchise'],
                    was_email_activated=True)
                instance.save()
                logger.info(
                    "BUGFIX: Created shared user and attached to staff.")

        #---------------------------
        # Update `SharedUser` object.
        #---------------------------
        if instance.owner:
            # Update details.
            instance.owner.first_name = validated_data.get(
                'given_name', instance.owner.first_name)
            instance.owner.last_name = validated_data.get(
                'last_name', instance.owner.last_name)

            if email:
                instance.owner.email = email
                instance.owner.username = get_unique_username_from_email(email)

            # Update the password.
            password = validated_data.get('password', None)
            instance.owner.set_password(password)

            # Save the model to the database.
            instance.owner.save()
            logger.info("Updated shared user.")

        #---------------------------
        # Update `Customer` object.
        #---------------------------
        instance.given_name = validated_data.get('given_name',
                                                 instance.given_name)
        instance.middle_name = validated_data.get('middle_name',
                                                  instance.middle_name)
        instance.last_name = validated_data.get('last_name',
                                                instance.last_name)
        instance.last_modified_by = self.context['last_modified_by']
        instance.is_ok_to_email = validated_data.get('is_ok_to_email',
                                                     instance.is_ok_to_email)
        instance.is_ok_to_text = validated_data.get('is_ok_to_text',
                                                    instance.is_ok_to_text)

        instance.last_modified_by = self.context['last_modified_by']
        instance.last_modified_from = self.context['last_modified_from']
        instance.last_modified_from_is_public = self.context[
            'last_modified_from_is_public']
        instance.organization_name = validated_data.get(
            'organization_name', instance.organization_name)
        instance.organization_type_of = validated_data.get(
            'organization_type_of', instance.organization_type_of)

        instance.email = validated_data.get('email', instance.contact_type)
        instance.telephone = validated_data.get('telephone', None)
        instance.telephone_extension = validated_data.get(
            'telephone_extension', None)
        instance.telephone_type_of = validated_data.get(
            'telephone_type_of', None)
        instance.other_telephone = validated_data.get('other_telephone', None)
        instance.other_telephone_extension = validated_data.get(
            'other_telephone_extension', None)
        instance.other_telephone_type_of = validated_data.get(
            'other_telephone_type_of', None)

        instance.save()
        logger.info("Updated the customer.")
        return instance