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 | |
d9ed098e | 20 | from mediagoblin import messages |
44e51d34 | 21 | from mediagoblin.util import render_to_response, redirect, clean_html |
aba81c9f | 22 | from mediagoblin.edit import forms |
0732236e | 23 | from mediagoblin.edit.lib import may_edit_media |
8cd5d4f8 | 24 | from mediagoblin.decorators import require_active_login, get_user_media_entry |
aba81c9f | 25 | |
44e51d34 JW |
26 | import markdown |
27 | ||
c849e690 | 28 | |
8cd5d4f8 | 29 | @get_user_media_entry |
aba81c9f E |
30 | @require_active_login |
31 | def edit_media(request, media): | |
c849e690 E |
32 | if not may_edit_media(request, media): |
33 | return exc.HTTPForbidden() | |
34 | ||
aba81c9f E |
35 | form = forms.EditForm(request.POST, |
36 | title = media['title'], | |
37 | slug = media['slug'], | |
38 | description = media['description']) | |
39 | ||
98857207 | 40 | if request.method == 'POST' and form.validate(): |
d5e90fe4 CAW |
41 | # Make sure there isn't already a MediaEntry with such a slug |
42 | # and userid. | |
43 | existing_user_slug_entries = request.db.MediaEntry.find( | |
44 | {'slug': request.POST['slug'], | |
45 | 'uploader': media['uploader'], | |
46 | '_id': {'$ne': media['_id']}}).count() | |
47 | ||
48 | if existing_user_slug_entries: | |
49 | form.slug.errors.append( | |
50 | u'An entry with that slug already exists for this user.') | |
51 | else: | |
52 | media['title'] = request.POST['title'] | |
44e2da2f JW |
53 | media['description'] = request.POST.get('description') |
54 | ||
44e2da2f JW |
55 | md = markdown.Markdown( |
56 | safe_mode = 'escape') | |
44e51d34 JW |
57 | media['description_html'] = clean_html( |
58 | md.convert( | |
59 | media['description'])) | |
44e2da2f | 60 | |
d5e90fe4 | 61 | media['slug'] = request.POST['slug'] |
747623cc | 62 | media.save() |
d5e90fe4 | 63 | |
9150244a E |
64 | return redirect(request, "mediagoblin.user_pages.media_home", |
65 | user=media.uploader()['username'], media=media['slug']) | |
98857207 | 66 | |
9038c9f9 CAW |
67 | return render_to_response( |
68 | request, | |
c9c24934 E |
69 | 'mediagoblin/edit/edit.html', |
70 | {'media': media, | |
71 | 'form': form}) | |
630b57a3 | 72 | |
46fd661e | 73 | |
630b57a3 | 74 | @require_active_login |
75 | def edit_profile(request): | |
76 | ||
0bf34072 | 77 | user = request.user |
630b57a3 | 78 | form = forms.EditProfileForm(request.POST, |
0bf34072 | 79 | url = user.get('url'), |
80 | bio = user.get('bio')) | |
630b57a3 | 81 | |
82 | if request.method == 'POST' and form.validate(): | |
83 | user['url'] = request.POST['url'] | |
84 | user['bio'] = request.POST['bio'] | |
85 | user.save() | |
86 | ||
d9ed098e CFD |
87 | messages.add_message(request, |
88 | messages.SUCCESS, | |
89 | 'Profile edited!') | |
90 | return redirect(request, "mediagoblin.edit.profile") | |
630b57a3 | 91 | |
92 | return render_to_response( | |
93 | request, | |
94 | 'mediagoblin/edit/edit_profile.html', | |
95 | {'user': user, | |
96 | 'form': form}) |