From 243c3843bd574129caa7663e25d1a843b2d2dd30 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:02 -0700 Subject: [PATCH 01/18] Whitespace and formatting cleanup. * Removed trailing whitespace * Line length < 80 where possible * Honor conventions on number of blank lines * Honor conventions about spaces around :, = --- mediagoblin/app.py | 3 +- mediagoblin/auth/forms.py | 8 ++--- mediagoblin/auth/lib.py | 3 +- mediagoblin/auth/routing.py | 3 +- mediagoblin/auth/views.py | 3 +- mediagoblin/db/__init__.py | 2 +- mediagoblin/db/indexes.py | 5 +-- mediagoblin/db/migrations.py | 2 +- mediagoblin/db/models.py | 35 ++++++++++---------- mediagoblin/db/open.py | 2 +- mediagoblin/db/util.py | 5 +-- mediagoblin/decorators.py | 2 +- mediagoblin/edit/__init__.py | 2 -- mediagoblin/edit/views.py | 2 +- mediagoblin/gmg_commands/__init__.py | 3 +- mediagoblin/gmg_commands/import_export.py | 7 ++-- mediagoblin/gmg_commands/migrate.py | 4 +-- mediagoblin/gmg_commands/users.py | 7 ++-- mediagoblin/init/__init__.py | 18 +++++++---- mediagoblin/init/celery/__init__.py | 2 +- mediagoblin/init/celery/from_celery.py | 2 +- mediagoblin/init/config.py | 2 +- mediagoblin/listings/routing.py | 1 - mediagoblin/listings/views.py | 3 +- mediagoblin/messages.py | 2 ++ mediagoblin/middleware/noop.py | 1 + mediagoblin/process_media/__init__.py | 18 ++++++----- mediagoblin/process_media/errors.py | 9 +++--- mediagoblin/storage/cloudfiles.py | 1 + mediagoblin/submit/__init__.py | 2 -- mediagoblin/submit/security.py | 2 +- mediagoblin/submit/views.py | 16 ++++++---- mediagoblin/user_pages/__init__.py | 2 -- mediagoblin/user_pages/views.py | 13 +++++--- mediagoblin/util.py | 39 +++++++++++++---------- mediagoblin/views.py | 1 + mediagoblin/workbench.py | 4 ++- setup.py | 12 +++---- 38 files changed, 135 insertions(+), 113 deletions(-) diff --git a/mediagoblin/app.py b/mediagoblin/app.py index dd5f0b89..9bbccf24 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -91,7 +91,7 @@ class MediaGoblinApp(object): # object. ####################################################### - setup_globals(app = self) + setup_globals(app=self) # Workbench *currently* only used by celery, so this only # matters in always eager mode :) @@ -101,7 +101,6 @@ class MediaGoblinApp(object): self.middleware = [util.import_component(m)(self) for m in middleware.ENABLED_MIDDLEWARE] - def __call__(self, environ, start_response): request = Request(environ) diff --git a/mediagoblin/auth/forms.py b/mediagoblin/auth/forms.py index 6339b4a3..aadb5888 100644 --- a/mediagoblin/auth/forms.py +++ b/mediagoblin/auth/forms.py @@ -59,9 +59,10 @@ class ForgotPassForm(wtforms.Form): 'Username or email', [wtforms.validators.Required()]) - def validate_username(form,field): - if not (re.match(r'^\w+$',field.data) or - re.match(r'^.+@[^.].*\.[a-z]{2,10}$',field.data, re.IGNORECASE)): + def validate_username(form, field): + if not (re.match(r'^\w+$', field.data) or + re.match(r'^.+@[^.].*\.[a-z]{2,10}$', field.data, + re.IGNORECASE)): raise wtforms.ValidationError(u'Incorrect input') @@ -82,4 +83,3 @@ class ChangePassForm(wtforms.Form): token = wtforms.HiddenField( '', [wtforms.validators.Required()]) - diff --git a/mediagoblin/auth/lib.py b/mediagoblin/auth/lib.py index d7d351a5..0ecccbb5 100644 --- a/mediagoblin/auth/lib.py +++ b/mediagoblin/auth/lib.py @@ -93,6 +93,7 @@ EMAIL_VERIFICATION_TEMPLATE = ( u"http://{host}{uri}?" u"userid={userid}&token={verification_key}") + def send_verification_email(user, request): """ Send the verification email to users to activate their accounts. @@ -127,6 +128,7 @@ EMAIL_FP_VERIFICATION_TEMPLATE = ( u"http://{host}{uri}?" u"userid={userid}&token={fp_verification_key}") + def send_fp_verification_email(user, request): """ Send the verification email to users to change their password. @@ -150,4 +152,3 @@ def send_fp_verification_email(user, request): [user['email']], 'GNU MediaGoblin - Change forgotten password!', rendered_email) - diff --git a/mediagoblin/auth/routing.py b/mediagoblin/auth/routing.py index 912d89fa..365ccfaa 100644 --- a/mediagoblin/auth/routing.py +++ b/mediagoblin/auth/routing.py @@ -33,7 +33,8 @@ auth_routes = [ controller='mediagoblin.views:simple_template_render'), Route('mediagoblin.auth.forgot_password', '/forgot_password/', controller='mediagoblin.auth.views:forgot_password'), - Route('mediagoblin.auth.verify_forgot_password', '/forgot_password/verify/', + Route('mediagoblin.auth.verify_forgot_password', + '/forgot_password/verify/', controller='mediagoblin.auth.views:verify_forgot_password'), Route('mediagoblin.auth.fp_changed_success', '/forgot_password/changed_success/', diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index f67f0588..afcfcf1e 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -233,8 +233,7 @@ def forgot_password(request): request, 'mediagoblin.user_pages.user_home', user=user['username']) - - # do not reveal whether or not there is a matching user, just move along + # do not reveal whether or not there is a matching user return redirect(request, 'mediagoblin.auth.fp_email_sent') return render_to_response( diff --git a/mediagoblin/db/__init__.py b/mediagoblin/db/__init__.py index c5124b1a..27e8a90f 100644 --- a/mediagoblin/db/__init__.py +++ b/mediagoblin/db/__init__.py @@ -23,7 +23,7 @@ Database Abstraction/Wrapper Layer pymongo. Read beow for why, but note that nobody is actually doing this and there's no proof that we'll ever support more than MongoDB... it would be a huge amount of work to do so. - + If you really want to prove that possible, jump on IRC and talk to us about making such a branch. In the meanwhile, it doesn't hurt to have things as they are... if it ever makes it hard for us to diff --git a/mediagoblin/db/indexes.py b/mediagoblin/db/indexes.py index 75394a31..1dd73f2b 100644 --- a/mediagoblin/db/indexes.py +++ b/mediagoblin/db/indexes.py @@ -93,8 +93,9 @@ MEDIAENTRY_INDEXES = { ('created', DESCENDING)]}, 'state_uploader_tags_created': { - # Indexing on processed?, media uploader, associated tags, and timestamp - # Used for showing media items matching a tag search, most recent first. + # Indexing on processed?, media uploader, associated tags, and + # timestamp Used for showing media items matching a tag + # search, most recent first. 'index': [('state', ASCENDING), ('uploader', ASCENDING), ('tags.slug', DESCENDING), diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 755f49c5..28bb62fc 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -87,7 +87,7 @@ def mediaentry_add_fail_error_and_metadata(database): {'fail_error': {'$exists': False}}, {'$set': {'fail_error': None}}, multi=True) - + collection.update( {'fail_metadata': {'$exists': False}}, {'$set': {'fail_metadata': {}}}, diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index bbddada6..42db3f83 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -14,7 +14,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import datetime, uuid +import datetime +import uuid from mongokit import Document @@ -69,17 +70,17 @@ class User(Document): 'username': unicode, 'email': unicode, 'created': datetime.datetime, - 'plugin_data': dict, # plugins can dump stuff here. + 'plugin_data': dict, # plugins can dump stuff here. 'pw_hash': unicode, 'email_verified': bool, 'status': unicode, 'verification_key': unicode, 'is_admin': bool, - 'url' : unicode, - 'bio' : unicode, # May contain markdown - 'bio_html': unicode, # May contain plaintext, or HTML - 'fp_verification_key': unicode, # forgotten password verification key - 'fp_token_expire': datetime.datetime + 'url': unicode, + 'bio': unicode, # May contain markdown + 'bio_html': unicode, # May contain plaintext, or HTML + 'fp_verification_key': unicode, # forgotten password verification key + 'fp_token_expire': datetime.datetime, } required_fields = ['username', 'created', 'pw_hash', 'email'] @@ -174,8 +175,8 @@ class MediaEntry(Document): critical to this piece of media but may be usefully relevant to people viewing the work. (currently unused.) - - fail_error: path to the exception raised - - fail_metadata: + - fail_error: path to the exception raised + - fail_metadata: """ __collection__ = 'media_entries' @@ -184,11 +185,11 @@ class MediaEntry(Document): 'title': unicode, 'slug': unicode, 'created': datetime.datetime, - 'description': unicode, # May contain markdown/up - 'description_html': unicode, # May contain plaintext, or HTML + 'description': unicode, # May contain markdown/up + 'description_html': unicode, # May contain plaintext, or HTML 'media_type': unicode, - 'media_data': dict, # extra data relevant to this media_type - 'plugin_data': dict, # plugins can dump stuff here. + 'media_data': dict, # extra data relevant to this media_type + 'plugin_data': dict, # plugins can dump stuff here. 'tags': [dict], 'state': unicode, @@ -220,7 +221,8 @@ class MediaEntry(Document): return self.db.MediaComment.find({ 'media_entry': self['_id']}).sort('created', DESCENDING) - def get_display_media(self, media_map, fetch_order=DISPLAY_IMAGE_FETCHING_ORDER): + def get_display_media(self, media_map, + fetch_order=DISPLAY_IMAGE_FETCHING_ORDER): """ Find the best media for display. @@ -273,7 +275,7 @@ class MediaEntry(Document): """ Provide a url to the previous entry from this user, if there is one """ - cursor = self.db.MediaEntry.find({'_id' : {"$gt": self['_id']}, + cursor = self.db.MediaEntry.find({'_id': {"$gt": self['_id']}, 'uploader': self['uploader'], 'state': 'processed'}).sort( '_id', ASCENDING).limit(1) @@ -286,7 +288,7 @@ class MediaEntry(Document): """ Provide a url to the next entry from this user, if there is one """ - cursor = self.db.MediaEntry.find({'_id' : {"$lt": self['_id']}, + cursor = self.db.MediaEntry.find({'_id': {"$lt": self['_id']}, 'uploader': self['uploader'], 'state': 'processed'}).sort( '_id', DESCENDING).limit(1) @@ -353,4 +355,3 @@ def register_models(connection): Register all models in REGISTER_MODELS with this connection. """ connection.register(REGISTER_MODELS) - diff --git a/mediagoblin/db/open.py b/mediagoblin/db/open.py index e73b6258..e677ba12 100644 --- a/mediagoblin/db/open.py +++ b/mediagoblin/db/open.py @@ -29,7 +29,7 @@ def connect_database_from_config(app_config, use_pymongo=False): port = app_config.get('db_port') if port: port = asint(port) - + if use_pymongo: connection = pymongo.Connection( app_config.get('db_host'), port) diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 84a6cbce..38f0233f 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -118,11 +118,12 @@ def remove_deprecated_indexes(database, deprecated_indexes=DEPRECATED_INDEXES): ################# # The default migration registry... -# +# # Don't set this yourself! RegisterMigration will automatically fill # this with stuff via decorating methods in migrations.py -class MissingCurrentMigration(Exception): pass +class MissingCurrentMigration(Exception): + pass MIGRATIONS = {} diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index 7d5978fc..204ac47a 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -119,6 +119,7 @@ def get_user_media_entry(controller): return _make_safe(wrapper, controller) + def get_media_entry_by_id(controller): """ Pass in a MediaEntry based off of a url component @@ -138,4 +139,3 @@ def get_media_entry_by_id(controller): return controller(request, media=media, *args, **kwargs) return _make_safe(wrapper, controller) - diff --git a/mediagoblin/edit/__init__.py b/mediagoblin/edit/__init__.py index 576bd0f5..ba347c69 100644 --- a/mediagoblin/edit/__init__.py +++ b/mediagoblin/edit/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - - diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 15edfdd6..d15461c0 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -119,7 +119,7 @@ def edit_attachments(request, media): name=request.POST['attachment_name'] \ or request.POST['attachment_file'].filename, filepath=attachment_public_filepath, - created=datetime.utcnow() + created=datetime.utcnow(), )) media.save() diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index 0071c65b..b3f69ccc 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -28,7 +28,7 @@ SUBCOMMAND_MAP = { 'setup': 'mediagoblin.gmg_commands.migrate:migrate_parser_setup', 'func': 'mediagoblin.gmg_commands.migrate:migrate', 'help': 'Apply all unapplied bulk migrations to the database'}, - 'adduser':{ + 'adduser': { 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup', 'func': 'mediagoblin.gmg_commands.users:adduser', 'help': 'Creates an user'}, @@ -80,4 +80,3 @@ def main_cli(): if __name__ == '__main__': main_cli() - diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index 05edbfc8..962e545c 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -91,7 +91,7 @@ def _import_database(db, args): args.mongorestore_path, '-d', db.name, os.path.join(args._cache_path['database'], db.name)]) - + p.wait() _log.info('...Database imported') @@ -229,7 +229,8 @@ def env_export(args): ''' if args.cache_path: if os.path.exists(args.cache_path): - _log.error('The cache directory must not exist before you run this script') + _log.error('The cache directory must not exist ' + 'before you run this script') _log.error('Cache directory: {0}'.format(args.cache_path)) return False @@ -245,7 +246,7 @@ def env_export(args): globa_config, app_config = setup_global_and_app_config(args.conf_file) setup_storage() - + connection, db = setup_connection_and_db_from_config( app_config, use_pymongo=True) diff --git a/mediagoblin/gmg_commands/migrate.py b/mediagoblin/gmg_commands/migrate.py index 1a597188..e6dd6f78 100644 --- a/mediagoblin/gmg_commands/migrate.py +++ b/mediagoblin/gmg_commands/migrate.py @@ -55,13 +55,13 @@ def migrate(args): for collection, index_name in removed_indexes: print "Removed index '%s' in collection '%s'" % ( index_name, collection) - + # Migrate print "\n== Applying migrations... ==" migration_manager.migrate_new( pre_callback=_print_started_migration, post_callback=_print_finished_migration) - + # Add new indexes print "\n== Adding new indexes... ==" new_indexes = db_util.add_new_indexes(db) diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index 5421907d..3fda0e32 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -41,7 +41,7 @@ def adduser(args): db = mg_globals.database users_with_username = \ db.User.find({ - 'username': args.username.lower() + 'username': args.username.lower(), }).count() if users_with_username: @@ -74,7 +74,7 @@ def makeadmin(args): db = mg_globals.database - user = db.User.one({'username':unicode(args.username.lower())}) + user = db.User.one({'username': unicode(args.username.lower())}) if user: user['is_admin'] = True user.save() @@ -100,11 +100,10 @@ def changepw(args): db = mg_globals.database - user = db.User.one({'username':unicode(args.username.lower())}) + user = db.User.one({'username': unicode(args.username.lower())}) if user: user['pw_hash'] = auth_lib.bcrypt_gen_password_hash(args.password) user.save() print 'Password successfully changed' else: print 'The user doesn\'t exist' - diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py index b7f52595..f21e2fdd 100644 --- a/mediagoblin/init/__init__.py +++ b/mediagoblin/init/__init__.py @@ -29,8 +29,12 @@ from mediagoblin.workbench import WorkbenchManager from mediagoblin.storage import storage_system_from_config -class Error(Exception): pass -class ImproperlyConfigured(Error): pass +class Error(Exception): + pass + + +class ImproperlyConfigured(Error): + pass def setup_global_and_app_config(config_path): @@ -76,8 +80,8 @@ def setup_database(): "in fact they appear to be from the future?!") setup_globals( - db_connection = connection, - database = db) + db_connection=connection, + database=db) return connection, db @@ -126,8 +130,8 @@ def setup_storage(): queue_store = storage_system_from_config(global_config[key_long]) setup_globals( - public_store = public_store, - queue_store = queue_store) + public_store=public_store, + queue_store=queue_store) return public_store, queue_store @@ -137,7 +141,7 @@ def setup_workbench(): workbench_manager = WorkbenchManager(app_config['workbench_path']) - setup_globals(workbench_manager = workbench_manager) + setup_globals(workbench_manager=workbench_manager) def setup_beaker_cache(): diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index c58b1305..21ce1d39 100644 --- a/mediagoblin/init/celery/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -84,6 +84,6 @@ def setup_celery_from_config(app_config, global_config, for key, value in celery_settings.iteritems(): setattr(this_module, key, value) - + if set_environ: os.environ['CELERY_CONFIG_MODULE'] = settings_module diff --git a/mediagoblin/init/celery/from_celery.py b/mediagoblin/init/celery/from_celery.py index 3e5adb98..05669b67 100644 --- a/mediagoblin/init/celery/from_celery.py +++ b/mediagoblin/init/celery/from_celery.py @@ -44,7 +44,7 @@ def setup_self(check_environ_for_conf=True, module_name=OUR_MODULENAME, if not os.path.exists(mgoblin_conf_file): raise IOError( "MEDIAGOBLIN_CONFIG not set or file does not exist") - + # By setting the environment variable here we should ensure that # this is the module that gets set up. os.environ['CELERY_CONFIG_MODULE'] = module_name diff --git a/mediagoblin/init/config.py b/mediagoblin/init/config.py index 029a0956..ae232e91 100644 --- a/mediagoblin/init/config.py +++ b/mediagoblin/init/config.py @@ -73,7 +73,7 @@ def read_mediagoblin_config(config_path, config_spec=CONFIG_SPEC_PATH): # For now the validator just works with the default functions, # but in the future if we want to add additional validation/configuration # functions we'd add them to validator.functions here. - # + # # See also: # http://www.voidspace.org.uk/python/validate.html#adding-functions validator = Validator() diff --git a/mediagoblin/listings/routing.py b/mediagoblin/listings/routing.py index b72bd015..234f2595 100644 --- a/mediagoblin/listings/routing.py +++ b/mediagoblin/listings/routing.py @@ -25,4 +25,3 @@ tag_routes = [ Route('mediagoblin.listings.tag_atom_feed', "/{tag}/atom/", controller="mediagoblin.listings.views:tag_atom_feed"), ] - diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index b3384eb4..2d61ee9b 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -46,7 +46,7 @@ def tag_listing(request, page): {u'state': u'processed', u'tags.slug': tag_slug}) cursor = cursor.sort('created', DESCENDING) - + pagination = Pagination(page, cursor) media_entries = pagination() @@ -63,6 +63,7 @@ def tag_listing(request, page): ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 + def tag_atom_feed(request): """ generates the atom feed with the tag images diff --git a/mediagoblin/messages.py b/mediagoblin/messages.py index dc82fbf6..054d46c0 100644 --- a/mediagoblin/messages.py +++ b/mediagoblin/messages.py @@ -20,11 +20,13 @@ SUCCESS = 'success' WARNING = 'warning' ERROR = 'error' + def add_message(request, level, text): messages = request.session.setdefault('messages', []) messages.append({'level': level, 'text': text}) request.session.save() + def fetch_messages(request, clear_from_session=True): messages = request.session.get('messages') if messages and clear_from_session: diff --git a/mediagoblin/middleware/noop.py b/mediagoblin/middleware/noop.py index 28380232..820b5d9e 100644 --- a/mediagoblin/middleware/noop.py +++ b/mediagoblin/middleware/noop.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + class NoOpMiddleware(object): def __init__(self, mg_app): diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 2b9eed6e..9a7d5c39 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -65,9 +65,10 @@ class ProcessMedia(Task): """ If the processing failed we should mark that in the database. - Assuming that the exception raised is a subclass of BaseProcessingFail, - we can use that to get more information about the failure and store that - for conveying information to users about the failure, etc. + Assuming that the exception raised is a subclass of + BaseProcessingFail, we can use that to get more information + about the failure and store that for conveying information to + users about the failure, etc. """ entry_id = args[0] mark_entry_failed(entry_id, exc) @@ -80,10 +81,10 @@ def mark_entry_failed(entry_id, exc): """ Mark a media entry as having failed in its conversion. - Uses the exception that was raised to mark more information. If the - exception is a derivative of BaseProcessingFail then we can store extra - information that can be useful for users telling them why their media failed - to process. + Uses the exception that was raised to mark more information. If + the exception is a derivative of BaseProcessingFail then we can + store extra information that can be useful for users telling them + why their media failed to process. Args: - entry_id: The id of the media entry @@ -164,7 +165,8 @@ def process_image(entry): with queued_file: original_filepath = create_pub_filepath(entry, queued_filepath[-1]) - with mgg.public_store.get_file(original_filepath, 'wb') as original_file: + with mgg.public_store.get_file(original_filepath, 'wb') \ + as original_file: original_file.write(queued_file.read()) mgg.queue_store.delete_file(queued_filepath) diff --git a/mediagoblin/process_media/errors.py b/mediagoblin/process_media/errors.py index 156f0a01..cb236154 100644 --- a/mediagoblin/process_media/errors.py +++ b/mediagoblin/process_media/errors.py @@ -16,17 +16,18 @@ from mediagoblin.util import lazy_pass_to_ugettext as _ + class BaseProcessingFail(Exception): """ Base exception that all other processing failure messages should subclass from. - + You shouldn't call this itself; instead you should subclass it and provid the exception_path and general_message applicable to this error. """ general_message = u'' - + @property def exception_path(self): return u"%s:%s" % ( @@ -34,8 +35,8 @@ class BaseProcessingFail(Exception): def __init__(self, **metadata): self.metadata = metadata or {} - - + + class BadMediaFail(BaseProcessingFail): """ Error that should be raised when an inappropriate file was given diff --git a/mediagoblin/storage/cloudfiles.py b/mediagoblin/storage/cloudfiles.py index b1dd9450..0d3cc3df 100644 --- a/mediagoblin/storage/cloudfiles.py +++ b/mediagoblin/storage/cloudfiles.py @@ -27,6 +27,7 @@ from mediagoblin.storage import StorageInterface, clean_listy_filepath import cloudfiles import mimetypes + class CloudFilesStorage(StorageInterface): ''' OpenStack/Rackspace Cloud's Swift/CloudFiles support diff --git a/mediagoblin/submit/__init__.py b/mediagoblin/submit/__init__.py index 576bd0f5..ba347c69 100644 --- a/mediagoblin/submit/__init__.py +++ b/mediagoblin/submit/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - - diff --git a/mediagoblin/submit/security.py b/mediagoblin/submit/security.py index 9d62a36e..6708baf7 100644 --- a/mediagoblin/submit/security.py +++ b/mediagoblin/submit/security.py @@ -16,9 +16,9 @@ from mimetypes import guess_type - ALLOWED = ['image/jpeg', 'image/png', 'image/tiff', 'image/gif'] + def check_filetype(posted_file): if not guess_type(posted_file.filename)[0] in ALLOWED: return False diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e24d78f3..22a13b6d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -61,8 +61,8 @@ def submit_start(request): entry['description'] = unicode(request.POST.get('description')) entry['description_html'] = cleaned_markdown_conversion( entry['description']) - - entry['media_type'] = u'image' # heh + + entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] # Process the user's folksonomy "tags" @@ -90,8 +90,10 @@ def submit_start(request): # We generate this ourselves so we know what the taks id is for # retrieval later. - # (If we got it off the task's auto-generation, there'd be a risk of - # a race condition when we'd save after sending off the task) + + # (If we got it off the task's auto-generation, there'd be + # a risk of a race condition when we'd save after sending + # off the task) task_id = unicode(uuid.uuid4()) entry['queued_task_id'] = task_id @@ -113,8 +115,8 @@ def submit_start(request): # expect a lot of users to run things in this way we have to # capture stuff here. # - # ... not completely the diaper pattern because the exception is - # re-raised :) + # ... not completely the diaper pattern because the + # exception is re-raised :) mark_entry_failed(entry[u'_id'], exc) # re-raise the exception raise @@ -122,7 +124,7 @@ def submit_start(request): add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", - user = request.user['username']) + user=request.user['username']) return render_to_response( request, diff --git a/mediagoblin/user_pages/__init__.py b/mediagoblin/user_pages/__init__.py index 576bd0f5..ba347c69 100644 --- a/mediagoblin/user_pages/__init__.py +++ b/mediagoblin/user_pages/__init__.py @@ -13,5 +13,3 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - - diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 6a82d718..e6ba6b79 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -53,7 +53,7 @@ def user_home(request, page): #if no data is available, return NotFound if media_entries == None: return render_404(request) - + user_gallery_url = request.urlgen( 'mediagoblin.user_pages.user_gallery', user=user['username']) @@ -66,6 +66,7 @@ def user_home(request, page): 'media_entries': media_entries, 'pagination': pagination}) + @uses_pagination def user_gallery(request, page): """'Gallery' of a User()""" @@ -85,7 +86,7 @@ def user_gallery(request, page): #if no data is available, return NotFound if media_entries == None: return render_404(request) - + return render_to_response( request, 'mediagoblin/user_pages/gallery.html', @@ -95,6 +96,7 @@ def user_gallery(request, page): MEDIA_COMMENTS_PER_PAGE = 50 + @get_user_media_entry @uses_pagination def media_home(request, media, page, **kwargs): @@ -142,8 +144,8 @@ def media_post_comment(request): 'Comment posted!') return redirect(request, 'mediagoblin.user_pages.media_home', - media = request.matchdict['media'], - user = request.matchdict['user']) + media=request.matchdict['media'], + user=request.matchdict['user']) @get_user_media_entry @@ -184,6 +186,7 @@ def media_confirm_delete(request, media): ATOM_DEFAULT_NR_OF_UPDATED_ITEMS = 15 + def atom_feed(request): """ generates the atom feed with the newest images @@ -204,7 +207,7 @@ def atom_feed(request): feed = AtomFeed(request.matchdict['user'], feed_url=request.url, url=request.host_url) - + for entry in cursor: feed.add(entry.get('title'), entry.get('description_html'), diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 7ff3ec7f..4132b497 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -45,6 +45,8 @@ from itertools import izip, count DISPLAY_IMAGE_FETCHING_ORDER = [u'medium', u'original', u'thumb'] TESTS_ENABLED = False + + def _activate_testing(): """ Call this to activate testing in util.py @@ -78,7 +80,7 @@ SETUP_JINJA_ENVS = {} def get_jinja_env(template_loader, locale): """ - Set up the Jinja environment, + Set up the Jinja environment, (In the future we may have another system for providing theming; for now this is good enough.) @@ -147,7 +149,7 @@ def render_to_response(request, template, context, status=200): def redirect(request, *args, **kwargs): """Returns a HTTPFound(), takes a request and then urlgen params""" - + querystring = None if kwargs.get('querystring'): querystring = kwargs.get('querystring') @@ -197,6 +199,7 @@ def import_component(import_string): _punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') + def slugify(text, delim=u'-'): """ Generates an ASCII-only slug. Taken from http://flask.pocoo.org/snippets/5/ @@ -213,7 +216,7 @@ def slugify(text, delim=u'-'): ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # We have two "test inboxes" here: -# +# # EMAIL_TEST_INBOX: # ---------------- # If you're writing test views, you'll probably want to check this. @@ -233,7 +236,7 @@ def slugify(text, delim=u'-'): # ***IMPORTANT!*** # ---------------- # Before running tests that call functions which send email, you should -# always call _clear_test_inboxes() to "wipe" the inboxes clean. +# always call _clear_test_inboxes() to "wipe" the inboxes clean. EMAIL_TEST_INBOX = [] EMAIL_TEST_MBOX_INBOX = [] @@ -253,6 +256,7 @@ class FakeMhost(object): 'to': to_addrs, 'message': message}) + def _clear_test_inboxes(): global EMAIL_TEST_INBOX global EMAIL_TEST_MBOX_INBOX @@ -263,6 +267,7 @@ def _clear_test_inboxes(): ### ### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + def send_email(from_addr, to_addrs, subject, message_body): """ Simple email sending wrapper, use this so we can capture messages @@ -418,7 +423,7 @@ def convert_to_tag_list_of_dicts(tag_string): # Split the tag string into a list of tags for tag in stripped_tag_string.split( - mg_globals.app_config['tags_delimiter']): + mg_globals.app_config['tags_delimiter']): # Ignore empty or duplicate tags if tag.strip() and tag.strip() not in [t['name'] for t in taglist]: @@ -437,12 +442,13 @@ def media_tags_as_string(media_entry_tags): media_tag_string = '' if media_entry_tags: media_tag_string = mg_globals.app_config['tags_delimiter'].join( - [tag['name'] for tag in media_entry_tags]) + [tag['name'] for tag in media_entry_tags]) return media_tag_string TOO_LONG_TAG_WARNING = \ u'Tags must be shorter than %s characters. Tags that are too long: %s' + def tag_length_validator(form, field): """ Make sure tags do not exceed the maximum tag length. @@ -460,6 +466,7 @@ def tag_length_validator(form, field): MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape') + def cleaned_markdown_conversion(text): """ Take a block of text, run it through MarkDown, and clean its HTML. @@ -474,6 +481,7 @@ def cleaned_markdown_conversion(text): SETUP_GETTEXTS = {} + def setup_gettext(locale): """ Setup the gettext instance based on this locale @@ -558,6 +566,7 @@ def fake_ugettext_passthrough(string): PAGINATION_DEFAULT_PER_PAGE = 30 + class Pagination(object): """ Pagination class for mongodb queries. @@ -574,9 +583,9 @@ class Pagination(object): Args: - page: requested page - per_page: number of objects per page - - cursor: db cursor - - jump_to_id: ObjectId, sets the page to the page containing the object - with _id == jump_to_id. + - cursor: db cursor + - jump_to_id: ObjectId, sets the page to the page containing the + object with _id == jump_to_id. """ self.page = page self.per_page = per_page @@ -594,7 +603,6 @@ class Pagination(object): self.active_id = jump_to_id break - def __call__(self): """ Returns slice of objects for the requested page @@ -628,20 +636,18 @@ class Pagination(object): last = num def get_page_url_explicit(self, base_url, get_params, page_no): - """ - Get a page url by adding a page= parameter to the base url - """ + """Get a page url by adding a page= parameter to the base url + """ new_get_params = copy.copy(get_params or {}) new_get_params['page'] = page_no return "%s?%s" % ( base_url, urllib.urlencode(new_get_params)) def get_page_url(self, request, page_no): - """ - Get a new page url based of the request, and the new page number. + """Get a new page url based of the request, and the new page number. This is a nice wrapper around get_page_url_explicit() - """ + """ return self.get_page_url_explicit( request.path_info, request.GET, page_no) @@ -682,6 +688,7 @@ def render_404(request): return render_to_response( request, 'mediagoblin/404.html', {}, status=400) + def delete_media_files(media): """ Delete all files associated with a MediaEntry diff --git a/mediagoblin/views.py b/mediagoblin/views.py index 96687f96..afa6ac91 100644 --- a/mediagoblin/views.py +++ b/mediagoblin/views.py @@ -19,6 +19,7 @@ from mediagoblin.util import render_to_response, Pagination from mediagoblin.db.util import DESCENDING from mediagoblin.decorators import uses_pagination + @uses_pagination def root_view(request, page): cursor = request.db.MediaEntry.find( diff --git a/mediagoblin/workbench.py b/mediagoblin/workbench.py index 722f8e27..60a79f47 100644 --- a/mediagoblin/workbench.py +++ b/mediagoblin/workbench.py @@ -42,8 +42,10 @@ class Workbench(object): def __unicode__(self): return unicode(self.dir) + def __str__(self): return str(self.dir) + def __repr__(self): return repr(self.dir) @@ -140,7 +142,7 @@ class WorkbenchManager(object): self.base_workbench_dir = os.path.abspath(base_workbench_dir) if not os.path.exists(self.base_workbench_dir): os.makedirs(self.base_workbench_dir) - + def create_workbench(self): """ Create and return the path to a new workbench (directory). diff --git a/setup.py b/setup.py index 06626926..11c8fe6c 100644 --- a/setup.py +++ b/setup.py @@ -29,16 +29,17 @@ def get_version(): if mo: return mo.group(1) else: - raise RuntimeError("Unable to find version string in %s." % VERSIONFILE) + raise RuntimeError("Unable to find version string in %s." % + VERSIONFILE) setup( - name = "mediagoblin", - version = get_version(), + name="mediagoblin", + version=get_version(), packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), zip_safe=False, # scripts and dependencies - install_requires = [ + install_requires=[ 'setuptools', 'PasteScript', 'beaker', @@ -66,7 +67,7 @@ setup( # 'lxml', ], test_suite='nose.collector', - entry_points = """\ + entry_points="""\ [console_scripts] gmg = mediagoblin.gmg_commands:main_cli pybabel = mediagoblin.babel.messages.frontend:main @@ -83,7 +84,6 @@ setup( [babel.extractors] jinja2 = jinja2.ext:babel_extract """, - license='AGPLv3', author='Free Software Foundation and contributors', author_email='cwebber@gnu.org', From 285ffeddf3542201b83072d3be544c85e9c487c2 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sat, 1 Oct 2011 15:10:41 -0700 Subject: [PATCH 02/18] has_key is deprecated, converting uses to use "in" operator. --- mediagoblin/auth/views.py | 4 ++-- mediagoblin/db/util.py | 2 +- mediagoblin/gmg_commands/__init__.py | 2 +- mediagoblin/init/__init__.py | 4 ++-- mediagoblin/init/celery/__init__.py | 10 +++++----- mediagoblin/staticdirect.py | 6 +++--- mediagoblin/submit/views.py | 2 +- mediagoblin/util.py | 16 ++++++++-------- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index afcfcf1e..adf2c315 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -146,7 +146,7 @@ def verify_email(request): you are lucky :) """ # If we don't have userid and token parameters, we can't do anything; 404 - if not request.GET.has_key('userid') or not request.GET.has_key('token'): + if not 'userid' in request.GET or not 'token' in request.GET: return render_404(request) user = request.db.User.find_one( @@ -307,6 +307,6 @@ def _process_for_token(request): formdata = { 'vars': formdata_vars, 'has_userid_and_token': - formdata_vars.has_key('userid') and formdata_vars.has_key('token')} + 'userid' in formdata_vars and 'token' in formdata_vars} return formdata diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 38f0233f..52e97f6d 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -148,7 +148,7 @@ class RegisterMigration(object): """ def __init__(self, migration_number, migration_registry=MIGRATIONS): assert migration_number > 0, "Migration number must be > 0!" - assert not migration_registry.has_key(migration_number), \ + assert migration_number not in migration_registry, \ "Duplicate migration numbers detected! That's not allowed!" self.migration_number = migration_number diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index b3f69ccc..3250c246 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -61,7 +61,7 @@ def main_cli(): subparsers = parser.add_subparsers(help='sub-command help') for command_name, command_struct in SUBCOMMAND_MAP.iteritems(): - if command_struct.has_key('help'): + if 'help' in command_struct: subparser = subparsers.add_parser( command_name, help=command_struct['help']) else: diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py index f21e2fdd..08a0618d 100644 --- a/mediagoblin/init/__init__.py +++ b/mediagoblin/init/__init__.py @@ -103,10 +103,10 @@ def get_jinja_loader(user_template_path=None): def get_staticdirector(app_config): - if app_config.has_key('direct_remote_path'): + if 'direct_remote_path' in app_config: return staticdirect.RemoteStaticDirect( app_config['direct_remote_path'].strip()) - elif app_config.has_key('direct_remote_paths'): + elif 'direct_remote_paths' in app_config: direct_remote_path_lines = app_config[ 'direct_remote_paths'].strip().splitlines() return staticdirect.MultiRemoteStaticDirect( diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index 21ce1d39..f7ef9f39 100644 --- a/mediagoblin/init/celery/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -40,25 +40,25 @@ def setup_celery_from_config(app_config, global_config, - set_environ: if set, this will CELERY_CONFIG_MODULE to the settings_module """ - if global_config.has_key('celery'): + if 'celery' in global_config: celery_conf = global_config['celery'] else: celery_conf = {} - + celery_settings = {} # set up mongodb stuff celery_settings['CELERY_RESULT_BACKEND'] = 'mongodb' - if not celery_settings.has_key('BROKER_BACKEND'): + if 'BROKER_BACKEND' not in celery_settings: celery_settings['BROKER_BACKEND'] = 'mongodb' celery_mongo_settings = {} - if app_config.has_key('db_host'): + if 'db_host' in app_config: celery_mongo_settings['host'] = app_config['db_host'] if celery_settings['BROKER_BACKEND'] == 'mongodb': celery_settings['BROKER_HOST'] = app_config['db_host'] - if app_config.has_key('db_port'): + if 'db_port' in app_config: celery_mongo_settings['port'] = app_config['db_port'] if celery_settings['BROKER_BACKEND'] == 'mongodb': celery_settings['BROKER_PORT'] = app_config['db_port'] diff --git a/mediagoblin/staticdirect.py b/mediagoblin/staticdirect.py index 58175881..c6d2b374 100644 --- a/mediagoblin/staticdirect.py +++ b/mediagoblin/staticdirect.py @@ -21,24 +21,24 @@ import urlparse # Staticdirect infrastructure. # Borrowed largely from cc.engine # by Chris Webber & Creative Commons -# +# # This needs documentation! #################################### import pkg_resources import urlparse + class StaticDirect(object): def __init__(self): self.cache = {} def __call__(self, filepath): - if self.cache.has_key(filepath): + if filepath in self.cache: return self.cache[filepath] static_direction = self.cache[filepath] = self.get(filepath) return static_direction - def get(self, filepath): # should be implemented by the individual staticdirector diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 22a13b6d..d450ca21 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -40,7 +40,7 @@ def submit_start(request): submit_form = submit_forms.SubmitStartForm(request.POST) if request.method == 'POST' and submit_form.validate(): - if not (request.POST.has_key('file') + if not ('file' in request.POST and isinstance(request.POST['file'], FieldStorage) and request.POST['file'].file): submit_form.file.errors.append( diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 4132b497..d6ce5930 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -89,7 +89,7 @@ def get_jinja_env(template_loader, locale): # If we have a jinja environment set up with this locale, just # return that one. - if SETUP_JINJA_ENVS.has_key(locale): + if locale in SETUP_JINJA_ENVS: return SETUP_JINJA_ENVS[locale] template_env = jinja2.Environment( @@ -166,7 +166,7 @@ def setup_user_in_request(request): Examine a request and tack on a request.user parameter if that's appropriate. """ - if not request.session.has_key('user_id'): + if not 'user_id' in request.session: request.user = None return @@ -356,7 +356,7 @@ def get_locale_from_request(request): """ request_form = request.GET or request.POST - if request_form.has_key('lang'): + if 'lang' in request_form: return locale_to_lower_upper(request_form['lang']) accept_lang_matches = request.accept_language.best_matches() @@ -364,9 +364,9 @@ def get_locale_from_request(request): # Your routing can explicitly specify a target language matchdict = request.matchdict or {} - if matchdict.has_key('locale'): + if 'locale' in matchdict: target_lang = matchdict['locale'] - elif request.session.has_key('target_lang'): + elif 'target_lang' in request.session: target_lang = request.session['target_lang'] # Pull the first acceptable language elif accept_lang_matches: @@ -393,9 +393,9 @@ HTML_CLEANER = Cleaner( annoying_tags=True, allow_tags=[ 'div', 'b', 'i', 'em', 'strong', 'p', 'ul', 'ol', 'li', 'a', 'br'], - remove_unknown_tags=False, # can't be used with allow_tags + remove_unknown_tags=False, # can't be used with allow_tags safe_attrs_only=True, - add_nofollow=True, # for now + add_nofollow=True, # for now host_whitelist=(), whitelist_tags=set([])) @@ -492,7 +492,7 @@ def setup_gettext(locale): # TODO: fallback nicely on translations from pt_PT to pt if not # available, etc. - if SETUP_GETTEXTS.has_key(locale): + if locale in SETUP_GETTEXTS: this_gettext = SETUP_GETTEXTS[locale] else: this_gettext = gettext.translation( From 0cf5b8ad2499a93fdba5ff1202fdc554208ec85f Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 12 Nov 2011 13:35:41 -0600 Subject: [PATCH 03/18] Don't force-convert resized images to JPEG. That's just not nice for those of us who like transparency! --- mediagoblin/process_media/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 2b9eed6e..85bdcbea 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -136,7 +136,7 @@ def process_image(entry): thumb_file = mgg.public_store.get_file(thumb_filepath, 'w') with thumb_file: - thumb.save(thumb_file, "JPEG", quality=90) + thumb.save(thumb_file) # If the size of the original file exceeds the specified size of a `medium` # file, a `medium.jpg` files is created and later associated with the media @@ -154,7 +154,7 @@ def process_image(entry): medium_file = mgg.public_store.get_file(medium_filepath, 'w') with medium_file: - medium.save(medium_file, "JPEG", quality=90) + medium.save(medium_file) medium_processed = True # we have to re-read because unlike PIL, not everything reads From d0504cfa875b0ac7340fb00a64fc8422faecdc9a Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 12 Nov 2011 15:12:39 -0600 Subject: [PATCH 04/18] Final step for non-force-conversion to jpeg --- mediagoblin/process_media/__init__.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 85bdcbea..f63fb2b0 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -14,8 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import Image +import os +import Image from celery.task import Task from celery import registry @@ -122,17 +123,16 @@ def process_image(entry): mgg.queue_store, queued_filepath, 'source') + extension = os.path.splitext(queued_filename)[1] + try: thumb = Image.open(queued_filename) except IOError: raise BadMediaFail() thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS) - # ensure color mode is compatible with jpg - if thumb.mode != "RGB": - thumb = thumb.convert("RGB") - thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg') + thumb_filepath = create_pub_filepath(entry, 'thumbnail' + extension) thumb_file = mgg.public_store.get_file(thumb_filepath, 'w') with thumb_file: @@ -147,10 +147,7 @@ def process_image(entry): if medium.size[0] > MEDIUM_SIZE[0] or medium.size[1] > MEDIUM_SIZE[1]: medium.thumbnail(MEDIUM_SIZE, Image.ANTIALIAS) - if medium.mode != "RGB": - medium = medium.convert("RGB") - - medium_filepath = create_pub_filepath(entry, 'medium.jpg') + medium_filepath = create_pub_filepath(entry, 'medium' + extension) medium_file = mgg.public_store.get_file(medium_filepath, 'w') with medium_file: From efd0a42ca1b81a2dd17aee1626060584a278020c Mon Sep 17 00:00:00 2001 From: Elrond Date: Sun, 13 Nov 2011 19:51:11 +0100 Subject: [PATCH 05/18] Mark two strings for translation --- mediagoblin/edit/views.py | 2 +- mediagoblin/templates/mediagoblin/base.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index a6ddb553..17244831 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -170,7 +170,7 @@ def edit_profile(request): messages.add_message(request, messages.SUCCESS, - 'Profile edited!') + _("Profile edited!")) return redirect(request, 'mediagoblin.user_pages.user_home', user=edit_username) diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index b4c4dcf3..925386e5 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -67,7 +67,7 @@ user= request.user['username']) }}"> {{ request.user['username'] }} - (log out) + ({% trans %}log out{% endtrans %}) {% else %} {% trans %}Log in{% endtrans %} From b97ae0fd7da45c32897a4cb8437c04ddf04fdc95 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sun, 13 Nov 2011 11:41:43 -0800 Subject: [PATCH 06/18] Issue 653: Don't throw exception if response has no vary header. --- mediagoblin/middleware/csrf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/middleware/csrf.py b/mediagoblin/middleware/csrf.py index 7a5e352e..6c977f21 100644 --- a/mediagoblin/middleware/csrf.py +++ b/mediagoblin/middleware/csrf.py @@ -98,7 +98,7 @@ class CsrfMiddleware(object): httponly=True) # update the Vary header - response.vary = (response.vary or []) + ['Cookie'] + response.vary = getattr(response, 'vary', []) + ['Cookie'] def _make_token(self, request): """Generate a new token to use for CSRF protection.""" From ad3f1233df672688c09ab923d8bb216a351db8cb Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sun, 13 Nov 2011 11:59:24 -0800 Subject: [PATCH 07/18] Issue 653: Handle the case where request.vary is None --- mediagoblin/middleware/csrf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/middleware/csrf.py b/mediagoblin/middleware/csrf.py index 6c977f21..d0601af8 100644 --- a/mediagoblin/middleware/csrf.py +++ b/mediagoblin/middleware/csrf.py @@ -98,7 +98,7 @@ class CsrfMiddleware(object): httponly=True) # update the Vary header - response.vary = getattr(response, 'vary', []) + ['Cookie'] + response.vary = (getattr(response, 'vary') or []) + ['Cookie'] def _make_token(self, request): """Generate a new token to use for CSRF protection.""" From d9ed3aeb402fc66de2a79d145b5a443c9e660c18 Mon Sep 17 00:00:00 2001 From: Nathan Yergler Date: Sun, 13 Nov 2011 12:07:09 -0800 Subject: [PATCH 08/18] Issue 653: This time for sure! --- mediagoblin/middleware/csrf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/middleware/csrf.py b/mediagoblin/middleware/csrf.py index d0601af8..8275c18e 100644 --- a/mediagoblin/middleware/csrf.py +++ b/mediagoblin/middleware/csrf.py @@ -98,7 +98,7 @@ class CsrfMiddleware(object): httponly=True) # update the Vary header - response.vary = (getattr(response, 'vary') or []) + ['Cookie'] + response.vary = (getattr(response, 'vary', None) or []) + ['Cookie'] def _make_token(self, request): """Generate a new token to use for CSRF protection.""" From 688f56c2dc579218b35263d0189e5d7c9ba9627f Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 13 Nov 2011 14:34:22 -0600 Subject: [PATCH 09/18] Improved title block on media page --- mediagoblin/templates/mediagoblin/user_pages/media.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 17beffb2..2441ec1b 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -20,6 +20,8 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% from "mediagoblin/utils/pagination.html" import render_pagination %} +{% block title %}{{ media.title }} — {{ super() }}{% endblock %} + {% block mediagoblin_content %} {% if media %}
From 017d6ca3501b157277fc01fb37df2dbbd9ed17ef Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 13 Nov 2011 14:38:40 -0600 Subject: [PATCH 10/18] Enhanced title for user profile page --- .../templates/mediagoblin/user_pages/user.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index c5beeaaa..d65da055 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -26,6 +26,17 @@ user=user.username) }}"> {% endblock mediagoblin_head %} +{% block title %} + {%- if user -%} + {%- trans username=user.username -%} + {{ username }}'s profile + {%- endtrans %} — {{ super() }} + {%- else -%} + {{ super() }} + {%- endif -%} +{% endblock %} + + {% block mediagoblin_content -%} {# If no user... #} {% if not user %} From 7fc25d27208ef9926e94eeba953160ffbe676942 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 13 Nov 2011 14:40:11 -0600 Subject: [PATCH 11/18] If the gallery view makes sure we have a user anyway, do we need this check? Seems like the classic annoying "SHOULD NEVER HAPPEN" else: statement :) --- .../mediagoblin/user_pages/gallery.html | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/gallery.html b/mediagoblin/templates/mediagoblin/user_pages/gallery.html index df931d9c..86105493 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/gallery.html +++ b/mediagoblin/templates/mediagoblin/user_pages/gallery.html @@ -27,28 +27,23 @@ {% endblock mediagoblin_head %} {% block mediagoblin_content -%} - {% if user %} -

- {%- trans username=user.username, - user_url=request.urlgen( - 'mediagoblin.user_pages.user_home', - user=user.username) -%} - {{ username }}'s media - {%- endtrans %} -

+

+ {%- trans username=user.username, + user_url=request.urlgen( + 'mediagoblin.user_pages.user_home', + user=user.username) -%} + {{ username }}'s media + {%- endtrans %} +

- + -
- {% set feed_url = request.urlgen( - 'mediagoblin.user_pages.atom_feed', - user=user.username) %} - {% include "mediagoblin/utils/feed_link.html" %} -
- {% else %} - {# This *should* not occur as the view makes sure we pass in a user. #} -

{% trans %}Sorry, no such user found.{% endtrans %}

- {% endif %} +

+ {% set feed_url = request.urlgen( + 'mediagoblin.user_pages.atom_feed', + user=user.username) %} + {% include "mediagoblin/utils/feed_link.html" %} +
{% endblock %} From ab56689017daa985f3938af4710f3c76ad415bda Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 13 Nov 2011 14:42:03 -0600 Subject: [PATCH 12/18] Enhanced title on the user's main media gallery --- mediagoblin/templates/mediagoblin/user_pages/gallery.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mediagoblin/templates/mediagoblin/user_pages/gallery.html b/mediagoblin/templates/mediagoblin/user_pages/gallery.html index 86105493..b066dd71 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/gallery.html +++ b/mediagoblin/templates/mediagoblin/user_pages/gallery.html @@ -26,6 +26,12 @@ user=user.username) }}"> {% endblock mediagoblin_head %} +{% block title %} + {%- trans username=user.username -%} + {{ username }}'s media + {%- endtrans %} — {{ super() }} +{% endblock %} + {% block mediagoblin_content -%}

{%- trans username=user.username, From 4671fda345394dad9ca4278b1cf7b2cdf7d2b4ee Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 13 Nov 2011 14:48:51 -0600 Subject: [PATCH 13/18] Improving on tag page *and* adjusting translation for RTL reasons Basically moving the variable inside the translation to give translators more flexibility --- mediagoblin/templates/mediagoblin/listings/tag.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mediagoblin/templates/mediagoblin/listings/tag.html b/mediagoblin/templates/mediagoblin/listings/tag.html index 58863015..f797f72f 100644 --- a/mediagoblin/templates/mediagoblin/listings/tag.html +++ b/mediagoblin/templates/mediagoblin/listings/tag.html @@ -26,9 +26,13 @@ tag=tag_slug) }}"> {% endblock mediagoblin_head %} +{% block title %} + {% trans %}Media tagged with: {{ tag_name }}{% endtrans %} — {{ super() }} +{% endblock %} + {% block mediagoblin_content -%} <h1> - {% trans %}Media tagged with:{% endtrans %} {{ tag_name }} + {% trans %}Media tagged with: {{ tag_name }}{% endtrans %} </h1> <div class="container_16 media_gallery"> From 2b7aa99d3c221e713a95b664491f35612f9023cc Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber <cwebber@dustycloud.org> Date: Sun, 13 Nov 2011 20:39:42 -0600 Subject: [PATCH 14/18] Only show "post a comment" link if comments already exist The purpose of the link is to help you jump past comments to the comment box, and so... Even with this new conditional, I'm not entirely sure I like that link ;) --- mediagoblin/templates/mediagoblin/user_pages/media.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 2441ec1b..1e495b98 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -62,7 +62,7 @@ {%- endtrans %} </p> <h3></h3> - {% if request.user %} + {% if request.user and comments.count() %} <p><a href="#comment_form">{% trans %}Post a comment{% endtrans %}</a></p> {% endif %} {% if comments %} From a9c7af90408c3537f42763e63862a2ae44bcc368 Mon Sep 17 00:00:00 2001 From: Elrond <elrond+mediagoblin.org@samba-tng.org> Date: Tue, 15 Nov 2011 11:21:15 +0100 Subject: [PATCH 15/18] export: Handle Unicode titles better in logging log("ascii %s" % unicode_string) tries to convert unicode to ascii, which might fail. Better use log(u"unicode format %s" % unicode_string) and let the logging framework handle the conversion. This works much better and the exceptions still happening aren't stopping the main app. Also remove one useless import. --- mediagoblin/gmg_commands/import_export.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index a46219a0..30112969 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -16,7 +16,6 @@ from mediagoblin import mg_globals from mediagoblin.db.open import setup_connection_and_db_from_config -from mediagoblin.init.config import read_mediagoblin_config from mediagoblin.storage.filestorage import BasicFileStorage from mediagoblin.init import setup_storage, setup_global_and_app_config @@ -209,7 +208,7 @@ def _export_media(db, args): for entry in db.media_entries.find(): for name, path in entry['media_files'].items(): - _log.info('Exporting {0} - {1}'.format( + _log.info(u'Exporting {0} - {1}'.format( entry['title'], name)) From 7cbddc96a85410c14583b598312e40efe6051a44 Mon Sep 17 00:00:00 2001 From: Elrond <elrond+mediagoblin.org@samba-tng.org> Date: Mon, 14 Nov 2011 14:21:06 +0100 Subject: [PATCH 16/18] Enable mongokit's "Dot notation" mongokit documents can allow to use x.FIELD instead of x["FIELD"]. First it looks a lot more pythonic. Second it might allow us an easier migration path towards an sqlalchemy database backend. Docs: http://namlook.github.com/mongokit/tutorial.html#dot-notation --- mediagoblin/db/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index c010cb89..65c15917 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -63,6 +63,7 @@ class User(Document): - bio_html: biography of the user converted to proper HTML. """ __collection__ = 'users' + use_dot_notation = True structure = { 'username': unicode, @@ -177,6 +178,7 @@ class MediaEntry(Document): - fail_metadata: """ __collection__ = 'media_entries' + use_dot_notation = True structure = { 'uploader': ObjectId, @@ -321,6 +323,7 @@ class MediaComment(Document): """ __collection__ = 'media_comments' + use_dot_notation = True structure = { 'media_entry': ObjectId, From eabe6b678a98fd06d9cd8463935a3b842f41485c Mon Sep 17 00:00:00 2001 From: Elrond <elrond+mediagoblin.org@samba-tng.org> Date: Sun, 13 Nov 2011 19:25:06 +0100 Subject: [PATCH 17/18] Dot-Notation for "_id" Note: Migrations can't use "Dot Notation"! Migrations run on pymongo, not mongokit. So they can't use the "Dot Notation". This isn't really a big issue, as migrations are anyway quite mongo specific. --- mediagoblin/auth/lib.py | 4 ++-- mediagoblin/auth/views.py | 4 ++-- mediagoblin/db/models.py | 10 +++++----- mediagoblin/decorators.py | 6 +++--- mediagoblin/edit/lib.py | 2 +- mediagoblin/edit/views.py | 6 +++--- mediagoblin/process_media/__init__.py | 4 ++-- mediagoblin/submit/views.py | 10 +++++----- .../mediagoblin/user_pages/media.html | 10 +++++----- .../templates/mediagoblin/user_pages/user.html | 6 +++--- mediagoblin/tests/test_auth.py | 12 ++++++------ mediagoblin/tests/test_submission.py | 6 +++--- mediagoblin/tools/pagination.py | 2 +- mediagoblin/user_pages/views.py | 18 +++++++++--------- 14 files changed, 50 insertions(+), 50 deletions(-) diff --git a/mediagoblin/auth/lib.py b/mediagoblin/auth/lib.py index 653424cc..cf4a2b83 100644 --- a/mediagoblin/auth/lib.py +++ b/mediagoblin/auth/lib.py @@ -109,7 +109,7 @@ def send_verification_email(user, request): 'verification_url': EMAIL_VERIFICATION_TEMPLATE.format( host=request.host, uri=request.urlgen('mediagoblin.auth.verify_email'), - userid=unicode(user['_id']), + userid=unicode(user._id), verification_key=user['verification_key'])}) # TODO: There is no error handling in place @@ -144,7 +144,7 @@ def send_fp_verification_email(user, request): 'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format( host=request.host, uri=request.urlgen('mediagoblin.auth.verify_forgot_password'), - userid=unicode(user['_id']), + userid=unicode(user._id), fp_verification_key=user['fp_verification_key'])}) # TODO: There is no error handling in place diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index 8888d23c..8412b81c 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -87,7 +87,7 @@ def register(request): user.save(validate=True) # log the user in - request.session['user_id'] = unicode(user['_id']) + request.session['user_id'] = unicode(user._id) request.session.save() # send verification email @@ -122,7 +122,7 @@ def login(request): if user and user.check_login(request.POST['password']): # set up login in session - request.session['user_id'] = unicode(user['_id']) + request.session['user_id'] = unicode(user._id) request.session.save() if request.POST.get('next'): diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 65c15917..1c1bc2fd 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -219,7 +219,7 @@ class MediaEntry(Document): def get_comments(self): return self.db.MediaComment.find({ - 'media_entry': self['_id']}).sort('created', DESCENDING) + 'media_entry': self._id}).sort('created', DESCENDING) def get_display_media(self, media_map, fetch_order=common.DISPLAY_IMAGE_FETCHING_ORDER): @@ -250,7 +250,7 @@ class MediaEntry(Document): {'slug': self['slug']}) if duplicate: - self['slug'] = "%s-%s" % (self['_id'], self['slug']) + self['slug'] = "%s-%s" % (self._id, self['slug']) def url_for_self(self, urlgen): """ @@ -269,13 +269,13 @@ class MediaEntry(Document): return urlgen( 'mediagoblin.user_pages.media_home', user=uploader['username'], - media=unicode(self['_id'])) + media=unicode(self._id)) def url_to_prev(self, urlgen): """ Provide a url to the previous entry from this user, if there is one """ - cursor = self.db.MediaEntry.find({'_id': {"$gt": self['_id']}, + cursor = self.db.MediaEntry.find({'_id': {"$gt": self._id}, 'uploader': self['uploader'], 'state': 'processed'}).sort( '_id', ASCENDING).limit(1) @@ -288,7 +288,7 @@ class MediaEntry(Document): """ Provide a url to the next entry from this user, if there is one """ - cursor = self.db.MediaEntry.find({'_id': {"$lt": self['_id']}, + cursor = self.db.MediaEntry.find({'_id': {"$lt": self._id}, 'uploader': self['uploader'], 'state': 'processed'}).sort( '_id', DESCENDING).limit(1) diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index b247e229..8f7532ec 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -60,7 +60,7 @@ def user_may_delete_media(controller): uploader = request.db.MediaEntry.find_one( {'_id': ObjectId(request.matchdict['media'])}).uploader() if not (request.user['is_admin'] or - request.user['_id'] == uploader['_id']): + request.user._id == uploader._id): return exc.HTTPForbidden() return controller(request, *args, **kwargs) @@ -99,7 +99,7 @@ def get_user_media_entry(controller): media = request.db.MediaEntry.find_one( {'slug': request.matchdict['media'], 'state': 'processed', - 'uploader': user['_id']}) + 'uploader': user._id}) # no media via slug? Grab it via ObjectId if not media: @@ -107,7 +107,7 @@ def get_user_media_entry(controller): media = request.db.MediaEntry.find_one( {'_id': ObjectId(request.matchdict['media']), 'state': 'processed', - 'uploader': user['_id']}) + 'uploader': user._id}) except InvalidId: return render_404(request) diff --git a/mediagoblin/edit/lib.py b/mediagoblin/edit/lib.py index b722e9c1..458b704e 100644 --- a/mediagoblin/edit/lib.py +++ b/mediagoblin/edit/lib.py @@ -17,7 +17,7 @@ def may_edit_media(request, media): """Check, if the request's user may edit the media details""" - if media['uploader'] == request.user['_id']: + if media['uploader'] == request.user._id: return True if request.user['is_admin']: return True diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index f3ebebe8..5f781552 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -57,7 +57,7 @@ def edit_media(request, media): existing_user_slug_entries = request.db.MediaEntry.find( {'slug': request.POST['slug'], 'uploader': media['uploader'], - '_id': {'$ne': media['_id']}}).count() + '_id': {'$ne': media._id}}).count() if existing_user_slug_entries: form.slug.errors.append( @@ -78,7 +78,7 @@ def edit_media(request, media): location=media.url_for_self(request.urlgen)) if request.user['is_admin'] \ - and media['uploader'] != request.user['_id'] \ + and media['uploader'] != request.user._id \ and request.method != 'POST': messages.add_message( request, messages.WARNING, @@ -104,7 +104,7 @@ def edit_attachments(request, media): attachment_public_filepath \ = mg_globals.public_store.get_unique_filepath( - ['media_entries', unicode(media['_id']), 'attachment', + ['media_entries', unicode(media._id), 'attachment', secure_filename(request.POST['attachment_file'].filename)]) attachment_public_file = mg_globals.public_store.get_file( diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 3d6b418f..34d83e54 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -32,7 +32,7 @@ MEDIUM_SIZE = 640, 640 def create_pub_filepath(entry, filename): return mgg.public_store.get_unique_filepath( ['media_entries', - unicode(entry['_id']), + unicode(entry._id), filename]) @@ -56,7 +56,7 @@ class ProcessMedia(Task): try: process_image(entry) except BaseProcessingFail, exc: - mark_entry_failed(entry[u'_id'], exc) + mark_entry_failed(entry._id, exc) return entry['state'] = u'processed' diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 25f7d79d..bd63bd18 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -52,7 +52,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry['_id'] = ObjectId() + entry._id = ObjectId() entry['title'] = ( unicode(request.POST['title']) or unicode(splitext(filename)[0])) @@ -62,7 +62,7 @@ def submit_start(request): entry['description']) entry['media_type'] = u'image' # heh - entry['uploader'] = request.user['_id'] + entry['uploader'] = request.user._id # Process the user's folksonomy "tags" entry['tags'] = convert_to_tag_list_of_dicts( @@ -74,7 +74,7 @@ def submit_start(request): # Now store generate the queueing related filename queue_filepath = request.app.queue_store.get_unique_filepath( ['media_entries', - unicode(entry['_id']), + unicode(entry._id), secure_filename(filename)]) # queue appropriately @@ -105,7 +105,7 @@ def submit_start(request): # conditions with changes to the document via processing code) try: process_media.apply_async( - [unicode(entry['_id'])], {}, + [unicode(entry._id)], {}, task_id=task_id) except BaseException as exc: # The purpose of this section is because when running in "lazy" @@ -116,7 +116,7 @@ def submit_start(request): # # ... not completely the diaper pattern because the # exception is re-raised :) - mark_entry_failed(entry[u'_id'], exc) + mark_entry_failed(entry._id, exc) # re-raise the exception raise diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 1e495b98..4b02b684 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -69,10 +69,10 @@ {% for comment in comments %} {% set comment_author = comment.author() %} {% if pagination.active_id == comment._id %} - <div class="comment_wrapper comment_active" id="comment-{{ comment['_id'] }}"> + <div class="comment_wrapper comment_active" id="comment-{{ comment._id }}"> <a name="comment" id="comment"></a> {% else %} - <div class="comment_wrapper" id="comment-{{ comment['_id'] }}"> + <div class="comment_wrapper" id="comment-{{ comment._id }}"> {% endif %} <div class="comment_content">{% autoescape False %}{{ comment.content_html }} @@ -83,7 +83,7 @@ {{ comment_author['username'] }}</a> {% trans %}at{% endtrans %} <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment', - comment = comment['_id'], + comment = comment._id, user = media.uploader().username, media = media._id) }}#comment"> {{ comment.created.strftime("%I:%M%p %Y-%m-%d") }} @@ -114,7 +114,7 @@ <div class="grid_5 omega"> {% include "mediagoblin/utils/prev_next.html" %} - {% if media['uploader'] == request.user['_id'] or + {% if media['uploader'] == request.user._id or request.user['is_admin'] %} <h3>{% trans %}Actions{% endtrans %}</h3> <p> @@ -151,7 +151,7 @@ {% endif %} {% if app_config['allow_attachments'] - and (media['uploader'] == request.user['_id'] + and (media['uploader'] == request.user._id or request.user['is_admin']) %} <p> <a href="{{ request.urlgen('mediagoblin.edit.attachments', diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index d65da055..1de7f611 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -90,7 +90,7 @@ </h1> {% if not user['url'] and not user['profile'] %} - {% if request.user['_id'] == user['_id'] %} + {% if request.user._id == user._id %} <div class="grid_6 alpha empty_space"> <p> {% trans %}Here's a spot to tell others about yourself.{% endtrans %} @@ -113,7 +113,7 @@ {% else %} <div class="grid_6 alpha"> {% include "mediagoblin/utils/profile.html" %} - {% if request.user['_id'] == user['_id'] or request.user['is_admin'] %} + {% if request.user._id == user._id or request.user['is_admin'] %} <a href="{{ request.urlgen('mediagoblin.edit.profile') }}?username={{ user.username }}"> {%- trans %}Edit profile{% endtrans -%} @@ -140,7 +140,7 @@ {% include "mediagoblin/utils/feed_link.html" %} </div> {% else %} - {% if request.user['_id'] == user['_id'] %} + {% if request.user._id == user._id %} <div class="grid_10 omega empty_space"> <p> {% trans -%} diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index 40961eca..153c6e53 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -168,7 +168,7 @@ def test_register_views(test_app): ## Make sure user is logged in request = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/user_pages/user.html']['request'] - assert request.session['user_id'] == unicode(new_user['_id']) + assert request.session['user_id'] == unicode(new_user._id) ## Make sure we get email confirmation, and try verifying assert len(mail.EMAIL_TEST_INBOX) == 1 @@ -185,7 +185,7 @@ def test_register_views(test_app): ### user should have these same parameters assert parsed_get_params['userid'] == [ - unicode(new_user['_id'])] + unicode(new_user._id)] assert parsed_get_params['token'] == [ new_user['verification_key']] @@ -193,7 +193,7 @@ def test_register_views(test_app): template.clear_test_template_context() response = test_app.get( "/auth/verify_email/?userid=%s&token=total_bs" % unicode( - new_user['_id'])) + new_user._id)) response.follow() context = template.TEMPLATE_TEST_CONTEXT[ 'mediagoblin/user_pages/user.html'] @@ -269,7 +269,7 @@ def test_register_views(test_app): # user should have matching parameters new_user = mg_globals.database.User.find_one({'username': 'happygirl'}) - assert parsed_get_params['userid'] == [unicode(new_user['_id'])] + assert parsed_get_params['userid'] == [unicode(new_user._id)] assert parsed_get_params['token'] == [new_user['fp_verification_key']] ### The forgotten password token should be set to expire in ~ 10 days @@ -280,7 +280,7 @@ def test_register_views(test_app): template.clear_test_template_context() response = test_app.get( "/auth/forgot_password/verify/?userid=%s&token=total_bs" % unicode( - new_user['_id']), status=400) + new_user._id), status=400) assert response.status == '400 Bad Request' ## Try using an expired token to change password, shouldn't work @@ -412,7 +412,7 @@ def test_authentication_views(test_app): # Make sure user is in the session context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html'] session = context['request'].session - assert session['user_id'] == unicode(test_user['_id']) + assert session['user_id'] == unicode(test_user._id) # Successful logout # ----------------- diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py index 1c657e6c..dec7118b 100644 --- a/mediagoblin/tests/test_submission.py +++ b/mediagoblin/tests/test_submission.py @@ -177,7 +177,7 @@ class TestSubmission: request.urlgen('mediagoblin.user_pages.media_confirm_delete', # No work: user=media.uploader().username, user=self.test_user['username'], - media=media['_id']), + media=media._id), # no value means no confirm {}) @@ -197,7 +197,7 @@ class TestSubmission: request.urlgen('mediagoblin.user_pages.media_confirm_delete', # No work: user=media.uploader().username, user=self.test_user['username'], - media=media['_id']), + media=media._id), {'confirm': 'y'}) response.follow() @@ -208,7 +208,7 @@ class TestSubmission: # Does media entry still exist? assert_false( request.db.MediaEntry.find( - {'_id': media['_id']}).count()) + {'_id': media._id}).count()) def test_malicious_uploads(self): # Test non-suppoerted file with non-supported extension diff --git a/mediagoblin/tools/pagination.py b/mediagoblin/tools/pagination.py index bc20ec90..5ebc3c5a 100644 --- a/mediagoblin/tools/pagination.py +++ b/mediagoblin/tools/pagination.py @@ -53,7 +53,7 @@ class Pagination(object): cursor = copy.copy(self.cursor) for (doc, increment) in izip(cursor, count(0)): - if doc['_id'] == jump_to_id: + if doc._id == jump_to_id: self.page = 1 + int(floor(increment / self.per_page)) self.active_id = jump_to_id diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 2090d6fd..82865bb4 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -45,7 +45,7 @@ def user_home(request, page): {'user': user}) cursor = request.db.MediaEntry.find( - {'uploader': user['_id'], + {'uploader': user._id, 'state': 'processed'}).sort('created', DESCENDING) pagination = Pagination(page, cursor) @@ -78,7 +78,7 @@ def user_gallery(request, page): return render_404(request) cursor = request.db.MediaEntry.find( - {'uploader': user['_id'], + {'uploader': user._id, 'state': 'processed'}).sort('created', DESCENDING) pagination = Pagination(page, cursor) @@ -135,8 +135,8 @@ def media_post_comment(request, media): assert request.method == 'POST' comment = request.db.MediaComment() - comment['media_entry'] = media['_id'] - comment['author'] = request.user['_id'] + comment['media_entry'] = media._id + comment['author'] = request.user._id comment['content'] = unicode(request.POST['comment_content']) comment['content_html'] = cleaned_markdown_conversion(comment['content']) @@ -179,7 +179,7 @@ def media_confirm_delete(request, media): location=media.url_for_self(request.urlgen)) if ((request.user[u'is_admin'] and - request.user[u'_id'] != media.uploader()[u'_id'])): + request.user._id != media.uploader()._id)): messages.add_message( request, messages.WARNING, _("You are about to delete another user's media. " @@ -207,7 +207,7 @@ def atom_feed(request): return render_404(request) cursor = request.db.MediaEntry.find({ - 'uploader': user['_id'], + 'uploader': user._id, 'state': 'processed'}) \ .sort('created', DESCENDING) \ .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS) @@ -251,7 +251,7 @@ def processing_panel(request): # # Make sure we have permission to access this user's panel. Only # admins and this user herself should be able to do so. - if not (user[u'_id'] == request.user[u'_id'] + if not (user._id == request.user._id or request.user.is_admin): # No? Let's simply redirect to this user's homepage then. return redirect( @@ -260,12 +260,12 @@ def processing_panel(request): # Get media entries which are in-processing processing_entries = request.db.MediaEntry.find( - {'uploader': user['_id'], + {'uploader': user._id, 'state': 'processing'}).sort('created', DESCENDING) # Get media entries which have failed to process failed_entries = request.db.MediaEntry.find( - {'uploader': user['_id'], + {'uploader': user._id, 'state': 'failed'}).sort('created', DESCENDING) # Render to response From 3618a9ac5112c657fd095a0f9cbd346921a4e800 Mon Sep 17 00:00:00 2001 From: Elrond <elrond+mediagoblin.org@samba-tng.org> Date: Mon, 14 Nov 2011 17:11:37 +0100 Subject: [PATCH 18/18] Dot-Notation: x._id = ObjectId() doesn't seem to work properly For whatever reason, this does not work as expected: entry._id = ObjectId() Need to go this way: entry['_id'] = ObjectId() --- mediagoblin/submit/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index bd63bd18..139b1d1d 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -52,7 +52,7 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry._id = ObjectId() + entry['_id'] = ObjectId() entry['title'] = ( unicode(request.POST['title']) or unicode(splitext(filename)[0]))