diff options
24 files changed, 174 insertions, 133 deletions
diff --git a/docs/hackinghowto.rst b/docs/hackinghowto.rst index 911f2340..08b228f1 100644 --- a/docs/hackinghowto.rst +++ b/docs/hackinghowto.rst @@ -150,7 +150,7 @@ celeryd in another window. Run:: - CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_celery ./bin/celeryd + CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery ./bin/celeryd Running the test suite diff --git a/mediagoblin/app.py b/mediagoblin/app.py index b27b5761..9454b403 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -21,11 +21,12 @@ import routes from webob import Request, exc from mediagoblin import routing, util, storage, staticdirect -from mediagoblin.config import ( +from mediagoblin.init.config import ( read_mediagoblin_config, generate_validation_report) from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.mg_globals import setup_globals -from mediagoblin.celery_setup import setup_celery_from_config +from mediagoblin.init.celery import setup_celery_from_config +from mediagoblin.init import get_jinja_loader from mediagoblin.workbench import WorkbenchManager @@ -71,7 +72,7 @@ class MediaGoblinApp(object): app_config) # Get the template environment - self.template_loader = util.get_jinja_loader( + self.template_loader = get_jinja_loader( app_config.get('user_template_path')) # Set up storage systems diff --git a/mediagoblin/db/__init__.py b/mediagoblin/db/__init__.py index c129cbf8..776025ca 100644 --- a/mediagoblin/db/__init__.py +++ b/mediagoblin/db/__init__.py @@ -13,3 +13,49 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. + +""" +Database Abstraction/Wrapper Layer +================================== + + **NOTE from Chris Webber:** I asked Elrond to explain why he put + ASCENDING and DESCENDING in db/util.py when we could just import from + 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 + actually do things, we might revisit or remove this. But for more + information, read below. + +This submodule is for most of the db specific stuff. + +There are two main ideas here: + +1. Open up a small possibility to replace mongo by another + db. This means, that all direct mongo accesses should + happen in the db submodule. While all the rest uses an + API defined by this submodule. + + Currently this API happens to be basicly mongo. + Which means, that the abstraction/wrapper layer is + extremely thin. + +2. Give the rest of the app a simple and easy way to get most of + their db needs. Which often means some simple import + from db.util. + +What does that mean? + +* Never import mongo directly outside of this submodule. + +* Inside this submodule you can do whatever is needed. The + API border is exactly at the submodule layer. Nowhere + else. + +* helper functions can be moved in here. They become part + of the db.* API + +""" diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index bf825a23..1d91a14b 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -23,7 +23,6 @@ from mediagoblin.auth import lib as auth_lib from mediagoblin import mg_globals from mediagoblin.db import migrations from mediagoblin.db.util import DESCENDING, ObjectId -from mediagoblin.util import Pagination ################### # Custom validators @@ -109,24 +108,13 @@ class MediaEntry(Document): migration_handler = migrations.MediaEntryMigration + def get_comments(self): + return self.db.MediaComment.find({ + 'media_entry': self['_id']}).sort('created', DESCENDING) + def main_mediafile(self): pass - - def get_comments(self, page): - cursor = self.db.MediaComment.find({ - 'media_entry': self['_id']}).sort('created', DESCENDING) - - pagination = Pagination(page, cursor) - comments = pagination() - - data = list() - for comment in comments: - comment['author'] = self.db.User.find_one({ - '_id': comment['author']}) - data.append(comment) - - return (data, pagination) - + def generate_slug(self): self['slug'] = util.slugify(self['title']) diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index a9071495..5a7aa4bd 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -17,6 +17,7 @@ from webob import exc +from mediagoblin import messages from mediagoblin.util import render_to_response, redirect, clean_html from mediagoblin.edit import forms from mediagoblin.edit.lib import may_edit_media @@ -83,7 +84,10 @@ def edit_profile(request): user['bio'] = request.POST['bio'] user.save() - return redirect(request, "index", user=user['username']) + messages.add_message(request, + messages.SUCCESS, + 'Profile edited!') + return redirect(request, "mediagoblin.edit.profile") return render_to_response( request, diff --git a/mediagoblin/templates/mediagoblin/media_details.html b/mediagoblin/init/__init__.py index 0e907616..b8ed2456 100644 --- a/mediagoblin/templates/mediagoblin/media_details.html +++ b/mediagoblin/init/__init__.py @@ -1,4 +1,3 @@ -{# # GNU MediaGoblin -- federated, autonomous media hosting # Copyright (C) 2011 Free Software Foundation, Inc # @@ -14,24 +13,21 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -#} -{% extends "mediagoblin/base.html" %} -{% block mediagoblin_content %} - {# temporarily, an "image gallery" that isn't one really ;) #} - {% if media %} - <div class="grid_8 alpha media_image"> - <img src="{{ request.app.public_store.file_url( - media.media_files.main) }}" /> - <h1>Media details for {{media.title}}</h1> - <p> - <br/>Uploaded: {{ media.created}} - <br/>Description: {{media.description}} - </p> - </div> - <div class="grid_4 omega sidebar"> - <p>Uploaded: {{ media.created}}</p> - </div> - {% else %} - <p>Sorry, no such media found.<p/> - {% endif %} -{% endblock %} + +import jinja2 + + +def get_jinja_loader(user_template_path=None): + """ + Set up the Jinja template loaders, possibly allowing for user + overridden templates. + + (In the future we may have another system for providing theming; + for now this is good enough.) + """ + if user_template_path: + return jinja2.ChoiceLoader( + [jinja2.FileSystemLoader(user_template_path), + jinja2.PackageLoader('mediagoblin', 'templates')]) + else: + return jinja2.PackageLoader('mediagoblin', 'templates') diff --git a/mediagoblin/celery_setup/__init__.py b/mediagoblin/init/celery/__init__.py index e35dbce2..67c3dfa0 100644 --- a/mediagoblin/celery_setup/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -20,7 +20,7 @@ import sys MANDATORY_CELERY_IMPORTS = ['mediagoblin.process_media'] -DEFAULT_SETTINGS_MODULE = 'mediagoblin.celery_setup.dummy_settings_module' +DEFAULT_SETTINGS_MODULE = 'mediagoblin.init.celery.dummy_settings_module' def setup_celery_from_config(app_config, global_config, diff --git a/mediagoblin/celery_setup/dummy_settings_module.py b/mediagoblin/init/celery/dummy_settings_module.py index e69de29b..e69de29b 100644 --- a/mediagoblin/celery_setup/dummy_settings_module.py +++ b/mediagoblin/init/celery/dummy_settings_module.py diff --git a/mediagoblin/celery_setup/from_celery.py b/mediagoblin/init/celery/from_celery.py index ed0a409e..c053591b 100644 --- a/mediagoblin/celery_setup/from_celery.py +++ b/mediagoblin/init/celery/from_celery.py @@ -17,7 +17,7 @@ import os from mediagoblin import app, mg_globals -from mediagoblin.celery_setup import setup_celery_from_config +from mediagoblin.init.celery import setup_celery_from_config OUR_MODULENAME = __name__ diff --git a/mediagoblin/celery_setup/from_tests.py b/mediagoblin/init/celery/from_tests.py index 779ecd65..b2293e2c 100644 --- a/mediagoblin/celery_setup/from_tests.py +++ b/mediagoblin/init/celery/from_tests.py @@ -17,7 +17,7 @@ import os from mediagoblin.tests.tools import TEST_APP_CONFIG -from mediagoblin.celery_setup.from_celery import setup_self +from mediagoblin.init.celery.from_celery import setup_self OUR_MODULENAME = __name__ diff --git a/mediagoblin/config.py b/mediagoblin/init/config.py index 2f93d32c..2f93d32c 100644 --- a/mediagoblin/config.py +++ b/mediagoblin/init/config.py diff --git a/mediagoblin/static/css/base.css b/mediagoblin/static/css/base.css index 31573820..3b2a9a50 100644 --- a/mediagoblin/static/css/base.css +++ b/mediagoblin/static/css/base.css @@ -133,15 +133,6 @@ a.mediagoblin_logo:hover { /* common website elements */ -.dotted_line { - width:100%; - height:0px; - border-bottom: dotted 1px #5f5f5f; - position:absolute; - left:0px; - margin-top:-20px; -} - .button { font-family:'Carter One', arial, serif; height:32px; @@ -164,6 +155,10 @@ a.mediagoblin_logo:hover { padding-right:11px; } +.pagination{ +text-align:center; +} + /* forms */ .form_box { @@ -223,6 +218,17 @@ a.mediagoblin_logo:hover { width:280px; } +/* comments */ + +.comment_author { + margin-bottom:40px; + padding-top:4px; +} + +.comment_content p { + margin-bottom:4px; +} + /* media galleries */ ul.media_thumbnail { @@ -240,3 +246,10 @@ li.media_thumbnail { zoom:1; . *display:inline; } + +/* icons */ + +img.media_icon{ + margin:0 4px; + vertical-align:sub; +} diff --git a/mediagoblin/static/images/icon_delete.png b/mediagoblin/static/images/icon_delete.png Binary files differnew file mode 100644 index 00000000..9d76a5db --- /dev/null +++ b/mediagoblin/static/images/icon_delete.png diff --git a/mediagoblin/static/images/icon_edit.png b/mediagoblin/static/images/icon_edit.png Binary files differnew file mode 100644 index 00000000..480c73ad --- /dev/null +++ b/mediagoblin/static/images/icon_edit.png diff --git a/mediagoblin/static/images/icon_feed.png b/mediagoblin/static/images/icon_feed.png Binary files differnew file mode 100644 index 00000000..11e5b1e7 --- /dev/null +++ b/mediagoblin/static/images/icon_feed.png diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index e16f1e00..0c13f5c4 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -20,12 +20,8 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% block mediagoblin_content %} - {# temporarily, an "image gallery" that isn't one really ;) #} {% if media %} <div class="grid_8 alpha media_image"> - <h1> - {{media.title}} - </h1> {% if media.media_files.medium %} <img class="media_image" src="{{ request.app.public_store.file_url( media.media_files.medium) }}" /> @@ -33,76 +29,86 @@ <img class="media_image" src="{{ request.app.public_store.file_url( media.media_files.main) }}" /> {% endif %} + + <h2> + {{media.title}} + </h2> + + {% autoescape False %} + <p>{{ media.description_html }}</p> + {% endautoescape %} + <p> - Uploaded on + — uploaded on {{ "%4d-%02d-%02d"|format(media.created.year, media.created.month, media.created.day) }} by <a href="{{ request.urlgen('mediagoblin.user_pages.user_home', user= media.uploader().username) }}"> {{- media.uploader().username }}</a> - </p> - - {% autoescape False %} - <p>{{ media.description_html }}</p> - {% endautoescape %} + </p> + <br /><br /> - {% if media['uploader'] == request.user['_id'] %} - <p><a href="{{ request.urlgen('mediagoblin.edit.edit_media', - user= media.uploader().username, - media= media._id) }}">Edit</a></p> - {% endif %} + <h3>Comments</h3> {% if request.user %} <form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment', user= media.uploader().username, media=media._id) }}" method="POST"> - <h3>Post a comment!</h3> {{ wtforms_util.render_field_div(comment_form.comment) }} <div class="form_submit_buttons"> - <input type="submit" value="Submit" class="button" /> + <input type="submit" value="Post comment!" class="button" /> </div> </form> {% endif %} - {# - {{ wtforms_util.render_textarea_div(submit_form.description) }} - {{ wtforms_util.render_field_div(submit_form.file) }} - #} - {% if comments %} - <h3>Comments</h3> {% for comment in comments %} + {% set comment_author = comment.author() %} <div class="comment_wrapper" id="comment-{{ comment['_id'] }}"> - <div class="comment_author">By: - <a href="{{ request.urlgen('mediagoblin.user_pages.user_home', - user = comment['author']['username']) }}"> - {{ comment['author']['username'] }} - </a> - </div> - <div class="comment_datetime"> - <a href="#comment-{{ comment['_id'] }}"> - {{ "%4d-%02d-%02d %02d:%02d"|format(comment.created.year, - comment.created.month, - comment.created.day, - comment.created.hour, - comment.created.minute) }} - </a> - </div> <div class="comment_content"> {% autoescape False %} {{ comment.content_html }} {% endautoescape %} - </div> - </div> + </div> + <div class="comment_author">— + <a href="{{ request.urlgen('mediagoblin.user_pages.user_home', + user = comment_author['username']) }}"> + {{ comment_author['username'] }}</a> at + <!--</div> + <div class="comment_datetime">--> + <a href="#comment-{{ comment['_id'] }}"> + {{ "%4d-%02d-%02d %02d:%02d"|format(comment.created.year, + comment.created.month, + comment.created.day, + comment.created.hour, + comment.created.minute) }} + </a> + </div> + </div> {% endfor %} + {% include "mediagoblin/utils/pagination.html" %} </div> {% endif %} - <div class="grid_4 omega media_sidebar"> - <p>This is a sidebar! Yay!</p> + <h3>Sidebar content here!</h3> + <p> + {% if media['uploader'] == request.user['_id'] %} + <p> + <a href="{{ request.urlgen('mediagoblin.edit.edit_media', + user= media.uploader().username, + media= media._id) }}" + ><img src="{{ request.staticdirect('/images/icon_edit.png') }}" + class="media_icon" />edit</a> + </p> + <p> + <img src="{{ request.staticdirect('/images/icon_delete.png') }}" + class="media_icon" />delete + </p> + {% endif %} + </p> </div> {% else %} - <p>Sorry, no such media found.<p/> + <p>Sorry, no such media found.<p/> {% endif %} {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/utils/pagination.html b/mediagoblin/templates/mediagoblin/utils/pagination.html index 2be0b92e..7b55b81d 100644 --- a/mediagoblin/templates/mediagoblin/utils/pagination.html +++ b/mediagoblin/templates/mediagoblin/utils/pagination.html @@ -17,19 +17,19 @@ {# only display if {{pagination}} is defined #} -{% if pagination %} +{% if pagination and pagination.pages > 1 %} <div class="pagination"> - + <p> {% if pagination.has_prev %} - <a href="{{ pagination.get_page_url(request, pagination.page-1) }}">« Prev</> + <a href="{{ pagination.get_page_url(request, pagination.page-1) }}">« Prev</a> {% endif %} {%- for page in pagination.iter_pages() %} {% if page %} {% if page != pagination.page %} - <a href="{{ pagination.get_page_url(request, page) }}">{{ page }}</a> + <a href="{{ pagination.get_page_url(request, page) }}">{{ page }}</a> {% else %} - <strong>{{ page }}</strong> + {{ page }} {% endif %} {% else %} <span class="ellipsis">…</span> @@ -39,6 +39,7 @@ {% if pagination.has_next %} <a href="{{ pagination.get_page_url(request, pagination.page + 1) }}">Next »</a> {% endif %} + </p> </div> {% endif %} diff --git a/mediagoblin/tests/test_celery_setup.py b/mediagoblin/tests/test_celery_setup.py index 8bf97ae4..b80cab49 100644 --- a/mediagoblin/tests/test_celery_setup.py +++ b/mediagoblin/tests/test_celery_setup.py @@ -16,8 +16,8 @@ import pkg_resources -from mediagoblin import celery_setup -from mediagoblin.config import read_mediagoblin_config +from mediagoblin.init import celery as celery_setup +from mediagoblin.init.config import read_mediagoblin_config TEST_CELERY_CONF_NOSPECIALDB = pkg_resources.resource_filename( diff --git a/mediagoblin/tests/test_config.py b/mediagoblin/tests/test_config.py index 244f05e5..f9f12072 100644 --- a/mediagoblin/tests/test_config.py +++ b/mediagoblin/tests/test_config.py @@ -16,7 +16,7 @@ import pkg_resources -from mediagoblin import config +from mediagoblin.init import config CARROT_CONF_GOOD = pkg_resources.resource_filename( diff --git a/mediagoblin/tests/test_mgoblin_app.ini b/mediagoblin/tests/test_mgoblin_app.ini index e022d47b..fd0f87a4 100644 --- a/mediagoblin/tests/test_mgoblin_app.ini +++ b/mediagoblin/tests/test_mgoblin_app.ini @@ -8,7 +8,7 @@ email_debug_mode = true db_name = __mediagoblin_tests__ # Celery shouldn't be set up by the application as it's setup via -# mediagoblin.celery_setup.from_celery +# mediagoblin.init.celery.from_celery celery_setup_elsewhere = true [celery] diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index 64f773f0..e56af4de 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -22,7 +22,7 @@ from paste.deploy import loadapp from webtest import TestApp from mediagoblin import util -from mediagoblin.config import read_mediagoblin_config +from mediagoblin.init.config import read_mediagoblin_config from mediagoblin.decorators import _make_safe from mediagoblin.db.open import setup_connection_and_db_from_config @@ -42,8 +42,8 @@ USER_DEV_DIRECTORIES_TO_SETUP = [ BAD_CELERY_MESSAGE = """\ Sorry, you *absolutely* must run nosetests with the -mediagoblin.celery_setup.from_tests module. Like so: -$ CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests""" +mediagoblin.init.celery.from_tests module. Like so: +$ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests ./bin/nosetests""" class BadCeleryEnviron(Exception): pass @@ -51,7 +51,7 @@ class BadCeleryEnviron(Exception): pass def suicide_if_bad_celery_environ(): if not os.environ.get('CELERY_CONFIG_MODULE') == \ - 'mediagoblin.celery_setup.from_tests': + 'mediagoblin.init.celery.from_tests': raise BadCeleryEnviron(BAD_CELERY_MESSAGE) @@ -59,7 +59,7 @@ def get_test_app(dump_old_app=True): suicide_if_bad_celery_environ() # Leave this imported as it sets up celery. - from mediagoblin.celery_setup import from_tests + from mediagoblin.init.celery import from_tests global MGOBLIN_APP diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 399d2020..012d27a3 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -82,17 +82,19 @@ def user_gallery(request, page): 'media_entries': media_entries, 'pagination': pagination}) +MEDIA_COMMENTS_PER_PAGE = 50 @get_user_media_entry @uses_pagination -def media_home(request, media, **kwargs): +def media_home(request, media, page, **kwargs): """ 'Homepage' of a MediaEntry() """ - comment_form = user_forms.MediaCommentForm(request.POST) + pagination = Pagination(page, media.get_comments(), MEDIA_COMMENTS_PER_PAGE) + comments = pagination() - (comments, pagination) = media.get_comments(kwargs.get('page')) + comment_form = user_forms.MediaCommentForm(request.POST) return render_to_response( request, diff --git a/mediagoblin/util.py b/mediagoblin/util.py index a20e87c4..ab219df0 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -64,22 +64,6 @@ def clear_test_buckets(): clear_test_template_context() -def get_jinja_loader(user_template_path=None): - """ - Set up the Jinja template loaders, possibly allowing for user - overridden templates. - - (In the future we may have another system for providing theming; - for now this is good enough.) - """ - if user_template_path: - return jinja2.ChoiceLoader( - [jinja2.FileSystemLoader(user_template_path), - jinja2.PackageLoader('mediagoblin', 'templates')]) - else: - return jinja2.PackageLoader('mediagoblin', 'templates') - - SETUP_JINJA_ENVS = {} diff --git a/runtests.sh b/runtests.sh index 9b96b17c..1dfbf093 100755 --- a/runtests.sh +++ b/runtests.sh @@ -27,4 +27,4 @@ else exit 1 fi -CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests $NOSETESTS $@ +CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests $NOSETESTS $@ |