コード例 #1
0
	def save(self, *args, **kwargs):
		if(not self.id):
			new_slug = '{}-{}'.format(
				slugify(self.title, allow_unicode=True),
				generate_random_string())

			while Diary.objects.filter(slug=new_slug).exists():
				new_slug = '{}-{}'.format(
					slugify(self.title, allow_unicode=True),
					generate_random_string())

			self.slug = new_slug
		self.description = ' '.join(self.content[:255].split(' ')[:-1])
		return super(Diary, self).save(*args, **kwargs)
コード例 #2
0
    def save(self, *args, **kwargs):
        if (not self.id):
            title_slug = slugify(self.title, allow_unicode=True)
            new_slug = '{}'.format(title_slug)

            while Diary.objects.filter(slug=new_slug).exists():
                new_slug = '{}-{}'.format(title_slug, generate_random_string())

            self.slug = new_slug

        # self.description is supposed to be plain text so that it's displayed
        # in the diary list page
        start_length = 500
        total_position = len(self.content)
        text_description = bleach.clean(self.content[:start_length],
                                        strip=True,
                                        tags=[],
                                        attributes=[]).strip()
        # If 500 non-clean characters is not enough, add 50 every time
        while len(text_description) < 245 & start_length < total_position:
            text_description += bleach.clean(
                self.content[start_length:start_length + 50],
                strip=True,
                tags=[],
                attributes=[]).strip()
            start_length += 50
        self.description = text_description[:255]

        return super(Diary, self).save(*args, **kwargs)
コード例 #3
0
def add_slug_to_expenditure(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        text = instance.target
        if len(instance.target) > 30:
            text = text[:30]
        slug = slugify(text)
        random_string = generate_random_string()
        instance.slug = slug + "-" + str(instance.amount) + "-" + random_string
コード例 #4
0
def add_slug_to_task(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        text = instance.title
        if len(instance.title) > 30:
            text = text[:30]
        slug = slugify(text)
        random_string = generate_random_string()
        instance.slug = slug + "-" + random_string
コード例 #5
0
ファイル: signals.py プロジェクト: hectep/quora
def add_slug_to_question(sender, instance, *args, **kwargs):
    """
    A signal that generates unique slug for every question before save.
    """
    if instance and not instance.slug:
        slug = slugify(instance.content)
        random_string = generate_random_string()
        instance.slug = slug + '-' + random_string
コード例 #6
0
def add_slug_to_income(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        text = instance.source
        if len(instance.source) > 30:
            text = text[:30]
        slug = slugify(text)
        random_string = generate_random_string()
        instance.slug = slug + "-" + str(instance.amount) + "-" + random_string
コード例 #7
0
ファイル: signals.py プロジェクト: MenshikovIA/QuestionTime
def add_slug_to_question(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.content)

        while Question.objects.filter(slug=slug).exists() or slug == '':
            random_string = generate_random_string()
            slug = slug + "-" + random_string

        instance.slug = slug
コード例 #8
0
def unique_slug_generator(instance):
    author_slug = slugify(instance.author.username)
    random_slug = generate_random_string()
    slug = author_slug + "-" + random_slug
    Klass = instance.__class__
    qs_exists = Klass.objects.filter(slug=slug).exists()
    if qs_exists:
        return unique_slug_generator(instance)
    return slug
コード例 #9
0
def add_slug_to_question(sender, instance, *args, **kwargs):

    if instance and not instance.slug:

        slug = slugify(instance.content)

        random_string = generate_random_string()

        instance.slug = slug + "-" + random_string
コード例 #10
0
 def save(
     self,
     *args,
     **kwargs,
 ):  # new
     if not self.slug:
         random_s = generate_random_string()
         self.slug = slugify(self.Video_Name) + '-' + random_s
     return super().save(*args, **kwargs)
コード例 #11
0
ファイル: signals.py プロジェクト: pisalore/evs
def add_id_to_s3_document_before_upload(sender, instance, *args, **kwargs):
    if instance.document.name:
        user_folder = instance.loaded_by.__str__() + '/'
        if instance.event:
            event_folder = '{}{}/'.format(settings.EVENT_PREFIX,
                                          instance.event.id)
            user_folder = user_folder + event_folder
        instance.document.name = user_folder + generate_random_string(
        ) + instance.document.name
コード例 #12
0
ファイル: signals.py プロジェクト: jackyng88/Querios
def add_slug_to_question(sender, instance, *args, **kwargs):
    """
    Function that takes randomly generated string from the utils.py file from
    the core folder. This slug is added to the question to guarantee a 
    unique slug for use in question model for that particular instance.
    """
    if instance and not instance.slug:
        slug = slugify(instance.content)
        random_string = generate_random_string()
        instance.slug = slug + "-" + random_string
コード例 #13
0
def add_slug_to_user(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.email.split('@')[0])
        # Check if slug existed
        random_string = ''
        while True:
            if User.objects.filter(slug=slug + random_string).exists():
                random_string = generate_random_string(length=2)
            else:
                break
        instance.slug = slug + random_string
コード例 #14
0
def add_slug_to_question(sender, instance, *args, **kwargs):
    '''
    Fill the "slug" attribute for the Question model using
    the 'slugify' function to obtain the slug of the content
    field.
    To mantain its uniqueness, adds a random string on it.
    '''
    if instance and not instance.slug:
        slug = slugify(instance.content)
        random_string = generate_random_string()
        instance.slug = slug + '-' + random_string
コード例 #15
0
ファイル: models.py プロジェクト: dwiniarski/oil_pumpers
    def create_user(self, email, password):
        if email is None:
            raise TypeError('User must have an email')
        if password is None:
            raise TypeError('User must have a password')

        user = self.model(email=email)
        user.set_password(password)
        user.is_active = False
        user.is_superuser = False
        user.is_staff = False
        user.activation_token = generate_random_string(32)
        user.save()

        return user
コード例 #16
0
def add_slug_to_article(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.title)

        random_string = generate_random_string()

        instance.slug = slug + "-" + random_string


#Come si ottengono degli slug unici tra di loro?
#Aggiungendo all'instanza slug una stringa di
#caratteri casuali
# vedi la cartella core,
# si è creato il file utils.py

# poi  abbiamo aggiunto la stringa random_string = generate_random_string()
# e default_app_config nel file __init__ di questa app
コード例 #17
0
def add_slug_to_article_if_not_exists(sender, instance, *args, **kwargs):
    MAXIMUM_SLUG_LENGTH = 255

    if instance and not instance.slug:
        slug = slugify(instance.title)
        unique = generate_random_string()

        if len(slug) > MAXIMUM_SLUG_LENGTH:
            slug = slug[:MAXIMUM_SLUG_LENGTH]

        while len(slug + "-" + unique) > MAXIMUM_SLUG_LENGTH:
            parts = slug.slplit("-")

            if len(parts) == 1:
                slug = slug[:MAXIMUM_SLUG_LENGTH - len(unique) - 1]
            else:
                slug = "-".join(parts[:-1])

        instance.slug = slug + "-" + unique
コード例 #18
0
ファイル: signals.py プロジェクト: sourabh1031/cruzz
def add_slug_to_article_if_not_exists(sender, instance, *args, **kwargs):
    MAXIMUM_SLUG_LENGTH = 255

    if instance and not instance.slug:
        slug = slugify(instance.title)
        unique = generate_random_string()

        if len(slug) > MAXIMUM_SLUG_LENGTH:
            slug = slug[:MAXIMUM_SLUG_LENGTH]

        while len(slug + '-' + unique) > MAXIMUM_SLUG_LENGTH:
            parts = slug.split('-')

            if len(parts) is 1:
                # the slug has no hyphens
                # to append the unique string we must remove characters from the end of the string
                slug = slug[:MAXIMUM_SLUG_LENGTH - len(unique) - 1]
            else:
                slug = '-'.join(parts[:-1])

        instance.slug = slug + '-' + unique
コード例 #19
0
ファイル: signals.py プロジェクト: alexzarazuaa/SeekBar
def add_slug_to_bar_if_not_exists(sender, instance, *args, **kwargs):
    MAXIMUM_SLUG_LENGTH = 255

    if instance and not instance.slug:
        slug = slugify(instance.name)
        unique = generate_random_string()

        if len(slug) > MAXIMUM_SLUG_LENGTH:
            slug = slug[:MAXIMUM_SLUG_LENGTH]

        while len(slug + '-' + unique) > MAXIMUM_SLUG_LENGTH:
            parts = slug.split('-')

            if len(parts) == 1:
                # The slug has no hypens. To append the unique string we must
                # arbitrarly remove `len(unique)` characters from the end of
                # `slug`. Subtract one to account for extra hyphen.
                slug = slug[:MAXIMUM_SLUG_LENGTH - len(unique) - 1]
            else:
                slug = '-'.join(parts[:-1])

        instance.slug = slug + '-' + unique
コード例 #20
0
ファイル: signals.py プロジェクト: LukaszMalucha/vuebank
def add_slug_to_sell_transaction(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.instrument.name)
        random_string = generate_random_string()
        instance.slug = "sell-" + slug + "-" + random_string
コード例 #21
0
ファイル: signals.py プロジェクト: ParideNovi/EventBuddy
def add_slug_to_event(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.title)  #content is the slug text
        random_string = generate_random_string()  #to make unique the slug
        instance.slug = slug + "-" + random_string
コード例 #22
0
ファイル: utils_test.py プロジェクト: jameesjohn/oppia
 def test_generate_random_string(self) -> None:
     # Generate a random string of length 12.
     random_string = utils.generate_random_string(12)
     self.assertTrue(isinstance(random_string, python_utils.BASESTRING))
     self.assertEqual(len(random_string), 12)
コード例 #23
0
def add_slug_to_notification_history(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.title)
        random_string = generate_random_string()
        instance.slug = slug + "-" + random_string
コード例 #24
0
ファイル: signals.py プロジェクト: ta-ou/target-deploy
def add_slug_to_target(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.target)
        random_string = generate_random_string()
        instance.slug = slug + "-" + random_string
    pass
コード例 #25
0
def add_slug_to_evento(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.content)
        print("slugify... ", slug)
        random_string = generate_random_string()
        instance.slug = slug + "-" + random_string
コード例 #26
0
ファイル: signals.py プロジェクト: LukaszMalucha/vuebank
def add_slug_to_asset(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.instrument.name)
        random_string = generate_random_string()
        instance.slug = "a-" + slug + "-" + random_string
コード例 #27
0
def add_slug_to_product(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.title)
        random_string = utils.generate_random_string()
        instance.slug = f"{slug}-{random_string}"
コード例 #28
0
def add_slug_to_question(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.content)
        random_string = generate_random_string()
        instance.slug = slug + "-" + random_string  # manually assign slug + field before new instance is created
コード例 #29
0
ファイル: signals.py プロジェクト: opeodedeyi/cre8ive-backend
def add_slug_to_showcase(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.title)
        random_string = generate_random_string()
        instance.slug = slug + "-" + random_string 
コード例 #30
0
def add_slug_to_question(sender, instance, *args, **kwargs):
    if instance and not instance.slug:
        slug = slugify(instance.title)
        random_string = generate_random_string()
        instance.slug = hashlib.md5(
            (slug + "-" + random_string).encode('utf-8')).hexdigest()