def save(self, commit=False): from addons.tasks import (create_persona_preview_images, save_persona_image) data = self.cleaned_data addon = Addon.objects.create(name=data['name'], slug=data.get('slug'), description=data.get('summary'), status=amo.STATUS_PENDING, type=amo.ADDON_PERSONA) addon._current_version = Version.objects.create(addon=addon, version='0') addon.save() # Save header, footer, and preview images. try: header = data['header_hash'] footer = data['footer_hash'] header = os.path.join(settings.TMP_PATH, 'persona_header', header) footer = os.path.join(settings.TMP_PATH, 'persona_footer', footer) dst_root = os.path.join(settings.ADDONS_PATH, str(addon.id)) save_persona_image.delay(src=header, full_dst=os.path.join(dst_root, 'header.png')) save_persona_image.delay(src=footer, full_dst=os.path.join(dst_root, 'footer.png')) create_persona_preview_images.delay(src=header, full_dst=[os.path.join(dst_root, 'preview.png'), os.path.join(dst_root, 'icon.png')], set_modified_on=[addon]) except IOError: addon.delete() raise # Save user info. user = self.request.amo_user AddonUser(addon=addon, user=user).save() # Create Persona instance. p = Persona() p.persona_id = 0 p.addon = addon p.header = 'header.png' p.footer = 'footer.png' if data['accentcolor']: p.accentcolor = data['accentcolor'].lstrip('#') if data['textcolor']: p.textcolor = data['textcolor'].lstrip('#') p.license_id = data['license'] p.submit = datetime.now() p.author = user.name p.display_username = user.username p.save() # Save tags. for t in data['tags']: Tag(tag_text=t).save_tag(addon) # Save categories. AddonCategory(addon=addon, category=data['category']).save() return addon
def save(self, commit=False): from addons.tasks import (create_persona_preview_images, save_persona_image) data = self.cleaned_data addon = Addon.objects.create(slug=data.get('slug'), status=amo.STATUS_PENDING, type=amo.ADDON_PERSONA) addon.name = {'en-US': data['name']} if data.get('summary'): addon.description = {'en-US': data['summary']} addon._current_version = Version.objects.create(addon=addon, version='0') addon.save() # Save header, footer, and preview images. try: header = data['header_hash'] footer = data['footer_hash'] header = os.path.join(settings.TMP_PATH, 'persona_header', header) footer = os.path.join(settings.TMP_PATH, 'persona_footer', footer) dst_root = os.path.join(settings.ADDONS_PATH, str(addon.id)) save_persona_image.delay(src=header, full_dst=os.path.join( dst_root, 'header.png')) save_persona_image.delay(src=footer, full_dst=os.path.join( dst_root, 'footer.png')) create_persona_preview_images.delay( src=header, full_dst=[ os.path.join(dst_root, 'preview.png'), os.path.join(dst_root, 'icon.png') ], set_modified_on=[addon]) except IOError: addon.delete() raise # Save user info. user = self.request.amo_user AddonUser(addon=addon, user=user).save() # Create Persona instance. p = Persona() p.persona_id = 0 p.addon = addon p.header = 'header.png' p.footer = 'footer.png' if data['accentcolor']: p.accentcolor = data['accentcolor'].lstrip('#') if data['textcolor']: p.textcolor = data['textcolor'].lstrip('#') p.license = data['license'] p.submit = datetime.now() p.author = user.name p.display_username = user.username p.save() # Save tags. for t in data['tags']: Tag(tag_text=t).save_tag(addon) # Save categories. AddonCategory(addon=addon, category=data['category']).save() return addon