Commit | Line | Data |
---|---|---|
9bfe1d8e E |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011 Free Software Foundation, Inc | |
3 | # | |
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License as published by | |
6 | # the Free Software Foundation, either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU Affero General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
aba81c9f E |
16 | |
17 | ||
1c63ad5d | 18 | from webob import exc |
aba81c9f | 19 | |
9150244a | 20 | from mediagoblin.util import render_to_response, redirect |
aba81c9f | 21 | from mediagoblin.edit import forms |
0732236e | 22 | from mediagoblin.edit.lib import may_edit_media |
8cd5d4f8 | 23 | from mediagoblin.decorators import require_active_login, get_user_media_entry |
aba81c9f | 24 | |
c849e690 | 25 | |
8cd5d4f8 | 26 | @get_user_media_entry |
aba81c9f E |
27 | @require_active_login |
28 | def edit_media(request, media): | |
c849e690 E |
29 | if not may_edit_media(request, media): |
30 | return exc.HTTPForbidden() | |
31 | ||
aba81c9f E |
32 | form = forms.EditForm(request.POST, |
33 | title = media['title'], | |
34 | slug = media['slug'], | |
35 | description = media['description']) | |
36 | ||
98857207 | 37 | if request.method == 'POST' and form.validate(): |
d5e90fe4 CAW |
38 | # Make sure there isn't already a MediaEntry with such a slug |
39 | # and userid. | |
40 | existing_user_slug_entries = request.db.MediaEntry.find( | |
41 | {'slug': request.POST['slug'], | |
42 | 'uploader': media['uploader'], | |
43 | '_id': {'$ne': media['_id']}}).count() | |
44 | ||
45 | if existing_user_slug_entries: | |
46 | form.slug.errors.append( | |
47 | u'An entry with that slug already exists for this user.') | |
48 | else: | |
49 | media['title'] = request.POST['title'] | |
44e2da2f JW |
50 | media['description'] = request.POST.get('description') |
51 | ||
52 | import markdown | |
53 | md = markdown.Markdown( | |
54 | safe_mode = 'escape') | |
55 | media['description_html'] = md.convert( | |
56 | media['description']) | |
57 | ||
d5e90fe4 | 58 | media['slug'] = request.POST['slug'] |
747623cc | 59 | media.save() |
d5e90fe4 | 60 | |
9150244a E |
61 | return redirect(request, "mediagoblin.user_pages.media_home", |
62 | user=media.uploader()['username'], media=media['slug']) | |
98857207 | 63 | |
9038c9f9 CAW |
64 | return render_to_response( |
65 | request, | |
c9c24934 E |
66 | 'mediagoblin/edit/edit.html', |
67 | {'media': media, | |
68 | 'form': form}) |