Beispiel #1
0
 def save(self, commit=True, use_card_filenames=False):
     instance = super(TinyPngForm, self).save(commit=False)
     for field in self.fields.keys():
         if (hasattr(instance, field) and field in dir(self.Meta.model)
                 and type(self.Meta.model._meta.get_field(field))
                 == models.models.ImageField):
             image = self.cleaned_data[field]
             if image and (isinstance(image, InMemoryUploadedFile)
                           or isinstance(image, TemporaryUploadedFile)):
                 filename = image.name
                 _, extension = os.path.splitext(filename)
                 if extension.lower() == '.png':
                     image = shrinkImageFromData(image.read(), filename)
                 if use_card_filenames and field in models.cardsImagesToName:
                     image.name = models.cardsImagesToName[field]({
                         'id':
                         instance.id,
                         'firstname':
                         instance.idol.name.split(' ')[-1] if instance.idol
                         and instance.idol.name else 'Unknown',
                     })
                 else:
                     image.name = randomString(32) + extension
                 setattr(instance, field, image)
     if commit:
         instance.save()
     return instance
Beispiel #2
0
 def save(self):
     instance = super(ModerationReportForm, self).save(commit=False)
     instance.status = 1
     if self.request.user.is_authenticated():
         instance.reported_by = self.request.user
     if self.account is not None:
         instance.fake_account = self.account
     elif self.eventparticipation is not None:
         instance.fake_eventparticipation = self.eventparticipation
     instance.save()
     for image in self.cleaned_data['images']:
         imageObject = models.UserImage.objects.create()
         imageObject.image.save(randomString(64), image)
         instance.images.add(imageObject)
     return instance
Beispiel #3
0
 def save(self):
     instance = super(ModerationReportForm, self).save(commit=False)
     instance.status = 1
     if self.request.user.is_authenticated():
         instance.reported_by = self.request.user
     if self.account is not None:
         instance.fake_account = self.account
     elif self.eventparticipation is not None:
         instance.fake_eventparticipation = self.eventparticipation
     elif self.user is not None:
         instance.fake_user = self.user
     elif self.activity is not None:
         instance.fake_activity = self.activity
     instance.save()
     for image in self.cleaned_data['images']:
         imageObject = models.UserImage.objects.create()
         imageObject.image.save(randomString(64), image)
         instance.images.add(imageObject)
     return instance
Beispiel #4
0
def card_upload_to(instance, filename):
    name, extension = os.path.splitext(filename)
    return 'cards/' + (str(instance.id) + '_' + utils.randomString(16) if instance and instance.id else utils.randomString(16)) + extension
Beispiel #5
0
def card_upload_to(instance, filename):
    name, extension = os.path.splitext(filename)
    return 'cards/' + (str(instance.id) + '_' +
                       utils.randomString(16) if instance and instance.id else
                       utils.randomString(16)) + extension
Beispiel #6
0
def event_EN_upload_to(instance, filename):
    name, extension = os.path.splitext(filename)
    return 'events/EN/' + (instance.english_name if instance.english_name else instance.japanese_name) + randomString(16) + extension