1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
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.
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.
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/>.
20 from mediagoblin
.util
import render_to_response
, redirect
, clean_html
21 from mediagoblin
.edit
import forms
22 from mediagoblin
.edit
.lib
import may_edit_media
23 from mediagoblin
.decorators
import require_active_login
, get_user_media_entry
30 def edit_media(request
, media
):
31 if not may_edit_media(request
, media
):
32 return exc
.HTTPForbidden()
34 form
= forms
.EditForm(request
.POST
,
35 title
= media
['title'],
37 description
= media
['description'])
39 if request
.method
== 'POST' and form
.validate():
40 # Make sure there isn't already a MediaEntry with such a slug
42 existing_user_slug_entries
= request
.db
.MediaEntry
.find(
43 {'slug': request
.POST
['slug'],
44 'uploader': media
['uploader'],
45 '_id': {'$ne': media
['_id']}}).count()
47 if existing_user_slug_entries
:
48 form
.slug
.errors
.append(
49 u
'An entry with that slug already exists for this user.')
51 media
['title'] = request
.POST
['title']
52 media
['description'] = request
.POST
.get('description')
54 md
= markdown
.Markdown(
56 media
['description_html'] = clean_html(
58 media
['description']))
60 media
['slug'] = request
.POST
['slug']
63 return redirect(request
, "mediagoblin.user_pages.media_home",
64 user
=media
.uploader()['username'], media
=media
['slug'])
66 return render_to_response(
68 'mediagoblin/edit/edit.html',
74 def edit_profile(request
):
77 form
= forms
.EditProfileForm(request
.POST
,
78 url
= user
.get('url'),
79 bio
= user
.get('bio'))
81 if request
.method
== 'POST' and form
.validate():
82 user
['url'] = request
.POST
['url']
83 user
['bio'] = request
.POST
['bio']
86 return redirect(request
, "index", user
=user
['username'])
88 return render_to_response(
90 'mediagoblin/edit/edit_profile.html',