159 Commits

Author SHA1 Message Date
Sebastian Spaeth
7525cdf9eb Disallow ":" as part of a media slug
We might want to use "id:IDN" as a special case slug to point to a media's
id.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2013-01-15 20:08:21 +01:00
Sebastian Spaeth
b0c8328e54 Move db.sql.models* to db.models* 2013-01-07 11:44:29 +01:00
Christopher Allan Webber
e535b9b36f Make translitcodec optional, and work nicely without it. 2013-01-06 21:41:08 -06:00
Sebastian Spaeth
ab7281fe24 Fix up symlinks in exif bump
Previous exif bump copied the newer version into
mediagoblin/tools/extlib/exif but not in extlib/exif. Fix this by
bumping extlib/exif and symlinking to tools/extlib/exif.

Do note that this is still the version fetched from http://sourceforge.net/projects/exif-py/
while the upstream maintainer seems to be active on:
https://github.com/ianare/exif-py

(The sf.net download is quite new though)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-26 10:26:06 +01:00
Sebastian Spaeth
71717fd531 Remove ObjectId from the tree
This was one of the last remaining Mongo holdouts and has been removed from
the tree herewith. Good bye, ObjectId.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-25 20:52:25 +01:00
Sebastian Spaeth
7c029a1f33 Remove InvalidId
It was a NoOp in our Non-mongo world. So it is safe to remove.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-25 20:28:19 +01:00
Sebastian Spaeth
bc142abc55 RIP out mongo
Since sqlalchemy is providing our database abstraction and we have
moved away from Mongo as the underlying database, it is now time to
simplify things and rip out mongo. This provides the bulk of the
changes, and can stand on its own. There are some followup tasks
that can be done, such as removing now unneeded abstraction layers,
e.g. db.sql.fake.py
2012-12-25 20:06:03 +01:00
Sebastian Spaeth
351fd95fff Update extlib/EXIF
Bump bundled EXIF lib to 1.0.10 as release in Sep 2012.
Also skip unused detailed EXIF tags for reading, we might turn that
on when we need them.

Adapt test to wording change in EXIF Flas field and due to the fact
that we use "details=False" by default now (we did not use these
anyway)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-25 19:54:09 +01:00
Elrond
05501c5742 Rewrite routing using new MGRoute class
MGRoute subclasses Rule():
Rule doesn't have a way to tag extra data, like the
controller function, we need. So MGRoute has a new
attribute .gmg_controller, which holds this.

Rewrite everything to use this new Rule variant and drop
all the other stuff that mapped endpoints to controller
functions, mostly.
2012-12-23 12:26:34 +01:00
Elrond
3d91433230 Move things from routing.py to tools/routing.py
This stops a cyclic import.

Move add_route, mount and endpoint_to_controller into
tools/routing.py and change all callers.
2012-12-23 12:26:34 +01:00
Sebastian Spaeth
785b287fcb Provide tools.response.render_http_exception and use that
After the webob->werkzeug transition, controller functions can raise
werkzeug.HttpExceptions. We need to catch these in app.py when calling
the controller and handle them, rendering the corresponding error Response()
object. For consistency, we also want to allow meddleware functions to
raise HttpExceptions (e.g. the csrf meddleware needs to complain about lack
of cookies), so wrap the request and response parts of the meddleware too.

Finally, the urlmap.match() can also raise HttpExceptions, so we give it the
same treatment (render_http_exception). I am not sure, if we do not need to
handle the Redirect exception there in any different way though...

The new function render_http_exception makes use of the render_error infrastructure
to return a nicely templated error page. It also checks if the stock error
messages was used in cases where we have localizations (403, 404) and use those.

It is now possible to do things like "raise Forbidden(_('You suckr'))" or
raise NotFound(_('where is my left show again')) if you want to return
customized error messages to the user.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-23 11:57:45 +01:00
Sebastian Spaeth
10f1f2f56b Remove Mongoism query.skip()
sqlalchemy supports slice() or [n:m] just fine.

Right now, it seems we cannot distinguish beween "empty" results
and out-of bound slices. It would be nice if we could distinguish
these somehow.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 11:30:29 +01:00
Sebastian Spaeth
b745bb50d8 Remove webob from render_to_response
We were still using webob's Response objects for template rendering.
Transition to werkzeug's Response object. One caveat was that it
seemed to have used the default mimetype "text/plain" for all pages,
so we override the default Response class, setting the default mime
type to "text/html".

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:10:48 +01:00
Sebastian Spaeth
4487d51c81 Extend redirect helper to take optional location keyword
In order to move away from webob with its redirect(location=...) we
need to provide a redirect function that allows to directly specify
the URL rather than the urlgen parameters that we now use.

Extend our MG.tools:redirect helper so we can pass in the direct URL
via the optional "location" keyword.

This commit does not switch over any redirect consumers yet.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 08:10:48 +01:00
Sebastian Spaeth
5c2b84869f Move DBModel._id -> DBModel.id
We were refering to model._id in most of the code base as this is
what Mongo uses. However, each use of _id required a) fixup of queries:
e.g. what we did in our find() and find_one() functions moving all
'_id' to 'id'. It also required using AliasFields to make the ._id
attribute available. This all means lots of superfluous fixing and
transitioning in a SQL world.

It will also not work in the long run. Much newer code already refers
to the objects by model.id (e.g. in the oauth plugin), which will break
with Mongo. So let's be honest, rip out the _id mongoism and live with
.id as the one canonical way to address objects.

This commit modifies all users and providers of model._id to use
model.id instead. This patch works with or without Mongo removed first,
but will break Mongo usage (even more than before)

I have not bothered to fixup db.mongo.* and db.sql.convert
(which converts from Mongo to SQL)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-21 00:30:48 +01:00
Christopher Allan Webber
00da119ec3 Switching both gettext calls to _() so babel can find/extract them.
Babel looks for _() and gettext() so this is necessary.
2012-12-14 10:49:05 -06:00
Christopher Allan Webber
cc81b5e55e Add comments explaining how translitcodec *is* used 2012-12-14 09:29:46 -06:00
Sebastian Spaeth
c843de8a57 Add example to the lazy gettext version to make clear when it's appropriate
I needed an example to really get when lazy_gettext would be good...
2012-12-14 15:16:49 +01:00
Sebastian Spaeth
18a52dacca Use the correct translation mechanism
We accidentally used the fake translation mechanism here which will not
actually translate anything.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-14 15:13:31 +01:00
Sebastian Spaeth
2222278dcd Remove gridify_*
We injected a gridify_list and gridify_cursor function into each jinja2
template that we render. This was used to split the list of media_entries
into batches of 5 for nicer table columns. However, jinja2 has a nice |batch
filter built in that does the job for us just as well with less code (on our side)

Less code=good

so let's merge this one.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-04 17:31:12 +01:00
Sebastian Spaeth
c39b9afc83 Fallback to "en_US" if browser does not send preferred languages
E.g. in our test suite we don't send an "accepted languages" header, which
caused the language matching to fail. So we need to explicitely fallback to
en_US, in case request.accepted_languages is None. This fixes the tests and
all cases where user browsers don't send preferred languages.

This also fixes issue #562, the AVAILABLE_LOCALES are already case-normalized
and we don't need to fudge the preferred language through the lower_upper_locale
thing for each and every request.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-04 09:44:07 +01:00
Sebastian Spaeth
620e4e1b6e Provide jinja2 urlencode filter
Astonishingly, the great jinja2 does not provide a builtin urlquote filter,
although it is obviously needed. (jina1 had one) This is:
https://github.com/mitsuhiko/jinja2/issues/17

Provide an urlencode filter, based on werkzeug's url_quote_plus function.
This is dead easy to implement and gives us all the freedom we want.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-03 14:11:22 +01:00
Sebastian Spaeth
826919c97c en_US is always available
We were using "en" as fallback only when no preferred language matched.
This is obviously bad. Always insert en_US as available locale, so we
can match it with the accept_languages.

Don't set available_locales as mg_global, per discussion with paroneaya,
make it a global var in translate.py

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-02 02:46:50 +01:00
Christopher Allan Webber
e4e7fbeeaa Fixing bug where not all conditions returned a language in get_locale_from_request()
Just had to change the indentation level of the last commit.
2012-12-01 19:36:52 -06:00
Sebastian Spaeth
d53ca5e506 Fall back to "en" if we don't find matching translations
In case of no matching translations, target_lang was "None" which
blew up things. Fall back to "en" in case we don't find a
corresponding translation.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-02 01:39:53 +01:00
Sebastian Spaeth
6ef75af50e Honor user's browser language (#558)
Previously we would attempt to satisfy the user's first language
preference, immediately falling back to english if that was not
possible. Now, we will get the best match of the user's preferred
languages.

This requires storing the available locales on app startup, so we
have mg_globals.available_locales ready to compare them against the
list of preferred user languages.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-02 00:29:30 +01:00
Sebastian Spaeth
7b9f9d1edb Fix i18n in our browser
We only ever served english pages since the switch to werkzeug's requests.
Fix this by actually checking the accepted languages that our web browser
sends and using that or falling back to english.

This is not optimal, imaging our browser sends "klingon, de" as accepted
languages and we happen to not have a klingon translation ready (a deficiency
that should be corrected immediately anyway!!). We would then fall back
to english rather than sending the sensible and pleasant German language
which the user would understand. This will require more backend work though.

Removing the gettext.find() in mg_globals.py. It looked in the wrong directory
anyway (mediagoblin/translations) and as that does not exist, had always returned
None without anyone noticing.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-12-01 23:40:10 +01:00
Sebastian Spaeth
138a18fd6e Implement licenses.get_license_by_url
Rather than exploding in the user's face (for example if we custom-configure
licenses in our MG instance, and there are still media with now "unknown"
licenses in the db), simply return a License object as a fallback, where all
attributes are set to the URL we were handed.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-11-30 14:31:43 +01:00
Sebastian Spaeth
8e5fae9b43 Improve mediagoblin.tools.licenses
"Objectify" our licenses to have .uri, .abbreviation, .name attributes
that we can pass into the templates and use there. namedtuples are a good
poor man's choice to make a License a class. (a named tuple really)

Document and optimize licenses_as_choices(), it is a one-liner really.
No need for verbose appends here...
2012-11-30 14:31:43 +01:00
Elrond
e4f33f4093 Merge remote-tracking branch 'spaetz/formerge/538_FORBIDDEN_admin_pages'
* spaetz/formerge/538_FORBIDDEN_admin_pages:
  Fix error page text
  Return code 403 when accessing admin pages
  Implement generic error pages
2012-11-29 15:27:50 +01:00
Sebastian Spaeth
26c71029b4 Fix error page text
Thanks to Elrond for noticing. We wrap error messages in <p> tags,
so there is no need to start the error message with <p>. DOH

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-11-29 14:51:24 +01:00
Elrond
f52301d261 Merge remote-tracking branch 'spaetz/formerge/507_remove_routes'
* spaetz/formerge/507_remove_routes:
  Purge routes package from MG (#507)
2012-11-29 14:29:43 +01:00
Sebastian Spaeth
6b5f1ca79b Implement generic error pages
Rather than having a 404.html, a 403.html, a 500.html,...
we have a generic error.html template that we pass in an
error code, a title and a (html'ish) error message.

Implement the common render_404 and render_403 shortcuts. More exotic
cases can be achieved by the generic render_error function.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-11-29 09:01:08 +01:00
Sebastian Spaeth
60389b21f5 Purge routes package from MG (#507)
We were not actually using the routes package anymore, but it was
still mentioned in the documention. Adapt the plugin documentation to
actually represent reality, although I don't like the API design.
(but this is for another day)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-11-20 09:29:37 +01:00
Sebastian Spaeth
9061383de2 No need to strip the tag 4 times
spaetz' rule: Don't do sth 4 times when once suffices.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-11-16 13:18:37 +01:00
Sebastian Spaeth
2a6a3b8cce Slightly shorten the media_tags_as_string function
Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-11-14 09:04:17 +01:00
dunkyp
36c7d93481 Remove tag delimiter configurability (#390), fixed pep-8 compliance
Hardcode commas as tag delimiters per discussion in issue 390. Also
improved PEP-8'ness of the file while touching. Includes some improvements
suggested by gandaro.

Reviewed-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2012-11-14 08:38:24 +01:00
Joar Wandborg
d56e82635f Fixed OAuth access_token duplicate route
Changed route name to "[...]list_connections"
2012-10-15 22:59:53 +02:00
Joar Wandborg
1ec7ff2adb Fixed 404 page under werkzeug.routing
- Removed ?lang=<langcode> feature due to incompatibility with werkzeug
  routes in the current state of the architecture.
2012-10-14 20:05:44 +02:00
Joar Wandborg
7742dcc1fb Switched most stuff over from Routes
Removed the Routes routing functionality and replaced it with
werkzeug.routes. Most views are functional.

Known issues:

 - Translation integration with the request object is not yet figured
   out. This breaks 404 pages.
2012-10-14 13:46:31 +02:00
Joar Wandborg
e2890c729f Fixed pylint issues, removed unused import 2012-10-02 22:29:22 +02:00
Joar Wandborg
3d7fa496ee Changed copy.copy(get_params) to dict(get_params)
in pagination because request.GET/request.args is immutable since the
switch to werkzeug.
2012-09-30 20:34:39 +02:00
Joar Wandborg
111a609df5 Replaced all request.POST with request.form, ...
- Fixed error handling in OAuth plugin
- Changed request.POST file fields to request.files
2012-09-29 21:08:20 +02:00
Joar Wandborg
f1d06e1d6c Switch from webob.Request to werkzeug.wrappers.Request 2012-09-29 21:08:20 +02:00
Joar Wandborg
0df00eb68f Added tests for HTTP callbacks 2012-09-27 00:45:25 +02:00
Joar Wandborg
939d57a022 HTTP callback fixes
- Added HTTPError catching around the callback request, to not mark the
  entry as failed, just log the exception.
- Fixed bug where I forgot to actually fetch the entry before passing it
  to json_processing_callback.
- Changed __main__ migration #6 to create the ProcessingMetaData table
  as it is currently, to prevent possible breakage if a siteadmin
  is lagging behind with his db migrations and more than one migration
  wants to fix stuff with the ProcessingMetaData table.
2012-09-26 23:53:51 +02:00
Joar Wandborg
5354f954dc Added support for http callbacks on processing
Sends an HTTP POST request back to an URL given on submission to the API
submit view.
2012-09-26 23:53:51 +02:00
Joar Wandborg
0e21b2342f Added flask-wtf html5 fields to extlib 2012-09-21 13:16:24 +02:00
Joar Wandborg
a062149e90 Created API plugin, moved api_auth to the API plugin 2012-09-13 20:59:00 +02:00
Joar Wandborg
f46e2a4db9 Add OAuth models, plugin DB migrations, api_auth 2012-09-13 20:38:59 +02:00