Esempio n. 1
0
def generate_hosted_app(name, categories, developer_name,
                        privacy_policy=None, device_types=(), status=4,
                        rated=True, uses_flash=False, default_locale='en-US',
                        **spec):
    generated_url = 'http://%s.testmanifest.com/fake-data/manifest.webapp' % (
        slugify(name),)
    a = app_factory(categories=categories, name=name, complete=False,
                    privacy_policy=spec.get('privacy_policy'),
                    file_kw={'status': status, 'uses_flash': uses_flash},
                    default_locale=default_locale, rated=rated,
                    manifest_url=spec.get('manifest_url', generated_url))
    if device_types:
        for dt in device_types:
            a.webappdevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt])
    else:
        a.webappdevicetype_set.create(device_type=1)
    a.versions.latest().update(reviewed=datetime.datetime.now(),
                               _developer_name=developer_name)
    if 'manifest_file' in spec:
        AppManifest.objects.create(
            version=a._latest_version,
            manifest=open(spec['manifest_file']).read())
    else:
        generate_hosted_manifest(a)
    return a
Esempio n. 2
0
def generate_hosted_app(name, categories, developer_name,
                        privacy_policy=None, device_types=(), status=4,
                        rated=True, uses_flash=False, default_locale='en-US',
                        **spec):
    generated_url = 'http://%s.testmanifest.com/fake-data/manifest.webapp' % (
        slugify(name),)
    a = app_factory(categories=categories, name=name, complete=False,
                    privacy_policy=spec.get('privacy_policy'),
                    file_kw={'status': status, 'uses_flash': uses_flash},
                    default_locale=default_locale, rated=rated,
                    manifest_url=spec.get('manifest_url', generated_url))
    if device_types:
        for dt in device_types:
            a.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt])
    else:
        a.addondevicetype_set.create(device_type=1)
    a.versions.latest().update(reviewed=datetime.datetime.now(),
                               _developer_name=developer_name)
    if 'manifest_file' in spec:
        AppManifest.objects.create(
            version=a._latest_version,
            manifest=open(spec['manifest_file']).read())
    else:
        generate_hosted_manifest(a)
    return a
Esempio n. 3
0
def generate_hosted_app(
    name,
    categories,
    developer_name,
    privacy_policy=None,
    device_types=(),
    status=4,
    rated=True,
    default_locale="en-US",
    **spec
):
    generated_url = "http://%s.testmanifest.com/fake-data/manifest.webapp" % (slugify(name),)
    a = app_factory(
        categories=categories,
        name=name,
        complete=False,
        privacy_policy=spec.get("privacy_policy"),
        file_kw={"status": status},
        default_locale=default_locale,
        rated=rated,
        manifest_url=spec.get("manifest_url", generated_url),
    )
    if device_types:
        for dt in device_types:
            a.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt])
    else:
        a.addondevicetype_set.create(device_type=1)
    a.versions.latest().update(reviewed=datetime.datetime.now(), _developer_name=developer_name)
    if "manifest_file" in spec:
        AppManifest.objects.create(version=a._latest_version, manifest=open(spec["manifest_file"]).read())
    else:
        generate_hosted_manifest(a)
    return a
Esempio n. 4
0
def clean_tags(request, tags, max_tags=None):
    """
    Blocked tags are not allowed.
    Restricted tags can only be edited by Reviewers and Curators.
    """
    target = [slugify(t, spaces=True, lower=True) for t in tags.split(',')]
    target = set(filter(None, target))

    min_len = mkt.MIN_TAG_LENGTH
    max_len = Tag._meta.get_field('tag_text').max_length
    max_tags = max_tags or mkt.MAX_TAGS
    total = len(target)

    blocked = (Tag.objects.values_list('tag_text',
                                       flat=True).filter(tag_text__in=target,
                                                         blocked=True))
    if blocked:
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext(u'Invalid tag: {0}', 'Invalid tags: {0}',
                       len(blocked)).format(', '.join(blocked))
        raise forms.ValidationError(msg)

    restricted = (Tag.objects.values_list('tag_text', flat=True).filter(
        tag_text__in=target, restricted=True))
    if restricted and not can_edit_restricted_tags(request):
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext(u'"{0}" is a reserved tag and cannot be used.',
                       u'"{0}" are reserved tags and cannot be used.',
                       len(restricted)).format('", "'.join(restricted))
        raise forms.ValidationError(msg)
    else:
        # Admin's restricted tags don't count towards the limit.
        total = len(target - set(restricted))

    if total > max_tags:
        num = total - max_tags
        msg = ngettext(u'You have {0} too many tags.',
                       u'You have {0} too many tags.', num).format(num)
        raise forms.ValidationError(msg)

    if any(t for t in target if len(t) > max_len):
        raise forms.ValidationError(
            _(u'All tags must be %s characters '
              u'or less after invalid characters are removed.' % max_len))

    if any(t for t in target if len(t) < min_len):
        msg = ngettext(u'All tags must be at least {0} character.',
                       u'All tags must be at least {0} characters.',
                       min_len).format(min_len)
        raise forms.ValidationError(msg)

    return target
Esempio n. 5
0
def clean_tags(request, tags, max_tags=None):
    """
    Blocked tags are not allowed.
    Restricted tags can only be edited by Reviewers and Curators.
    """
    target = [slugify(t, spaces=True, lower=True) for t in tags.split(',')]
    target = set(filter(None, target))

    min_len = mkt.MIN_TAG_LENGTH
    max_len = Tag._meta.get_field('tag_text').max_length
    max_tags = max_tags or mkt.MAX_TAGS
    total = len(target)

    blocked = (Tag.objects.values_list('tag_text', flat=True)
               .filter(tag_text__in=target, blocked=True))
    if blocked:
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext(u'Invalid tag: {0}', 'Invalid tags: {0}',
                       len(blocked)).format(', '.join(blocked))
        raise forms.ValidationError(msg)

    restricted = (Tag.objects.values_list('tag_text', flat=True)
                     .filter(tag_text__in=target, restricted=True))
    if restricted and not can_edit_restricted_tags(request):
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext(u'"{0}" is a reserved tag and cannot be used.',
                       u'"{0}" are reserved tags and cannot be used.',
                       len(restricted)).format('", "'.join(restricted))
        raise forms.ValidationError(msg)
    else:
        # Admin's restricted tags don't count towards the limit.
        total = len(target - set(restricted))

    if total > max_tags:
        num = total - max_tags
        msg = ngettext(u'You have {0} too many tags.',
                       u'You have {0} too many tags.', num).format(num)
        raise forms.ValidationError(msg)

    if any(t for t in target if len(t) > max_len):
        raise forms.ValidationError(
            _(u'All tags must be %s characters '
              u'or less after invalid characters are removed.' % max_len))

    if any(t for t in target if len(t) < min_len):
        msg = ngettext(u'All tags must be at least {0} character.',
                       u'All tags must be at least {0} characters.',
                       min_len).format(min_len)
        raise forms.ValidationError(msg)

    return target
Esempio n. 6
0
    def save(self, commit=False):
        form = super(WebsiteForm, self).save(commit=False)

        keywords_new = self.cleaned_data['keywords']
        keywords_old = [slugify(keyword, spaces=True)
                        for keyword in self.instance.keywords.values_list(
                            'tag_text', flat=True)]
        for k in set(keywords_new) - set(keywords_old):
            Tag(tag_text=k).save_tag(self.instance)
        for k in set(keywords_old) - set(keywords_new):
            Tag(tag_text=k).remove_tag(self.instance)

        form.save()
        return form
Esempio n. 7
0
    def save(self, commit=False):
        form = super(WebsiteForm, self).save(commit=False)

        keywords_new = self.cleaned_data['keywords']
        keywords_old = [
            slugify(keyword, spaces=True)
            for keyword in self.instance.keywords.values_list('tag_text',
                                                              flat=True)
        ]
        for k in set(keywords_new) - set(keywords_old):
            Tag(tag_text=k).save_tag(self.instance)
        for k in set(keywords_old) - set(keywords_new):
            Tag(tag_text=k).remove_tag(self.instance)

        form.save()
        return form
Esempio n. 8
0
def clean_tags(request, tags):
    target = [slugify(t, spaces=True, lower=True) for t in tags.split(",")]
    target = set(filter(None, target))

    min_len = mkt.MIN_TAG_LENGTH
    max_len = Tag._meta.get_field("tag_text").max_length
    max_tags = mkt.MAX_TAGS
    total = len(target)

    blocked = Tag.objects.values_list("tag_text", flat=True).filter(tag_text__in=target, blocked=True)
    if blocked:
        # L10n: {0} is a single tag or a comma-separated list of tags.
        msg = ngettext(u"Invalid tag: {0}", "Invalid tags: {0}", len(blocked)).format(", ".join(blocked))
        raise forms.ValidationError(msg)

    restricted = Tag.objects.values_list("tag_text", flat=True).filter(tag_text__in=target, restricted=True)
    if not acl.action_allowed(request, "Apps", "Edit"):
        if restricted:
            # L10n: {0} is a single tag or a comma-separated list of tags.
            msg = ngettext(
                u'"{0}" is a reserved tag and cannot be used.',
                u'"{0}" are reserved tags and cannot be used.',
                len(restricted),
            ).format('", "'.join(restricted))
            raise forms.ValidationError(msg)
    else:
        # Admin's restricted tags don't count towards the limit.
        total = len(target - set(restricted))

    if total > max_tags:
        num = total - max_tags
        msg = ngettext(u"You have {0} too many tags.", u"You have {0} too many tags.", num).format(num)
        raise forms.ValidationError(msg)

    if any(t for t in target if len(t) > max_len):
        raise forms.ValidationError(
            _(u"All tags must be %s characters " u"or less after invalid characters are removed." % max_len)
        )

    if any(t for t in target if len(t) < min_len):
        msg = ngettext(
            u"All tags must be at least {0} character.", u"All tags must be at least {0} characters.", min_len
        ).format(min_len)
        raise forms.ValidationError(msg)

    return target
Esempio n. 9
0
    def save(self, addon, commit=False):
        # We ignore `commit`, since we need it to be `False` so we can save
        # the ManyToMany fields on our own.
        addonform = super(AppFormBasic, self).save(commit=False)
        addonform.save()

        if 'manifest_url' in self.changed_data:
            before_url = self.old_manifest_url
            after_url = self.cleaned_data['manifest_url']

            # If a non-admin edited the manifest URL, add to Re-review Queue.
            if not acl.action_allowed(self.request, 'Admin', '%'):
                log.info(u'[Webapp:%s] (Re-review) Manifest URL changed '
                         u'from %s to %s'
                         % (self.instance, before_url, after_url))

                msg = (_(u'Manifest URL changed from {before_url} to '
                         u'{after_url}')
                       .format(before_url=before_url, after_url=after_url))

                RereviewQueue.flag(self.instance,
                                   mkt.LOG.REREVIEW_MANIFEST_URL_CHANGE, msg)

            # Refetch the new manifest.
            log.info('Manifest %s refreshed for %s'
                     % (addon.manifest_url, addon))
            update_manifests.delay([self.instance.id])

        tags_new = self.cleaned_data['tags']
        tags_old = [slugify(t, spaces=True) for t in self.get_tags(addon)]

        add_tags = set(tags_new) - set(tags_old)
        del_tags = set(tags_old) - set(tags_new)

        # Add new tags.
        for t in add_tags:
            Tag(tag_text=t).save_tag(addon)

        # Remove old tags.
        for t in del_tags:
            Tag(tag_text=t).remove_tag(addon)

        return addonform
Esempio n. 10
0
 def check(x, y):
     eq_(slugify(x), y)
     slug_validator(slugify(x))
Esempio n. 11
0
 def check(x, y):
     eq_(slugify(x), y)
     slug_validator(slugify(x))