Example #1
0
 def save(self, *args, **kwargs):
     '''
     Override the `save` function to support extra functionality of our model.
     '''
     '''
     If we are creating a new row, then we will automatically increment the
     `id` field instead of relying on Postgres DB.
     '''
     if self.id == None:
         try:
             latest_obj = Item.objects.latest('id')
             self.id = latest_obj.id + 1
         except Item.DoesNotExist:
             self.id = 1
     '''
     If we are creating a new model, then we will automatically increment the `id`.
     '''
     # The following code will generate a unique slug and if the slug
     # is not unique in the database, then continue to try generating
     # a unique slug until it is found.
     if self.slug == "" or self.slug == None:
         from tenant_foundation.models.item_type import ItemType
         if self.type_of.category == ItemType.CATEGORY.EVENT or self.type_of.category == ItemType.CATEGORY.INCIDENT or self.type_of.category == ItemType.CATEGORY.CONCERN or self.type_of.category == ItemType.CATEGORY.RESOURCE:
             slug = slugify(self.title)
             while Item.objects.filter(slug=slug).exists():
                 slug = slugify(self.title) + "-" + get_referral_code(16)
             self.slug = slug
         else:
             self.slug = str(self.id)
     '''
     Finally call the parent function which handles saving so we can carry
     out the saving operation by Django in our ORM.
     '''
     super(Item, self).save(*args, **kwargs)
    def save(self, *args, **kwargs):
        '''
        Override the `save` function to support extra functionality of our model.
        '''
        '''
        If we are creating a new row, then we will automatically increment the
        `id` field instead of relying on Postgres DB.
        '''
        if self.id == None:
            try:
                latest_obj = MemberComment.objects.latest('id')
                self.id = latest_obj.id + 1
            except MemberComment.DoesNotExist:
                self.id = 1

        # The following code will generate a unique slug and if the slug
        # is not unique in the database, then continue to try generating
        # a unique slug until it is found.
        slug = self.member.user.slug
        while MemberComment.objects.filter(slug=slug).exists():
            slug = self.member.user.slug + "-" + get_referral_code(4)
        self.slug = slug
        '''
        Finally call the parent function which handles saving so we can carry
        out the saving operation by Django in our ORM.
        '''
        super(MemberComment, self).save(*args, **kwargs)
    def save(self, *args, **kwargs):
        '''
        Override the `save` function to support extra functionality of our model.
        '''

        if self.slug == None or self.slug == "":
            # The following code will generate a unique slug and if the slug
            # is not unique in the database, then continue to try generating
            # a unique slug until it is found.
            slug = slugify(self.get_full_name())
            while SharedUser.objects.filter(slug=slug).exists():
                slug = slugify(
                    self.get_full_name()) + "-" + get_referral_code(4)
            self.slug = slug

        if self.tos_agreement == None or self.tos_agreement == None:
            # Open up the current "terms of agreement" file and extract the text
            # context which we will save with the user account.
            self.tos_agreement = render_to_string(
                'account/terms_of_service/2019_05_01.txt', {})
            self.has_signed_tos = True
            self.tos_signed_on = timezone.now()
        '''
        Finally call the parent function which handles saving so we can carry
        out the saving operation by Django in our ORM.
        '''
        super(SharedUser, self).save(*args, **kwargs)
    def save(self, *args, **kwargs):
        '''
        Override the `save` function to support extra functionality of our model.
        '''

        # The following code will generate a unique slug and if the slug
        # is not unique in the database, then continue to try generating
        # a unique slug until it is found.
        slug = self.associate.user.slug
        while AssociateComment.objects.filter(slug=slug).exists():
            slug = self.associate.user.slug + "-" + get_referral_code(4)
        self.slug = slug
        '''
        Finally call the parent function which handles saving so we can carry
        out the saving operation by Django in our ORM.
        '''
        super(AssociateComment, self).save(*args, **kwargs)
Example #5
0
    def save(self, *args, **kwargs):
        '''
        Override the `save` function to support extra functionality of our model.
        '''
        '''
        If we are creating a new row, then we will automatically increment the
        `id` field instead of relying on Postgres DB.
        '''
        if self.id == None:
            try:
                latest_obj = District.objects.latest('id')
                self.id = latest_obj.id + 1
            except District.DoesNotExist:
                self.id = 1

        # Assign our unique slug to this model as our external identifier.
        if self.slug == None or self.slug == "":
            # The following code will generate a unique slug and if the slug
            # is not unique in the database, then continue to try generating
            # a unique slug until it is found.
            slug = slugify(self.name)
            while District.objects.filter(slug=slug).exists():
                slug = slugify(self.name) + "-" + get_referral_code(4)
            self.slug = slug

        # Update our searchable content.
        text = str(self.name) + " " + str(self.description)
        if self.counselor_name:
            text += str(self.counselor_name)
        if self.counselor_email:
            text += " " + str(self.counselor_email)
        if self.counselor_phone:
            text += " " + str(self.counselor_phone)
        if self.website_url:
            text += " " + str(self.website_url)
        if self.type_of:
            text += " " + self.get_type_of_label()
        if self.slug:
            text += " " + str(self.slug)
        self.indexed_text = text
        '''
        Finally call the parent function which handles saving so we can carry
        out the saving operation by Django in our ORM.
        '''
        super(District, self).save(*args, **kwargs)
    def save(self, *args, **kwargs):
        '''
        Override the `save` function to support extra functionality of our model.
        '''
        '''
        If we are creating a new row, then we will automatically increment the
        `id` field instead of relying on Postgres DB.
        '''
        if self.id == None:
            try:
                latest_obj = StreetAddressRange.objects.latest('id')
                self.id = latest_obj.id + 1
            except StreetAddressRange.DoesNotExist:
                self.id = 1
        '''
        If we are creating a new model, then we will automatically set `slug`.
        '''
        # The following code will generate a unique slug and if the slug
        # is not unique in the database, then continue to try generating
        # a unique slug until it is found.
        if self.slug == "" or self.slug == None:
            text = str(self.street_number_start) + "-to-"
            text += str(self.street_number_end) + "-"
            text += str(self.street_name) + "-"
            text += str(self.street_type) + "-"
            if self.street_type_other:
                text += str(self.street_type_other) + "-"
            text += str(self.street_direction)
            slug = slugify(text)
            while StreetAddressRange.objects.filter(slug=slug).exists():
                slug = slugify(text) + "-" + get_referral_code(16)
            self.slug = slug

        # Internal implementation of generating our street numbers.
        self.street_numbers = get_special_range(self.street_number_start,
                                                self.street_number_end,
                                                self.street_number_range_type)
        '''
        Finally call the parent function which handles saving so we can carry
        out the saving operation by Django in our ORM.
        '''
        super(StreetAddressRange, self).save(*args, **kwargs)
Example #7
0
    def save(self, *args, **kwargs):
        '''
        Override the `save` function to support extra functionality of our model.
        '''

        '''
        If we are creating a new row, then we will automatically increment the
        `id` field instead of relying on Postgres DB.
        '''
        if self.id == None:
            try:
                latest_obj = Watch.objects.latest('id');
                self.id = latest_obj.id + 1
            except Watch.DoesNotExist:
                self.id = 1

        '''
        If we are creating a new model, then we will automatically create `slug`.
        '''
        # The following code will generate a unique slug and if the slug
        # is not unique in the database, then continue to try generating
        # a unique slug until it is found.
        if self.slug == "" or self.slug == None:
            slug = slugify(self.name)
            while Watch.objects.filter(slug=slug).exists():
                slug = slugify(self.name)+"-"+get_referral_code(16)
            self.slug = slug

        # The following code will create the searchable content.
        # tags slug
        self.indexed_text = str(self.name) + " " + str(self.description) + " " + str(self.district.indexed_text)
        if self.pk != None:
            tag_names = self.tags.values_list('text', flat=True)
            for tag_name in tag_names:
                self.indexed_text += str(tag_name) + ", "

        '''
        Finally call the parent function which handles saving so we can carry
        out the saving operation by Django in our ORM.
        '''
        super(Watch, self).save(*args, **kwargs)
Example #8
0
    def save(self, *args, **kwargs):
        '''
        Override the `save` function to support extra functionality of our model.
        '''

        '''
        If we are creating a new row, then we will automatically increment the
        `id` field instead of relying on Postgres DB.
        '''
        if self.id == None:
            try:
                latest_obj = PrivateFileUpload.objects.latest('id');
                self.id = latest_obj.id + 1
            except PrivateFileUpload.DoesNotExist:
                self.id = 1

        if self.title == None:
            self.title = str(self.data_file)

        # The following code will generate a unique slug and if the slug
        # is not unique in the database, then continue to try generating
        # a unique slug until it is found.
        slug = self.user.slug
        while PrivateFileUpload.objects.filter(slug=slug).exists():
            slug = self.user.slug+"-"+get_referral_code(16)
        self.slug = slug

        search_text = str(self.slug)
        if self.title:
            search_text += " " + self.title
        if self.description:
            search_text += " " + self.description
        if self.data_file:
            search_text += " " + str(self.data_file)
        self.indexed_text = Truncator(search_text).chars(511)

        '''
        Finally call the parent function which handles saving so we can carry
        out the saving operation by Django in our ORM.
        '''
        super(PrivateFileUpload, self).save(*args, **kwargs)