From 49745d5138540af8f7cbce318767172f4c560881 Mon Sep 17 00:00:00 2001 From: Jef van Schendel Date: Thu, 17 Jan 2013 20:04:22 +0100 Subject: Add "Browse collections" link to profile pages --- mediagoblin/templates/mediagoblin/user_pages/user.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index 76bce1e2..71acd66c 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -118,6 +118,12 @@ {% endif %} {% endif %} +

+ + {%- trans %}Browse collections{% endtrans -%} + +

{% if media_entries.count() %} -- cgit v1.2.3 From 9d8285864aacda5f321e473f4d9298a183f41645 Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 16 Jan 2013 19:50:48 +0100 Subject: Remove DEFAULT_WORKBENCH_DIR. We never used this. Removed, as okayed by cwebber. --- mediagoblin/workbench.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/mediagoblin/workbench.py b/mediagoblin/workbench.py index 0d4db52b..0bd4096b 100644 --- a/mediagoblin/workbench.py +++ b/mediagoblin/workbench.py @@ -19,10 +19,6 @@ import shutil import tempfile -DEFAULT_WORKBENCH_DIR = os.path.join( - tempfile.gettempdir(), u'mgoblin_workbench') - - # Actual workbench stuff # ---------------------- -- cgit v1.2.3 From 626a093ccc7bd275085cea1bbe7fb6ce14b47321 Mon Sep 17 00:00:00 2001 From: Elrond Date: Thu, 17 Jan 2013 22:10:43 +0100 Subject: Move workbench into tools directory. --- mediagoblin/init/__init__.py | 2 +- mediagoblin/tests/test_workbench.py | 2 +- mediagoblin/tools/workbench.py | 164 ++++++++++++++++++++++++++++++++++++ mediagoblin/workbench.py | 164 ------------------------------------ 4 files changed, 166 insertions(+), 166 deletions(-) create mode 100644 mediagoblin/tools/workbench.py delete mode 100644 mediagoblin/workbench.py diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py index ab6e6399..7c832442 100644 --- a/mediagoblin/init/__init__.py +++ b/mediagoblin/init/__init__.py @@ -26,7 +26,7 @@ from mediagoblin import mg_globals from mediagoblin.mg_globals import setup_globals from mediagoblin.db.open import setup_connection_and_db_from_config, \ check_db_migrations_current, load_models -from mediagoblin.workbench import WorkbenchManager +from mediagoblin.tools.workbench import WorkbenchManager from mediagoblin.storage import storage_system_from_config diff --git a/mediagoblin/tests/test_workbench.py b/mediagoblin/tests/test_workbench.py index 9da8eea0..636c8689 100644 --- a/mediagoblin/tests/test_workbench.py +++ b/mediagoblin/tests/test_workbench.py @@ -18,7 +18,7 @@ import os import tempfile -from mediagoblin import workbench +from mediagoblin.tools import workbench from mediagoblin.mg_globals import setup_globals from mediagoblin.decorators import get_workbench from mediagoblin.tests.test_storage import get_tmp_filestorage diff --git a/mediagoblin/tools/workbench.py b/mediagoblin/tools/workbench.py new file mode 100644 index 00000000..0bd4096b --- /dev/null +++ b/mediagoblin/tools/workbench.py @@ -0,0 +1,164 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import os +import shutil +import tempfile + + +# Actual workbench stuff +# ---------------------- + +class Workbench(object): + """ + Represent the directory for the workbench + + WARNING: DO NOT create Workbench objects on your own, + let the WorkbenchManager do that for you! + """ + def __init__(self, dir): + """ + WARNING: DO NOT create Workbench objects on your own, + let the WorkbenchManager do that for you! + """ + self.dir = dir + + def __unicode__(self): + return unicode(self.dir) + + def __str__(self): + return str(self.dir) + + def __repr__(self): + try: + return str(self) + except AttributeError: + return 'None' + + def joinpath(self, *args): + return os.path.join(self.dir, *args) + + def localized_file(self, storage, filepath, + filename_if_copying=None, + keep_extension_if_copying=True): + """ + Possibly localize the file from this storage system (for read-only + purposes, modifications should be written to a new file.). + + If the file is already local, just return the absolute filename of that + local file. Otherwise, copy the file locally to the workbench, and + return the absolute path of the new file. + + If it is copying locally, we might want to require a filename like + "source.jpg" to ensure that we won't conflict with other filenames in + our workbench... if that's the case, make sure filename_if_copying is + set to something like 'source.jpg'. Relatedly, if you set + keep_extension_if_copying, you don't have to set an extension on + filename_if_copying yourself, it'll be set for you (assuming such an + extension can be extacted from the filename in the filepath). + + Returns: + localized_filename + + Examples: + >>> wb_manager.localized_file( + ... '/our/workbench/subdir', local_storage, + ... ['path', 'to', 'foobar.jpg']) + u'/local/storage/path/to/foobar.jpg' + + >>> wb_manager.localized_file( + ... '/our/workbench/subdir', remote_storage, + ... ['path', 'to', 'foobar.jpg']) + '/our/workbench/subdir/foobar.jpg' + + >>> wb_manager.localized_file( + ... '/our/workbench/subdir', remote_storage, + ... ['path', 'to', 'foobar.jpg'], 'source.jpeg', False) + '/our/workbench/subdir/foobar.jpeg' + + >>> wb_manager.localized_file( + ... '/our/workbench/subdir', remote_storage, + ... ['path', 'to', 'foobar.jpg'], 'source', True) + '/our/workbench/subdir/foobar.jpg' + """ + if storage.local_storage: + return storage.get_local_path(filepath) + else: + if filename_if_copying is None: + dest_filename = filepath[-1] + else: + orig_filename, orig_ext = os.path.splitext(filepath[-1]) + if keep_extension_if_copying and orig_ext: + dest_filename = filename_if_copying + orig_ext + else: + dest_filename = filename_if_copying + + full_dest_filename = os.path.join( + self.dir, dest_filename) + + # copy it over + storage.copy_locally( + filepath, full_dest_filename) + + return full_dest_filename + + def destroy(self): + """ + Destroy this workbench! Deletes the directory and all its contents! + + WARNING: Does no checks for a sane value in self.dir! + """ + # just in case + workbench = os.path.abspath(self.dir) + shutil.rmtree(workbench) + del self.dir + + def __enter__(self): + """Make Workbench a context manager so we can use `with Workbench() as bench:`""" + return self + + def __exit__(self, *args): + """Clean up context manager, aka ourselves, deleting the workbench""" + self.destroy() + + +class WorkbenchManager(object): + """ + A system for generating and destroying workbenches. + + Workbenches are actually just subdirectories of a (local) temporary + storage space for during the processing stage. The preferred way to + create them is to use: + + with workbenchmger.create() as workbench: + do stuff... + + This will automatically clean up all temporary directories even in + case of an exceptions. Also check the + @mediagoblin.decorators.get_workbench decorator for a convenient + wrapper. + """ + + def __init__(self, base_workbench_dir): + 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(self): + """ + Create and return the path to a new workbench (directory). + """ + return Workbench(tempfile.mkdtemp(dir=self.base_workbench_dir)) diff --git a/mediagoblin/workbench.py b/mediagoblin/workbench.py deleted file mode 100644 index 0bd4096b..00000000 --- a/mediagoblin/workbench.py +++ /dev/null @@ -1,164 +0,0 @@ -# GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import os -import shutil -import tempfile - - -# Actual workbench stuff -# ---------------------- - -class Workbench(object): - """ - Represent the directory for the workbench - - WARNING: DO NOT create Workbench objects on your own, - let the WorkbenchManager do that for you! - """ - def __init__(self, dir): - """ - WARNING: DO NOT create Workbench objects on your own, - let the WorkbenchManager do that for you! - """ - self.dir = dir - - def __unicode__(self): - return unicode(self.dir) - - def __str__(self): - return str(self.dir) - - def __repr__(self): - try: - return str(self) - except AttributeError: - return 'None' - - def joinpath(self, *args): - return os.path.join(self.dir, *args) - - def localized_file(self, storage, filepath, - filename_if_copying=None, - keep_extension_if_copying=True): - """ - Possibly localize the file from this storage system (for read-only - purposes, modifications should be written to a new file.). - - If the file is already local, just return the absolute filename of that - local file. Otherwise, copy the file locally to the workbench, and - return the absolute path of the new file. - - If it is copying locally, we might want to require a filename like - "source.jpg" to ensure that we won't conflict with other filenames in - our workbench... if that's the case, make sure filename_if_copying is - set to something like 'source.jpg'. Relatedly, if you set - keep_extension_if_copying, you don't have to set an extension on - filename_if_copying yourself, it'll be set for you (assuming such an - extension can be extacted from the filename in the filepath). - - Returns: - localized_filename - - Examples: - >>> wb_manager.localized_file( - ... '/our/workbench/subdir', local_storage, - ... ['path', 'to', 'foobar.jpg']) - u'/local/storage/path/to/foobar.jpg' - - >>> wb_manager.localized_file( - ... '/our/workbench/subdir', remote_storage, - ... ['path', 'to', 'foobar.jpg']) - '/our/workbench/subdir/foobar.jpg' - - >>> wb_manager.localized_file( - ... '/our/workbench/subdir', remote_storage, - ... ['path', 'to', 'foobar.jpg'], 'source.jpeg', False) - '/our/workbench/subdir/foobar.jpeg' - - >>> wb_manager.localized_file( - ... '/our/workbench/subdir', remote_storage, - ... ['path', 'to', 'foobar.jpg'], 'source', True) - '/our/workbench/subdir/foobar.jpg' - """ - if storage.local_storage: - return storage.get_local_path(filepath) - else: - if filename_if_copying is None: - dest_filename = filepath[-1] - else: - orig_filename, orig_ext = os.path.splitext(filepath[-1]) - if keep_extension_if_copying and orig_ext: - dest_filename = filename_if_copying + orig_ext - else: - dest_filename = filename_if_copying - - full_dest_filename = os.path.join( - self.dir, dest_filename) - - # copy it over - storage.copy_locally( - filepath, full_dest_filename) - - return full_dest_filename - - def destroy(self): - """ - Destroy this workbench! Deletes the directory and all its contents! - - WARNING: Does no checks for a sane value in self.dir! - """ - # just in case - workbench = os.path.abspath(self.dir) - shutil.rmtree(workbench) - del self.dir - - def __enter__(self): - """Make Workbench a context manager so we can use `with Workbench() as bench:`""" - return self - - def __exit__(self, *args): - """Clean up context manager, aka ourselves, deleting the workbench""" - self.destroy() - - -class WorkbenchManager(object): - """ - A system for generating and destroying workbenches. - - Workbenches are actually just subdirectories of a (local) temporary - storage space for during the processing stage. The preferred way to - create them is to use: - - with workbenchmger.create() as workbench: - do stuff... - - This will automatically clean up all temporary directories even in - case of an exceptions. Also check the - @mediagoblin.decorators.get_workbench decorator for a convenient - wrapper. - """ - - def __init__(self, base_workbench_dir): - 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(self): - """ - Create and return the path to a new workbench (directory). - """ - return Workbench(tempfile.mkdtemp(dir=self.base_workbench_dir)) -- cgit v1.2.3 From ba5ea989a5826440e8b84af8128dadd0ae252259 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 17 Jan 2013 22:37:41 +0100 Subject: Return to media collection page if no collection selected schendje rightly pointed out that we should not return to the media homepage if we did not select a collection on the "collect" page, but should actually return to the collect page. This is an improvement of the user experience ;-) Signed-off-by: Sebastian Spaeth --- mediagoblin/user_pages/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 30c78a38..d1ec23dc 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -226,6 +226,10 @@ def media_collect(request, media): messages.add_message( request, messages.ERROR, _('You have to select or add a collection')) + return redirect(request, "mediagoblin.user_pages.media_collect", + user=media.get_uploader.username, + media=media.id) + # Check whether media already exists in collection elif CollectionItem.query.filter_by( -- cgit v1.2.3