Exemple #1
0
def edit_media(request, media):
    if not may_edit_media(request, media):
        return exc.HTTPForbidden()

    defaults = dict(
        title=media.title,
        slug=media.slug,
        description=media.description,
        tags=media_tags_as_string(media.tags),
        license=media.license)

    form = forms.EditForm(
        request.form,
        **defaults)

    if request.method == 'POST' and form.validate():
        # Make sure there isn't already a MediaEntry with such a slug
        # and userid.
        slug_used = check_media_slug_used(request.db, media.uploader,
                request.form['slug'], media.id)

        if slug_used:
            form.slug.errors.append(
                _(u'An entry with that slug already exists for this user.'))
        else:
            media.title = unicode(request.form['title'])
            media.description = unicode(request.form.get('description'))
            media.tags = convert_to_tag_list_of_dicts(
                                   request.form.get('tags'))

            media.license = unicode(request.form.get('license', '')) or None

            media.slug = unicode(request.form['slug'])

            media.save()

            return exc.HTTPFound(
                location=media.url_for_self(request.urlgen))

    if request.user.is_admin \
            and media.uploader != request.user._id \
            and request.method != 'POST':
        messages.add_message(
            request, messages.WARNING,
            _("You are editing another user's media. Proceed with caution."))

    return render_to_response(
        request,
        'mediagoblin/edit/edit.html',
        {'media': media,
         'form': form})
Exemple #2
0
    def generate_slug(self):
        # import this here due to a cyclic import issue
        # (db.models -> db.mixin -> db.util -> db.models)
        from mediagoblin.db.util import check_media_slug_used

        self.slug = slugify(self.title)

        duplicate = check_media_slug_used(mg_globals.database, self.uploader, self.slug, self.id)

        if duplicate:
            if self.id is not None:
                self.slug = u"%s-%s" % (self.id, self.slug)
            else:
                self.slug = None
Exemple #3
0
def edit_media(request, media):
    if not may_edit_media(request, media):
        raise Forbidden("User may not edit this media")

    defaults = dict(
        title=media.title,
        slug=media.slug,
        description=media.description,
        tags=media_tags_as_string(media.tags),
        license=media.license)

    form = forms.EditForm(
        request.form,
        **defaults)

    if request.method == 'POST' and form.validate():
        # Make sure there isn't already a MediaEntry with such a slug
        # and userid.
        slug = slugify(form.slug.data)
        slug_used = check_media_slug_used(media.uploader, slug, media.id)

        if slug_used:
            form.slug.errors.append(
                _(u'An entry with that slug already exists for this user.'))
        else:
            media.title = form.title.data
            media.description = form.description.data
            media.tags = convert_to_tag_list_of_dicts(
                                   form.tags.data)

            media.license = unicode(form.license.data) or None
            media.slug = slug
            media.save()

            return redirect_obj(request, media)

    if request.user.has_privilege(u'admin') \
            and media.uploader != request.user.id \
            and request.method != 'POST':
        messages.add_message(
            request, messages.WARNING,
            _("You are editing another user's media. Proceed with caution."))

    return render_to_response(
        request,
        'mediagoblin/edit/edit.html',
        {'media': media,
         'form': form})
Exemple #4
0
def edit_media(request, media):
    # If media is not processed, return NotFound.
    if not media.state == 'processed':
        return render_404(request)

    if not may_edit_media(request, media):
        raise Forbidden("User may not edit this media")

    defaults = dict(title=media.title,
                    slug=media.slug,
                    description=media.description,
                    tags=media_tags_as_string(media.tags),
                    license=media.license)

    form = forms.EditForm(request.method == 'POST' and request.form or None,
                          **defaults)

    if request.method == 'POST' and form.validate():
        # Make sure there isn't already a MediaEntry with such a slug
        # and userid.
        slug = slugify(form.slug.data)
        slug_used = check_media_slug_used(media.actor, slug, media.id)

        if slug_used:
            form.slug.errors.append(
                _('An entry with that slug already exists for this user.'))
        else:
            media.title = form.title.data
            media.description = form.description.data
            media.tags = convert_to_tag_list_of_dicts(form.tags.data)

            media.license = str(form.license.data) or None
            media.slug = slug
            media.save()

            return redirect_obj(request, media)

    if request.user.has_privilege('admin') \
            and media.actor != request.user.id \
            and request.method != 'POST':
        messages.add_message(
            request, messages.WARNING,
            _("You are editing another user's media. Proceed with caution."))

    return render_to_response(request, 'mediagoblin/edit/edit.html', {
        'media': media,
        'form': form
    })
Exemple #5
0
def edit_media(request, media):
    if not may_edit_media(request, media):
        raise Forbidden("User may not edit this media")

    defaults = dict(
        title=media.title,
        slug=media.slug,
        description=media.description,
        tags=media_tags_as_string(media.tags),
        license=media.license,
    )

    form = forms.EditForm(request.form, **defaults)

    if request.method == "POST" and form.validate():
        # Make sure there isn't already a MediaEntry with such a slug
        # and userid.
        slug_used = check_media_slug_used(request.db, media.uploader, request.form["slug"], media.id)

        if slug_used:
            form.slug.errors.append(_(u"An entry with that slug already exists for this user."))
        else:
            media.title = unicode(request.form["title"])
            media.description = unicode(request.form.get("description"))
            media.tags = convert_to_tag_list_of_dicts(request.form.get("tags"))

            media.license = unicode(request.form.get("license", "")) or None

            media.slug = unicode(request.form["slug"])

            media.save()

            return redirect(request, location=media.url_for_self(request.urlgen))

    if request.user.is_admin and media.uploader != request.user.id and request.method != "POST":
        messages.add_message(
            request, messages.WARNING, _("You are editing another user's media. Proceed with caution.")
        )

    return render_to_response(request, "mediagoblin/edit/edit.html", {"media": media, "form": form})
    def check_slug_used(self, slug):
        # import this here due to a cyclic import issue
        # (db.models -> db.mixin -> db.util -> db.models)
        from mediagoblin.db.util import check_media_slug_used

        return check_media_slug_used(self.uploader, slug, self.id)
Exemple #7
0
    def check_slug_used(self, slug):
        # import this here due to a cyclic import issue
        # (db.models -> db.mixin -> db.util -> db.models)
        from mediagoblin.db.util import check_media_slug_used

        return check_media_slug_used(self.actor, slug, self.id)