示例#1
0
def userAccountPreSave(sender, instance, raw, using, update_fields, **kwargs):

    if not instance.id:

        folderName = createUUID()
        while UserAccount.objects.filter(folder_name=folderName).exists():
            folderName = createRandomURL()
        instance.folder_name = folderName

        #

        randomURL = createRandomURL()
        while UserAccount.objects.filter(
                account_verification_id=randomURL).exists():
            randomURL = createRandomURL()
        instance.account_verification_id = randomURL

    else:

        userAccount = None

        try:
            userAccount = UserAccount.objects.get(pk=instance.pk)
        except UserAccount.DoesNotExist:
            return

        if instance.avatar and userAccount.avatar           and \
           instance.avatar.path != userAccount.avatar.path  and \
           os.path.isfile(userAccount.avatar.path):

            removeFile(userAccount.avatar.path)
示例#2
0
文件: handlers.py 项目: safakoner/kit
def conversionPreSave(sender, instance, raw, using, update_fields, **kwargs):

    if not instance.id:

        instance.folder_name = createUUID()

        randomURL = createRandomURL()
        while Conversion.objects.filter(url_id=randomURL).exists():
            randomURL = createRandomURL()
        instance.url_id = randomURL

    else:

        conversion = None

        try:
            conversion = Conversion.objects.get(pk=instance.pk)
        except Conversion.DoesNotExist:
            return

        if instance.background_image and conversion.background_image           and \
           instance.background_image.path != conversion.background_image.path  and \
           os.path.isfile(conversion.background_image.path):

            removeFile(conversion.background_image.path)
示例#3
0
def contextPreSave(sender, instance, raw, using, update_fields, **kwargs):

    if instance.id:

        context = None

        try:
            context = Context.objects.get(pk=instance.pk)
        except Context.DoesNotExist:
            return

        if instance.image and context.image           and \
           instance.image.path != context.image.path  and \
           os.path.isfile(context.image.path):

            removeFile(context.image.path)
示例#4
0
def testimonialPreSave(sender, instance, raw, using, update_fields, **kwargs):

    if instance.id:

        testimonial = None

        try:
            testimonial = Testimonial.objects.get(pk=instance.pk)
        except Testimonial.DoesNotExist:
            return

        if instance.avatar and testimonial.avatar           and \
           instance.avatar.path != testimonial.avatar.path  and \
           os.path.isfile(testimonial.avatar.path):

            removeFile(testimonial.avatar.path)
示例#5
0
def contextPreDelete(sender, instance, using, **kwargs):

    if instance.image:
        # User attribute to get the path
        removeFile(instance.image.path)
示例#6
0
def testimonialPreDelete(sender, instance, using, **kwargs):

    if instance.avatar:
        # User attribute to get the path
        removeFile(instance.avatar.path)