aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/app.py28
-rw-r--r--mediagoblin/auth/forms.py12
-rw-r--r--mediagoblin/edit/forms.py11
-rw-r--r--mediagoblin/edit/views.py11
-rw-r--r--mediagoblin/middleware/__init__.py19
-rw-r--r--mediagoblin/middleware/noop.py26
-rw-r--r--mediagoblin/static/css/base.css20
-rw-r--r--mediagoblin/submit/forms.py3
-rw-r--r--mediagoblin/templates/mediagoblin/root.html2
-rw-r--r--mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html24
-rw-r--r--mediagoblin/templates/mediagoblin/utils/pagination.html17
-rw-r--r--mediagoblin/user_pages/forms.py6
-rw-r--r--mediagoblin/user_pages/views.py2
-rw-r--r--mediagoblin/util.py2
14 files changed, 130 insertions, 53 deletions
diff --git a/mediagoblin/app.py b/mediagoblin/app.py
index dff61750..45b5e3ce 100644
--- a/mediagoblin/app.py
+++ b/mediagoblin/app.py
@@ -20,7 +20,7 @@ import urllib
import routes
from webob import Request, exc
-from mediagoblin import routing, util
+from mediagoblin import routing, util, middleware
from mediagoblin.mg_globals import setup_globals
from mediagoblin.init.celery import setup_celery_from_config
from mediagoblin.init import (get_jinja_loader, get_staticdirector,
@@ -61,7 +61,7 @@ class MediaGoblinApp(object):
# Get the template environment
self.template_loader = get_jinja_loader(
app_config.get('user_template_path'))
-
+
# Set up storage systems
self.public_store, self.queue_store = setup_storage()
@@ -94,11 +94,22 @@ class MediaGoblinApp(object):
# matters in always eager mode :)
setup_workbench()
+ # instantiate application middleware
+ self.middleware = [util.import_component(m)(self)
+ for m in middleware.ENABLED_MIDDLEWARE]
+
+
def __call__(self, environ, start_response):
request = Request(environ)
- path_info = request.path_info
+
+ # pass the request through our middleware classes
+ for m in self.middleware:
+ response = m.process_request(request)
+ if response is not None:
+ return response(environ, start_response)
## Routing / controller loading stuff
+ path_info = request.path_info
route_match = self.routing.match(path_info)
## Attach utilities to the request object
@@ -110,7 +121,7 @@ class MediaGoblinApp(object):
# Also attach a few utilities from request.app for convenience?
request.app = self
request.locale = util.get_locale_from_request(request)
-
+
request.template_env = util.get_jinja_env(
self.template_loader, request.locale)
request.db = self.db
@@ -139,7 +150,14 @@ class MediaGoblinApp(object):
controller = util.import_component(route_match['controller'])
request.start_response = start_response
- return controller(request)(environ, start_response)
+ # get the response from the controller
+ response = controller(request)
+
+ # pass the response through the middleware
+ for m in self.middleware[::-1]:
+ m.process_response(request, response)
+
+ return response(environ, start_response)
def paste_app_factory(global_config, **app_config):
diff --git a/mediagoblin/auth/forms.py b/mediagoblin/auth/forms.py
index daf7b993..1dfaf095 100644
--- a/mediagoblin/auth/forms.py
+++ b/mediagoblin/auth/forms.py
@@ -24,18 +24,14 @@ class RegistrationForm(wtforms.Form):
_('Username'),
[wtforms.validators.Required(),
wtforms.validators.Length(min=3, max=30),
- wtforms.validators.Regexp(r'^\w+$')],
- description=_(
- u"This is the name other users will identify you with."))
+ wtforms.validators.Regexp(r'^\w+$')])
password = wtforms.PasswordField(
_('Password'),
[wtforms.validators.Required(),
wtforms.validators.Length(min=6, max=30),
wtforms.validators.EqualTo(
'confirm_password',
- _('Passwords must match.'))],
- description=_(
- u"Try to use a strong password!"))
+ _('Passwords must match.'))])
confirm_password = wtforms.PasswordField(
_('Confirm password'),
[wtforms.validators.Required()],
@@ -44,9 +40,7 @@ class RegistrationForm(wtforms.Form):
email = wtforms.TextField(
_('Email address'),
[wtforms.validators.Required(),
- wtforms.validators.Email()],
- description=_(
- u"Your email will never be published."))
+ wtforms.validators.Email()])
class LoginForm(wtforms.Form):
diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py
index 7bf3c6a8..f81d58b2 100644
--- a/mediagoblin/edit/forms.py
+++ b/mediagoblin/edit/forms.py
@@ -25,13 +25,17 @@ class EditForm(wtforms.Form):
title = wtforms.TextField(
_('Title'),
[wtforms.validators.Length(min=0, max=500)])
- slug = wtforms.TextField(
- _('Slug'),
- [wtforms.validators.Required(message=_("The slug can't be empty"))])
description = wtforms.TextAreaField('Description of this work')
tags = wtforms.TextField(
_('Tags'),
[tag_length_validator])
+ slug = wtforms.TextField(
+ _('Slug'),
+ [wtforms.validators.Required(message=_("The slug can't be empty"))],
+ description=_(
+ "The title part of this media's URL. "
+ "You usually don't need to change this."))
+
class EditProfileForm(wtforms.Form):
bio = wtforms.TextAreaField(
@@ -42,6 +46,7 @@ class EditProfileForm(wtforms.Form):
[wtforms.validators.Optional(),
wtforms.validators.URL(message='Improperly formed URL')])
+
class EditAttachmentsForm(wtforms.Form):
attachment_name = wtforms.TextField(
'Title')
diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py
index e1af1a23..11bee110 100644
--- a/mediagoblin/edit/views.py
+++ b/mediagoblin/edit/views.py
@@ -46,9 +46,6 @@ def edit_media(request, media):
description=media['description'],
tags=media_tags_as_string(media['tags']))
- if len(media['attachment_files']):
- defaults['attachment_name'] = media['attachment_files'][0]['name']
-
form = forms.EditForm(
request.POST,
**defaults)
@@ -73,14 +70,6 @@ def edit_media(request, media):
media['description_html'] = cleaned_markdown_conversion(
media['description'])
- if 'attachment_name' in request.POST:
- media['attachment_files'][0]['name'] = \
- request.POST['attachment_name']
-
- if 'attachment_delete' in request.POST \
- and 'y' == request.POST['attachment_delete']:
- del media['attachment_files'][0]
-
media['slug'] = unicode(request.POST['slug'])
media.save()
diff --git a/mediagoblin/middleware/__init__.py b/mediagoblin/middleware/__init__.py
new file mode 100644
index 00000000..586debbf
--- /dev/null
+++ b/mediagoblin/middleware/__init__.py
@@ -0,0 +1,19 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ENABLED_MIDDLEWARE = (
+ 'mediagoblin.middleware.noop:NoOpMiddleware',
+ )
diff --git a/mediagoblin/middleware/noop.py b/mediagoblin/middleware/noop.py
new file mode 100644
index 00000000..28380232
--- /dev/null
+++ b/mediagoblin/middleware/noop.py
@@ -0,0 +1,26 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+class NoOpMiddleware(object):
+
+ def __init__(self, mg_app):
+ self.app = mg_app
+
+ def process_request(self, request):
+ pass
+
+ def process_response(self, request, response):
+ pass
diff --git a/mediagoblin/static/css/base.css b/mediagoblin/static/css/base.css
index 307e2970..d1b891ac 100644
--- a/mediagoblin/static/css/base.css
+++ b/mediagoblin/static/css/base.css
@@ -141,7 +141,7 @@ background-image: -moz-linear-gradient(center top , rgb(134, 212, 177), rgb(109,
/* common website elements */
-.button {
+.button, .cancel_link {
height: 32px;
min-width: 99px;
background-color: #86d4b1;
@@ -165,6 +165,16 @@ background-image: -moz-linear-gradient(center top , rgb(134, 212, 177), rgb(109,
font-weight: bold;
}
+.cancel_link {
+ background-color: #aaa;
+ background-image: -webkit-gradient(linear, left top, left bottom, from(##D2D2D2), to(#aaa));
+ background-image: -webkit-linear-gradient(top, #D2D2D2, #aaa);
+ background-image: -moz-linear-gradient(top, #D2D2D2, #aaa);
+ background-image: -ms-linear-gradient(top, #D2D2D2, #aaa);
+ background-image: -o-linear-gradient(top, #D2D2D2, #aaa);
+ background-image: linear-gradient(top, #D2D2D2, #aaa);
+}
+
.pagination{
text-align: center;
}
@@ -355,3 +365,11 @@ table.media_panel th {
font-weight: bold;
padding-bottom: 4px;
}
+
+
+/* Delete panel */
+
+.delete_checkbox_box {
+ margin-top: 10px;
+ margin-left: 10px;
+} \ No newline at end of file
diff --git a/mediagoblin/submit/forms.py b/mediagoblin/submit/forms.py
index 17df6be6..a999c714 100644
--- a/mediagoblin/submit/forms.py
+++ b/mediagoblin/submit/forms.py
@@ -26,7 +26,8 @@ class SubmitStartForm(wtforms.Form):
title = wtforms.TextField(
_('Title'),
[wtforms.validators.Length(min=0, max=500)])
- description = wtforms.TextAreaField('Description of this work')
+ description = wtforms.TextAreaField(
+ _('Description of this work'))
tags = wtforms.TextField(
_('Tags'),
[tag_length_validator])
diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html
index 8fc62f32..ed4878a5 100644
--- a/mediagoblin/templates/mediagoblin/root.html
+++ b/mediagoblin/templates/mediagoblin/root.html
@@ -35,7 +35,7 @@
</ul>
{% if allow_registration %}
- <p>Excited to join us? To add your own media, make collections and save favorites...<p>
+ <p>Excited to join us?<p>
<a class="header_submit_highlight" href="{{ request.urlgen('mediagoblin.auth.register') }}">Create a free account</a> or
<a class="header_submit" href="http://wiki.mediagoblin.org/HackingHowto">Set up MediaGoblin on your own server</a>
{% endif %}
diff --git a/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html b/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
index 48fbc3b0..01323a6e 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
@@ -31,17 +31,23 @@
Really delete {{ title }}?
{%- endtrans %}
</h1>
- <p>
- <em>
- {%- trans -%}
- If you choose yes, the media entry will be deleted <strong>permanently.</strong>
- {%- endtrans %}
- </em>
- </p>
- {{ wtforms_util.render_divs(form) }}
+ <div style="text-align: center;" >
+ <img src="{{ request.app.public_store.file_url(
+ media['media_files']['thumb']) }}" />
+ </div>
+
+ <br />
+
+ <p class="delete_checkbox_box">
+ {{ form.confirm }}
+ {{ _(form.confirm.label.text) }}
+ </p>
+
<div class="form_submit_buttons">
- <input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button" />
+ {# TODO: This isn't a button really... might do unexpected things :) #}
+ <a class="cancel_link" href="{{ media.url_for_self(request.urlgen) }}">{% trans %}Cancel{% endtrans %}</a>
+ <input type="submit" value="{% trans %}Delete Permanently{% endtrans %}" class="button" />
</div>
</div>
</form>
diff --git a/mediagoblin/templates/mediagoblin/utils/pagination.html b/mediagoblin/templates/mediagoblin/utils/pagination.html
index cdac01c8..87e15e0f 100644
--- a/mediagoblin/templates/mediagoblin/utils/pagination.html
+++ b/mediagoblin/templates/mediagoblin/utils/pagination.html
@@ -33,15 +33,18 @@
<div class="pagination">
<p>
{% if pagination.has_prev %}
- <a href="{{ pagination.get_page_url_explicit(
- base_url, get_params,
- pagination.page - 1) }}"><img class="pagination_arrow" src="/mgoblin_static/images/pagination_left.png" alt="Previous page" />Newer</a>
+ {% set prev_url = pagination.get_page_url_explicit(
+ base_url, get_params,
+ pagination.page - 1) %}
+ <a href="{{ prev_url }}"><img class="pagination_arrow" src="/mgoblin_static/images/pagination_left.png" alt="Previous page" /></a>
+ <a href="{{ prev_url }}">{% trans %}Newer{% endtrans %}</a>
{% endif %}
{% if pagination.has_next %}
- <a href="{{ pagination.get_page_url_explicit(
- base_url, get_params,
- pagination.page + 1) }}">Older<img class="pagination_arrow" src="/mgoblin_static/images/pagination_right.png" alt="Next page" />
- </a>
+ {% set next_url = pagination.get_page_url_explicit(
+ base_url, get_params,
+ pagination.page + 1) %}
+ <a href="{{ next_url }}">{% trans %}Older{% endtrans %}</a>
+ <a href="{{ next_url }}"><img class="pagination_arrow" src="/mgoblin_static/images/pagination_right.png" alt="Next page" /></a>
{% endif %}
<br />
Go to page:
diff --git a/mediagoblin/user_pages/forms.py b/mediagoblin/user_pages/forms.py
index 22dedfd9..bf456630 100644
--- a/mediagoblin/user_pages/forms.py
+++ b/mediagoblin/user_pages/forms.py
@@ -26,7 +26,5 @@ class MediaCommentForm(wtforms.Form):
class ConfirmDeleteForm(wtforms.Form):
- confirm = wtforms.RadioField('Confirm',
- default='False',
- choices=[('False', 'No, I made a mistake!'),
- ('True', 'Yes, delete it!')])
+ confirm = wtforms.BooleanField('I am sure I want to delete this',
+ [wtforms.validators.Required()])
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index 2c376283..f60bd186 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -154,7 +154,7 @@ def media_confirm_delete(request, media):
form = user_forms.ConfirmDeleteForm(request.POST)
if request.method == 'POST' and form.validate():
- if request.POST.get('confirm') == 'True':
+ if form.confirm.data is True:
username = media.uploader()['username']
# Delete all files on the public storage
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index e391b8b0..7ff3ec7f 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -689,7 +689,7 @@ def delete_media_files(media):
Arguments:
- media: A MediaEntry document
"""
- for handle, listpath in media['media_files'].items():
+ for listpath in media['media_files'].itervalues():
mg_globals.public_store.delete_file(
listpath)