def save_icon(obj, icon_content, sizes=mkt.CONTENT_ICON_SIZES): """ Saves the icon for `obj` to its final destination. `obj` can be an app or a website. """ tmp_dst = os.path.join(settings.TMP_PATH, 'icon', uuid.uuid4().hex) with public_storage.open(tmp_dst, 'wb') as fd: fd.write(icon_content) dirname = obj.get_icon_dir() destination = os.path.join(dirname, '%s' % obj.pk) remove_icons(destination) icon_hash = resize_icon(tmp_dst, destination, sizes, set_modified_on=[obj], src_storage=public_storage, dst_storage=public_storage) # Need to set icon type so .get_icon_url() works normally # submit step 4 does it through AppFormMedia, but we want to beat them to # the punch. resize_icon outputs pngs so we know it's 'image/png'. obj.icon_hash = icon_hash['icon_hash'] # In case, we're running not async. try: obj.icon_type = 'image/png' except AttributeError: # icon_type can be just a @property on models that only implement png. pass obj.save()
def save_icon(obj, icon_content): """ Saves the icon for `obj` to its final destination. `obj` can be an app or a website. """ tmp_dst = os.path.join(settings.TMP_PATH, 'icon', uuid.uuid4().hex) with public_storage.open(tmp_dst, 'wb') as fd: fd.write(icon_content) dirname = obj.get_icon_dir() destination = os.path.join(dirname, '%s' % obj.pk) remove_icons(destination) icon_hash = resize_icon(tmp_dst, destination, mkt.CONTENT_ICON_SIZES, set_modified_on=[obj], src_storage=public_storage, dst_storage=public_storage) # Need to set icon type so .get_icon_url() works normally # submit step 4 does it through AppFormMedia, but we want to beat them to # the punch. resize_icon outputs pngs so we know it's 'image/png'. obj.icon_hash = icon_hash['icon_hash'] # In case, we're running not async. try: obj.icon_type = 'image/png' except AttributeError: # icon_type can be just a @property on models that only implement png. pass obj.save()
def save(self, addon, commit=True): if self.cleaned_data["icon_upload_hash"]: upload_hash = self.cleaned_data["icon_upload_hash"] upload_path = os.path.join(settings.TMP_PATH, "icon", upload_hash) dirname = addon.get_icon_dir() destination = os.path.join(dirname, "%s" % addon.id) remove_icons(destination) tasks.resize_icon.delay(upload_path, destination, mkt.CONTENT_ICON_SIZES, set_modified_on=[addon]) return super(AppFormMedia, self).save(commit)
def save(self, addon, commit=True): if self.cleaned_data['icon_upload_hash']: upload_hash = self.cleaned_data['icon_upload_hash'] upload_path = os.path.join(settings.TMP_PATH, 'icon', upload_hash) dirname = addon.get_icon_dir() destination = os.path.join(dirname, '%s' % addon.id) remove_icons(destination) tasks.resize_icon.delay(upload_path, destination, mkt.CONTENT_ICON_SIZES, set_modified_on=[addon]) return super(AppFormMedia, self).save(commit)
def save_icon(webapp, content): tmp_dst = os.path.join(settings.TMP_PATH, "icon", uuid.uuid4().hex) with storage.open(tmp_dst, "wb") as fd: fd.write(content) dirname = webapp.get_icon_dir() destination = os.path.join(dirname, "%s" % webapp.id) remove_icons(destination) resize_icon(tmp_dst, destination, mkt.APP_ICON_SIZES, set_modified_on=[webapp]) # Need to set the icon type so .get_icon_url() works # normally submit step 4 does it through AppFormMedia, # but we want to beat them to the punch. # resize_icon outputs pngs, so we know it's 'image/png' webapp.icon_type = "image/png" webapp.save()
def save_icon(obj, icon_content): """ Saves the icon for `obj` to its final destination. `obj` can be an app or a website. """ tmp_dst = os.path.join(settings.TMP_PATH, "icon", uuid.uuid4().hex) with storage.open(tmp_dst, "wb") as fd: fd.write(icon_content) dirname = obj.get_icon_dir() destination = os.path.join(dirname, "%s" % obj.pk) remove_icons(destination) icon_hash = resize_icon(tmp_dst, destination, mkt.CONTENT_ICON_SIZES, set_modified_on=[obj]) # Need to set icon type so .get_icon_url() works normally # submit step 4 does it through AppFormMedia, but we want to beat them to # the punch. resize_icon outputs pngs so we know it's 'image/png'. obj.icon_hash = icon_hash["icon_hash"] # In case, we're running not async. obj.icon_type = "image/png" obj.save()
def save_icon(obj, icon_content): """ Saves the icon for `obj` to its final destination. `obj` can be an app or a website. """ tmp_dst = os.path.join(settings.TMP_PATH, 'icon', uuid.uuid4().hex) with storage.open(tmp_dst, 'wb') as fd: fd.write(icon_content) dirname = obj.get_icon_dir() destination = os.path.join(dirname, '%s' % obj.pk) remove_icons(destination) resize_icon(tmp_dst, destination, mkt.CONTENT_ICON_SIZES, set_modified_on=[obj]) # Need to set the icon type so .get_icon_url() works # normally submit step 4 does it through AppFormMedia, # but we want to beat them to the punch. # resize_icon outputs pngs, so we know it's 'image/png' obj.icon_type = 'image/png' obj.save()