Exemplo n.º 1
0
    def save(self, commit=False):
        from .tasks import create_persona_preview_image, save_persona_image
        # We ignore `commit`, since we need it to be `False` so we can save
        # the ManyToMany fields on our own.
        addon = super(NewPersonaForm, self).save(commit=False)
        addon.status = amo.STATUS_UNREVIEWED
        addon.type = amo.ADDON_PERSONA
        addon.save()
        addon._current_version = Version.objects.create(addon=addon,
                                                        version='0')
        addon.save()
        amo.log(amo.LOG.CREATE_ADDON, addon)
        log.debug('New persona %r uploaded' % addon)

        data = self.cleaned_data

        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 = os.path.join(settings.PERSONAS_PATH, str(addon.id))

        # Save header, footer, and preview images.
        save_persona_image(src=header, dst=dst, img_basename='header.jpg')
        save_persona_image(src=footer, dst=dst, img_basename='footer.jpg')
        create_persona_preview_image(src=header, dst=dst,
                                     img_basename='preview.jpg',
                                     set_modified_on=[addon])

        # Save user info.
        user = self.request.amo_user
        AddonUser(addon=addon, user=user).save()

        p = Persona()
        p.persona_id = 0
        p.addon = addon
        p.header = 'header.jpg'
        p.footer = 'footer.jpg'
        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.
        tb_c = Category.objects.get(application=amo.THUNDERBIRD.id,
                                    name__id=data['category'].name_id)
        AddonCategory(addon=addon, category=data['category']).save()
        AddonCategory(addon=addon, category=tb_c).save()

        return addon
Exemplo n.º 2
0
    def save(self, commit=False):
        from .tasks import create_persona_preview_image, save_persona_image
        # We ignore `commit`, since we need it to be `False` so we can save
        # the ManyToMany fields on our own.
        addon = super(NewPersonaForm, self).save(commit=False)
        addon.status = amo.STATUS_UNREVIEWED
        addon.type = amo.ADDON_PERSONA
        addon.save()
        addon._current_version = Version.objects.create(addon=addon,
                                                        version='0')
        addon.save()
        amo.log(amo.LOG.CREATE_ADDON, addon)
        log.debug('New persona %r uploaded' % addon)

        data = self.cleaned_data

        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 = os.path.join(settings.PERSONAS_PATH, str(addon.id))

        # Save header, footer, and preview images.
        save_persona_image(src=header, dst=dst, img_basename='header.jpg')
        save_persona_image(src=footer, dst=dst, img_basename='footer.jpg')
        create_persona_preview_image(src=header, dst=dst,
                                     img_basename='preview.jpg',
                                     set_modified_on=[addon])

        # Save user info.
        user = self.request.amo_user
        AddonUser(addon=addon, user=user).save()

        p = Persona()
        p.persona_id = 0
        p.addon = addon
        p.header = 'header'
        p.footer = 'footer'
        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.
        tb_c = Category.objects.get(application=amo.THUNDERBIRD.id,
                                    name__id=data['category'].name_id)
        AddonCategory(addon=addon, category=data['category']).save()
        AddonCategory(addon=addon, category=tb_c).save()

        return addon
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def save(self, commit=False):
        from addons.tasks import (create_persona_preview_image,
                                  save_persona_image)
        data = self.cleaned_data
        addon = Addon.objects.create(id=None,
                                     name=data['name'],
                                     slug=data['slug'],
                                     description=data['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 = os.path.join(settings.PERSONAS_PATH, str(addon.id))
            save_persona_image(src=header, dst=dst, img_basename='header.jpg')
            save_persona_image(src=footer, dst=dst, img_basename='footer.jpg')
            create_persona_preview_image(src=header,
                                         dst=dst,
                                         img_basename='preview.jpg',
                                         set_modified_on=[addon])
        except IOError:
            addon.delete()
            raise IOError

        # 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'
        p.footer = 'footer'
        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 categories.
        tb_c, created = Category.objects.get_or_create(
            application_id=amo.THUNDERBIRD.id,
            name__id=data['category'].name.id,
            type=amo.ADDON_PERSONA)
        AddonCategory(addon=addon, category=data['category']).save()
        AddonCategory(addon=addon, category=tb_c).save()

        return addon
Exemplo n.º 5
0
    def save(self, commit=False):
        from addons.tasks import create_persona_preview_image, save_persona_image

        data = self.cleaned_data
        addon = Addon.objects.create(
            id=None,
            name=data["name"],
            slug=data["slug"],
            description=data["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 = os.path.join(settings.PERSONAS_PATH, str(addon.id))
            save_persona_image(src=header, dst=dst, img_basename="header.jpg")
            save_persona_image(src=footer, dst=dst, img_basename="footer.jpg")
            create_persona_preview_image(src=header, dst=dst, img_basename="preview.jpg", set_modified_on=[addon])
        except IOError:
            addon.delete()
            raise IOError

        # 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"
        p.footer = "footer"
        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 categories.
        tb_c, created = Category.objects.get_or_create(
            application_id=amo.THUNDERBIRD.id, name__id=data["category"].name.id, type=amo.ADDON_PERSONA
        )
        AddonCategory(addon=addon, category=data["category"]).save()
        AddonCategory(addon=addon, category=tb_c).save()

        return addon
Exemplo n.º 6
0
    def save(self, commit=False):
        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('description'):
            addon.description = data['description']
        addon._current_version = Version.objects.create(addon=addon,
                                                        version='0')
        addon.save()

        # Create Persona instance.
        p = Persona()
        p.persona_id = 0
        p.addon = addon
        p.header = 'header.png'
        if data['footer_hash']:
            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()
        user = self.request.amo_user
        p.author = user.username
        p.display_username = user.name
        p.save()

        # Save header, footer, and preview images.
        save_theme.delay(data['header_hash'], data['footer_hash'], addon)

        # Save user info.
        addon.addonuser_set.create(user=user, role=amo.AUTHOR_ROLE_OWNER)

        # 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
Exemplo n.º 7
0
    def save(self, commit=False):
        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('description'):
            addon.description = data['description']
        addon._current_version = Version.objects.create(addon=addon,
                                                        version='0')
        addon.save()

        # Create Persona instance.
        p = Persona()
        p.persona_id = 0
        p.addon = addon
        p.header = 'header.png'
        if data['footer_hash']:
            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()
        user = self.request.user
        p.author = user.username
        p.display_username = user.name
        p.save()

        # Save header, footer, and preview images.
        save_theme.delay(data['header_hash'], data['footer_hash'], addon)

        # Save user info.
        addon.addonuser_set.create(user=user, role=amo.AUTHOR_ROLE_OWNER)

        # 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
Exemplo n.º 8
0
    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