示例#1
0
def geoip2_staff_metric_audit_func(organization, staff_metric):
    organization.activate_tenant()

    if staff_metric.created_from:
        staff_metric.created_from_position = get_point_from_ip(staff_metric.created_from)
    if staff_metric.last_modified_from:
        staff_metric.last_modified_from_position = get_point_from_ip(staff_metric.last_modified_from)
    staff_metric.save()
示例#2
0
def geoip2_member_audit_func(organization, member):
    organization.activate_tenant()

    if member.created_from:
        member.created_from_position = get_point_from_ip(member.created_from)
    if member.last_modified_from:
        member.last_modified_from_position = get_point_from_ip(
            member.last_modified_from)
    member.save()
示例#3
0
def geoip2_item_audit_func(organization, item):
    organization.activate_tenant()

    if item.created_from:
        item.created_from_position = get_point_from_ip(item.created_from)
    if item.last_modified_from:
        item.last_modified_from_position = get_point_from_ip(
            item.last_modified_from)
    item.save()
示例#4
0
def geoip2_associate_metric_audit_func(organization, associate_metric):
    organization.activate_tenant()

    if associate_metric.created_from:
        associate_metric.created_from_position = get_point_from_ip(
            associate_metric.created_from)
    if associate_metric.last_modified_from:
        associate_metric.last_modified_from_position = get_point_from_ip(
            associate_metric.last_modified_from)
    associate_metric.save()
示例#5
0
def geoip2_area_coordinator_audit_func(organization, area_coordinator):
    organization.activate_tenant()

    if area_coordinator.created_from:
        area_coordinator.created_from_position = get_point_from_ip(
            area_coordinator.created_from)
    if area_coordinator.last_modified_from:
        area_coordinator.last_modified_from_position = get_point_from_ip(
            area_coordinator.last_modified_from)
    area_coordinator.save()
示例#6
0
def geoip2_staff_comment_audit_func(organization, staff_comment):
    organization.activate_tenant()

    if staff_comment.comment:
        comment = staff_comment.comment
        if comment.created_from:
            comment.created_from_position = get_point_from_ip(comment.created_from)
        if comment.last_modified_from:
            comment.last_modified_from_position = get_point_from_ip(comment.last_modified_from)
        comment.save()
示例#7
0
def geoip2_area_coordinator_comment_audit_func(organization,
                                               area_coordinator_comment):
    organization.activate_tenant()

    if area_coordinator_comment.comment:
        comment = area_coordinator_comment.comment
        if comment.created_from:
            comment.created_from_position = get_point_from_ip(
                comment.created_from)
        if comment.last_modified_from:
            comment.last_modified_from_position = get_point_from_ip(
                comment.last_modified_from)
        comment.save()
示例#8
0
 def save(self, *args, **kwargs):
     '''
     Override the `save` function to support extra functionality of our model.
     '''
     if self.created_from:
         self.created_from_position = get_point_from_ip(self.created_from)
     if self.last_modified_from:
         self.last_modified_from_position = get_point_from_ip(
             self.last_modified_from)
     '''
     Finally call the parent function which handles saving so we can carry
     out the saving operation by Django in our ORM.
     '''
     super(MemberContact, self).save(*args, **kwargs)
示例#9
0
    def promote_to_staff(self, defaults):
        """
        - defaults
            - role_id
            - has_signed_staff_agreement
            - has_signed_conflict_of_interest_agreement
            - has_signed_code_of_conduct_agreement
            - has_signed_confidentiality_agreement
            - police_check_date
            - created_by
            - created_from
            - created_from_is_public
            - last_modified_by
            - last_modified_from
            - last_modified_from_is_public
        """
        from django.template.loader import render_to_string  # HTML / TXT
        from django.utils import timezone
        from shared_foundation.models import SharedGroup
        from tenant_foundation.models import Staff

        role_id = defaults.get('role_id', None)
        has_signed_staff_agreement = defaults.get('has_signed_staff_agreement', None)
        has_signed_conflict_of_interest_agreement = defaults.get('has_signed_conflict_of_interest_agreement', None)
        has_signed_code_of_conduct_agreement = defaults.get('has_signed_code_of_conduct_agreement', None)
        has_signed_confidentiality_agreement = defaults.get('has_signed_confidentiality_agreement', None)
        police_check_date = defaults.get('police_check_date', None)
        created_by = defaults.get('created_by', None)
        created_from = defaults.get('created_from', None)
        created_from_is_public = defaults.get('created_from_is_public', None)
        last_modified_by = defaults.get('last_modified_by', None)
        last_modified_from = defaults.get('last_modified_from', None)
        last_modified_from_is_public = defaults.get('last_modified_from_is_public', None)

        # Defensive code.
        assert self.user != None
        assert isinstance(role_id, int)
        assert isinstance(has_signed_staff_agreement, bool)
        assert isinstance(has_signed_conflict_of_interest_agreement, bool)
        assert isinstance(has_signed_code_of_conduct_agreement, bool)
        assert isinstance(has_signed_confidentiality_agreement, bool)
        assert police_check_date != None

        # Get the text agreement which will be signed.
        staff_agreement = render_to_string('account/staff_agreement/2019_05_01.txt', {}) if has_signed_staff_agreement else None
        conflict_of_interest_agreement = render_to_string('account/conflict_of_interest_agreement/2019_05_01.txt', {}) if has_signed_conflict_of_interest_agreement else None
        code_of_conduct_agreement = render_to_string('account/code_of_conduct_agreement/2019_05_01.txt', {}) if has_signed_code_of_conduct_agreement else None
        confidentiality_agreement = render_to_string('account/confidentiality_agreement/2019_05_01.txt', {}) if has_signed_confidentiality_agreement else None

        # Create or update our model.
        staff, created = Staff.objects.update_or_create(
            user=self.user,
            defaults={
                'user': self.user,
                'has_signed_staff_agreement': has_signed_staff_agreement,
                'staff_agreement': staff_agreement,
                'staff_agreement_signed_on': timezone.now(),
                'has_signed_conflict_of_interest_agreement': has_signed_conflict_of_interest_agreement,
                'conflict_of_interest_agreement': conflict_of_interest_agreement,
                'conflict_of_interest_agreement_signed_on': timezone.now(),
                'has_signed_code_of_conduct_agreement': has_signed_code_of_conduct_agreement,
                'code_of_conduct_agreement': code_of_conduct_agreement,
                'code_of_conduct_agreement_signed_on': timezone.now(),
                'has_signed_confidentiality_agreement': has_signed_confidentiality_agreement,
                'confidentiality_agreement': confidentiality_agreement,
                'confidentiality_agreement_signed_on': timezone.now(),
                'police_check_date': police_check_date,
                'created_by': created_by,
                'created_from': created_from,
                'created_from_is_public': created_from_is_public,
                'created_from_position': get_point_from_ip(created_from),
                'last_modified_by': last_modified_by,
                'last_modified_from': last_modified_from,
                'last_modified_from_is_public': last_modified_from_is_public,
                'last_modified_from_position': get_point_from_ip(last_modified_from),
            }
        )

        # Set the user's role to be after clearing the previous group memberships.
        staff.user.groups.clear()
        staff.user.groups.add(role_id)

        return staff
示例#10
0
    def promote_to_associate(self, defaults):
        """
        - defaults
            - has_signed_associate_agreement
            - has_signed_conflict_of_interest_agreement
            - has_signed_code_of_conduct_agreement
            - has_signed_confidentiality_agreement
            - police_check_date
            - created_by
            - created_from
            - created_from_is_public
            - last_modified_by
            - last_modified_from
            - last_modified_from_is_public
        """
        from django.template.loader import render_to_string  # HTML / TXT
        from django.utils import timezone
        from shared_foundation.models import SharedGroup
        from tenant_foundation.models import Associate

        has_signed_associate_agreement = defaults.get('has_signed_associate_agreement', None)
        has_signed_conflict_of_interest_agreement = defaults.get('has_signed_conflict_of_interest_agreement', None)
        has_signed_code_of_conduct_agreement = defaults.get('has_signed_code_of_conduct_agreement', None)
        has_signed_confidentiality_agreement = defaults.get('has_signed_confidentiality_agreement', None)
        police_check_date = defaults.get('police_check_date', None)
        created_by = defaults.get('created_by', None)
        created_from = defaults.get('created_from', None)
        created_from_is_public = defaults.get('created_from_is_public', None)
        last_modified_by = defaults.get('last_modified_by', None)
        last_modified_from = defaults.get('last_modified_from', None)
        last_modified_from_is_public = defaults.get('last_modified_from_is_public', None)

        # Defensive code.
        assert self.user != None
        assert isinstance(has_signed_associate_agreement, bool)
        assert isinstance(has_signed_conflict_of_interest_agreement, bool)
        assert isinstance(has_signed_code_of_conduct_agreement, bool)
        assert isinstance(has_signed_confidentiality_agreement, bool)
        assert police_check_date != None

        # Get the text agreement which will be signed.
        associate_agreement = render_to_string('account/associate_agreement/2019_05_01.txt', {}) if has_signed_associate_agreement else None
        conflict_of_interest_agreement = render_to_string('account/conflict_of_interest_agreement/2019_05_01.txt', {}) if has_signed_conflict_of_interest_agreement else None
        code_of_conduct_agreement = render_to_string('account/code_of_conduct_agreement/2019_05_01.txt', {}) if has_signed_code_of_conduct_agreement else None
        confidentiality_agreement = render_to_string('account/confidentiality_agreement/2019_05_01.txt', {}) if has_signed_confidentiality_agreement else None

        # Create or update our model.
        associate, created = Associate.objects.update_or_create(
            user=self.user,
            defaults={
                'user': self.user,
                'watch': self.watch,
                'type_of': self.type_of,
                'has_signed_associate_agreement': has_signed_associate_agreement,
                'associate_agreement': associate_agreement,
                'associate_agreement_signed_on': timezone.now(),
                'has_signed_conflict_of_interest_agreement': has_signed_conflict_of_interest_agreement,
                'conflict_of_interest_agreement': conflict_of_interest_agreement,
                'conflict_of_interest_agreement_signed_on': timezone.now(),
                'has_signed_code_of_conduct_agreement': has_signed_code_of_conduct_agreement,
                'code_of_conduct_agreement': code_of_conduct_agreement,
                'code_of_conduct_agreement_signed_on': timezone.now(),
                'has_signed_confidentiality_agreement': has_signed_confidentiality_agreement,
                'confidentiality_agreement': confidentiality_agreement,
                'confidentiality_agreement_signed_on': timezone.now(),
                'police_check_date': police_check_date,
                'created_by': created_by,
                'created_from': created_from,
                'created_from_is_public': created_from_is_public,
                'created_from_position': get_point_from_ip(created_from),
                'last_modified_by': last_modified_by,
                'last_modified_from': last_modified_from,
                'last_modified_from_is_public': last_modified_from_is_public,
                'last_modified_from_position': get_point_from_ip(last_modified_from),
            }
        )

        # Set the user's role to be a area coordinator after clearing the
        # previous group memberships.
        associate.user.groups.clear()
        associate.user.groups.add(SharedGroup.GROUP_MEMBERSHIP.ASSOCIATE)

        return associate