aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/mixin.py
Commit message (Collapse)AuthorAgeFilesLines
...
* New mediaentry slug tests now pass!Christopher Allan Webber2013-01-231-3/+4
| | | | | | - fixed some issues with "whacking uuid junk on the slug" - uuid4() -> uuid.uuid4() so that mock will work right - added all the tests!
* We don't want any empty string slugs, so make "" -> NoneChristopher Allan Webber2013-01-231-0/+4
|
* Switching uuid4()[1:4] -> uuid4().hex[:4]Christopher Allan Webber2013-01-231-1/+1
| | | | | | .hex is what we need to access to get at the ascii (hex) version anyway. Also, not sure why the previous version grabbed starting at the index of 1... just grab the first characters instead.
* Simplifying string concatenation in generate_slug and fixing docstringChristopher Allan Webber2013-01-151-5/+7
| | | | | | | | - made the mistake of copying some commit message things into the docstring. Fixed. - elrond points out that += is nicer and we don't need u"" in this case since we're not concatenating a variable, we're concatenating a known ascii string.
* A revised algorithm for generating slugs.Christopher Allan Webber2013-01-151-11/+47
| | | | | | | | | | | | | | | | | | | | | This one does not *force* slugs, but usually it will probably result in a niceish one. The end *result* of the algorithm will (presumably, I have not tested it) result in these resolutions for these situations: - If we have a slug, make sure it's clean and sanitized, and if it's unique, we'll use that. - If we have a title, slugify it, and if it's unique, we'll use that. - If we can't get any sort of thing that looks like it'll be a useful slug out of a title or an existing slug, bail, and don't set the slug at all. Don't try to create something just because. Make sure we have a reasonable basis for a slug first. - If we have a reasonable basis for a slug (either based on existing slug or slugified title) but it's not unique, first try appending the entry's id, if that exists - If that doesn't result in something unique, tack on some randomly generated bits until it's unique. That'll be a little bit of junk, but at least it has the *basis* of a nice slug!
* Need to import uuid4 for generate_slug to totally workChristopher Allan Webber2013-01-151-0/+2
|
* Make generate_slug assign a slug in any caseSebastian Spaeth2013-01-151-8/+15
| | | | | | | | | | | | generate_slug could assign "none" as slug. Make sure it assigns a unique slug in any case. We now try based on: a) existing slug values b) media.title c) media.id d) random garbage Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
* Simplify check_media_slug_usedSebastian Spaeth2013-01-151-2/+1
| | | | | | | Remove the unused dummy_db argument and generally make the function readable. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
* Move DBModel._id -> DBModel.idSebastian Spaeth2012-12-211-4/+4
| | | | | | | | | | | | | | | | | | | | | | | 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>
* make media_manager a property of MediaEntry in mixin.pySebastian Spaeth2012-12-041-3/+21
| | | | | | | | | | | | | | | | | | | | | | | | In all cases where get_media_manager(_media_type_as_string) was called in our code base we ultimately passed in a "MediaEntry().media_type" to get the matching MEDIA_MANAGER. It so makes sense to make this a function of the MediaEntry rather than a global function in mediagoblin.media_types and passing around media_entry.media_type as arguments all the time. It saves a few import statements and arguments. I also made it so the Media_manager property is cached for subsequent calls, although I am not too sure that this is needed (there are other cases for which this would make more sense) Also add a get_media_manager test to the media submission tests. It submits an image and checks that both media.media_type and media.media_manager return the right thing. Not sure if these tests could not be merged with an existing submission test, but it can't hurt to have things explicit. TODO: Right now we iterate through all existing media_managers to find the right one based on the string of its module name. This should be made a simple dict lookup to avoid all the extra work. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
* Implement licenses.get_license_by_urlSebastian Spaeth2012-11-301-1/+1
| | | | | | | | | 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>
* Use mediagoblin import machinerySebastian Spaeth2012-11-301-4/+5
| | | | | | | | | | | Rather than manually __importing__ the MEDIA_MANAGER, we should have been using tools.common.import_component in the first place. But even better to use the existing get_media_manager() function that exists for exactly our purpose. Also improve documentation of what happens in case of failure. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
* Remove importlib (python2.7'ism)Sebastian Spaeth2012-11-301-3/+1
| | | | | | | | importlib is cool, but only included in python2.7 which is beyond our minimum python version that we support. So simply use plain old __import__. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
* Simplify/Robustify the thumbnail URL usage in templatesSebastian Spaeth2012-11-151-0/+19
| | | | | | | | | | | | | | | | | | | | | | So far templates required a very complex blurb to simply insert a thumbnail URL, exposing much of the internal logic to the template designer. In addition, we would fail with an error if for some reason the media_files['thumb'] entry was never populated. This adds the MediaEntry.thumb_url property that template designers can simply use. It will do the right thing, either fetching the proper thumbnail or hand back a generic icon specified in a media's MEDIA_MANAGER as "default_thumb". Add an image default fallback icon (stolen from Tangos, which are Public Domain since version 0.8.90 as I understand) since the one we referred to was not existing. Perhaps, a "broken image" icon would be better, but I'll leave that to our capable designers. All templates have been modified to make use of the new thumb_url function. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
* Style fixesJoar Wandborg2012-09-181-0/+1
|
* Fixed collection sidebar for media_home to user collection.url_for_self ↵Aaron Williamson2012-09-181-1/+1
| | | | instead of incorrectly getting the session user
* Added basic collection functionalityAaron Williamson2012-09-181-0/+53
|
* Minor improvements to the processing panelJoar Wandborg2012-07-101-2/+2
| | | | | | - It is now possible to actually see what's processing, due to a bug fix where __getitem__ was called on the db model. - Removed DEPRECATED message from the docstring, it wasn't true.
* Prevent non-Unicode SQLAlchemy warnings in most submission tests.Brett Smith2012-07-081-1/+1
| | | | This commit makes test_submission mostly warning-clean.
* Fix cyclic import issue.Elrond2012-03-231-1/+2
| | | | | | | | Oh well: tools.exif -> processing -> db.util -> db.models -> db.mixin -> tools.exif So import tools.exif locally in exif_display_iter()
* Create MediaEntry.exif_display_iter()Elrond2012-03-231-0/+10
| | | | | | | | MediaEntry.media_data.exif_all will contain all the "clean" EXIF data. MediaEntry.exif_display_iter() is an iterator that fetches the most interesting entries for display from that data.
* Generic generate_slug for mongo and sql.Elrond2012-03-071-0/+18
| | | | | | | | | | Using the new check_media_slug_used it is possible to have one generic generate_slug in the mixin class instead of in each db class. In the sql variant self.id is not always set: If the slug alone would create a dupe the current code decides for "no slug at all".
* Drop pre-rendered html: MediaComment.content_htmlElrond2012-02-181-0/+10
| | | | | | | | | | | After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the MediaComment.content_html part.
* Drop pre-rendered html: MediaEntry.description_htmlElrond2012-02-181-0/+8
| | | | | | | | | | | After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the MediaEntry.description_html part.
* Drop pre-rendered html: User.bio_htmlElrond2012-02-181-0/+5
| | | | | | | | | | | After a bit of discussion, we decided to drop the pre-rendered html from the database and render it on the fly. In another step, we will use some proper caching method to cache this stuff. This commit affects the User.bio_html part.
* Fix copyright statements; add LICENSE for EXIF.pyWill Kahn-Greene2012-02-081-1/+1
|
* Let some code support "media without slug"Elrond2012-01-281-12/+9
| | | | | | | | | | | | | | The upcoming SQL database will allow having media without a slug again. This might especially be useful for API support, where the uploaded image (media) does not have *any* information to generate a slug from. This code change mostly allows the sql backend to have no slug in its model and improves some parts to properly handle that. It specifically does not have any web frontend support to edit/create MediaEntries with no slug.
* License "all rights reserved" default should be None/NULL, not empty stringChristopher Allan Webber2012-01-211-1/+1
|
* Moved get_license_data to mixin.py, added license to sql media model, added ↵Aaron Williamson2012-01-181-1/+5
| | | | translation tags to license template.
* Fix url_for_self mixupElrond2012-01-111-3/+5
| | | | | Move changes from mongo/models:url_for_self back into mixin:url_for_self.
* Add DB Mixin classes and use themElrond2012-01-081-0/+90
A bunch of functions on the db objects are really more like "utility functions": They could live outside the classes and be called "by hand" passing the appropiate reference. They usually only use the public API of the object and rarely use database related stuff. Goals: - First, simple: Share the code with the SQL objects, so that the code doesn't need to be duplicated. - Second, it might unclutter the db models and make them more into "model only" stuff. - Doesn't really hurt.