diff options
41 files changed, 1006 insertions, 170 deletions
diff --git a/docs/git.rst b/docs/git.rst index c3f7ccce..73e7a311 100644 --- a/docs/git.rst +++ b/docs/git.rst @@ -80,10 +80,10 @@ doing and why. How to send us your changes --------------------------- -There are three ways to let us know how to get it: +There are two ways to let us know how to get it: -1. (preferred) **push changes to publicly available git clone and let - us know where to find it** +1. *(preferred)* **push changes to publicly available git clone and + let us know where to find it** Push your feature/bugfix/issue branch to your publicly available git clone and add a comment to the issue with the url for your @@ -93,14 +93,22 @@ There are three ways to let us know how to get it: Run:: - git format-patch -o patches <remote>/master + git format-patch --stdout <remote>/master > issue_<number>.patch - Then tar up the newly created ``patches`` directory and attach the - directory to the issue. + ``format-patch`` creates a patch of all the commits that are in + your branch that aren't in ``<remote>/master``. The ``--stdout`` + flag causes all this output to go to stdout where it's redirected + to a file named ``issue_<number>.patch``. That file should be + based on the issue you're working with. For example, + ``issue_42.patch`` is a good filename and ``issue_42_rev2.patch`` + is good if you did a revision of it. + + Having said all that, the filename isn't wildly important. Example workflow ================ + Here's an example workflow. @@ -108,8 +116,8 @@ Contributing changes -------------------- Slartibartfast from the planet Magrathea far off in the universe has -decided that he is bored with fjords and wants to fix issue 42 and -send us the changes. +decided that he is bored with fjords and wants to fix issue 42 (the +meaning of life bug) and send us the changes. Slartibartfast has cloned the MediaGoblin repository and his clone lives on gitorious. @@ -124,19 +132,29 @@ Slartibartfast does the following: git fetch --all -p + This tells ``git fetch`` to fetch all the recent data from all of + the remotes (``--all``) and prune any branches that have been + deleted in the remotes (``-p``). + 2. Creates a branch from the tip of the MediaGoblin repository (the - remote is named ``gmg``) master branch called ``issue_42``:: + remote is named ``gmg``) master branch called ``bug42_meaning_of_life``:: - git checkout -b issue_42 gmg/master + git checkout -b bug42_meaning_of_life gmg/master -3. Slartibartfast works hard on his changes in the ``issue_42`` + This creates a new branch (``-b``) named ``bug42_meaning_of_life`` based + on the tip of the ``master`` branch of the remote named ``gmg`` and checks + it out. + +3. Slartibartfast works hard on his changes in the ``bug42_meaning_of_life`` branch. When done, he wants to notify us that he has made changes he wants us to see. -4. Slartibartfast pushes his changes to his clone (the remote is named - ``origin``):: +4. Slartibartfast pushes his changes to his clone:: + + git push origin bug42_meaning_of_life --set-upstream - git push origin issue_42 --set-upstream + This pushes the changes in the ``bug42_meaning_of_life`` branch to the + remote named ``origin``. 5. Slartibartfast adds a comment to issue 42 with the url for his repository and the name of the branch he put the code in. He also @@ -155,19 +173,19 @@ He runs the unit tests and discovers there's a bug in the code! Then he does this: -1. He checks out the ``issue_42`` branch:: +1. He checks out the ``bug42_meaning_of_life`` branch:: - git checkout issue_42 + git checkout bug42_meaning_of_life -2. He fixes the bug and checks it into the ``issue_42`` branch. +2. He fixes the bug and checks it into the ``bug42_meaning_of_life`` branch. 3. He pushes his changes to his clone (the remote is named ``origin``):: - git push origin issue_42 + git push origin bug42_meaning_of_life 4. He adds another comment to issue 42 explaining about the mistake and how he fixed it and that he's pushed the new change to the - ``issue_42`` branch of his publicly available clone. + ``bug42_meaning_of_life`` branch of his publicly available clone. What happens next @@ -180,7 +198,7 @@ request with his changes and explains what they are. Later, someone checks out his code and finds a problem with it. He adds a comment to the issue tracker specifying the problem and asks Slartibartfast to fix it. Slartibartfst goes through the above steps -again, fixes the issue, pushes it to his ``issue_42`` branch and adds +again, fixes the issue, pushes it to his ``bug42_meaning_of_life`` branch and adds another comment to the issue tracker about how he fixed it. Later, someone checks out his code and is happy with it. Someone @@ -192,8 +210,8 @@ Slartibartfast is notified of this. Slartibartfast does a:: git fetch --all The changes show up in the ``master`` branch of the ``gmg`` remote. -Slartibartfast now deletes his ``issue_42`` branch because he doesn't -need it anymore. +Slartibartfast now deletes his ``bug42_meaning_of_life`` branch +because he doesn't need it anymore. How to learn git diff --git a/docs/hackinghowto.rst b/docs/hackinghowto.rst index fcab5844..911f2340 100644 --- a/docs/hackinghowto.rst +++ b/docs/hackinghowto.rst @@ -136,7 +136,7 @@ This is fine in development, but if you want to actually run celery separately for testing (or deployment purposes), you'll want to run the server independently:: - ./bin/paster serve server.ini --reload + ./bin/paster serve paste.ini --reload Running celeryd @@ -158,7 +158,7 @@ Running the test suite Run:: - ./bin/nosetests + ./runtests.sh Running a shell diff --git a/docs/mediagoblin.rst b/docs/mediagoblin.rst index ea9c83a7..c437ecc3 100644 --- a/docs/mediagoblin.rst +++ b/docs/mediagoblin.rst @@ -2,6 +2,10 @@ GNU MediaGoblin ================= +.. contents:: Sections + :local: + + What is GNU MediaGoblin ======================= diff --git a/lazyserver.sh b/lazyserver.sh index bd93b109..fdb03ba0 100755 --- a/lazyserver.sh +++ b/lazyserver.sh @@ -27,4 +27,4 @@ else exit 1 fi -CELERY_ALWAYS_EAGER=true $PASTER serve server.ini --reload +CELERY_ALWAYS_EAGER=true $PASTER serve paste.ini --reload diff --git a/mediagoblin/contrib/960_12_col.css b/mediagoblin/contrib/960_12_col.css new file mode 100644 index 00000000..48e86ee8 --- /dev/null +++ b/mediagoblin/contrib/960_12_col.css @@ -0,0 +1,357 @@ +/* + 960 Grid System ~ Core CSS. + Learn more ~ http://960.gs/ + + Licensed under GPL and MIT. +*/ + +/* + Forces backgrounds to span full width, + even if there is horizontal scrolling. + Increase this if your layout is wider. + + Note: IE6 works fine without this fix. +*/ + +body { + min-width: 960px; +} + +/* `Container +----------------------------------------------------------------------------------------------------*/ + +.container_12 { + margin-left: auto; + margin-right: auto; + width: 960px; +} + +/* `Grid >> Global +----------------------------------------------------------------------------------------------------*/ + +.grid_1, +.grid_2, +.grid_3, +.grid_4, +.grid_5, +.grid_6, +.grid_7, +.grid_8, +.grid_9, +.grid_10, +.grid_11, +.grid_12 { + display: inline; + float: left; + margin-left: 10px; + margin-right: 10px; +} + +.push_1, .pull_1, +.push_2, .pull_2, +.push_3, .pull_3, +.push_4, .pull_4, +.push_5, .pull_5, +.push_6, .pull_6, +.push_7, .pull_7, +.push_8, .pull_8, +.push_9, .pull_9, +.push_10, .pull_10, +.push_11, .pull_11 { + position: relative; +} + +/* `Grid >> Children (Alpha ~ First, Omega ~ Last) +----------------------------------------------------------------------------------------------------*/ + +.alpha { + margin-left: 0; +} + +.omega { + margin-right: 0; +} + +/* `Grid >> 12 Columns +----------------------------------------------------------------------------------------------------*/ + +.container_12 .grid_1 { + width: 60px; +} + +.container_12 .grid_2 { + width: 140px; +} + +.container_12 .grid_3 { + width: 220px; +} + +.container_12 .grid_4 { + width: 300px; +} + +.container_12 .grid_5 { + width: 380px; +} + +.container_12 .grid_6 { + width: 460px; +} + +.container_12 .grid_7 { + width: 540px; +} + +.container_12 .grid_8 { + width: 620px; +} + +.container_12 .grid_9 { + width: 700px; +} + +.container_12 .grid_10 { + width: 780px; +} + +.container_12 .grid_11 { + width: 860px; +} + +.container_12 .grid_12 { + width: 940px; +} + +/* `Prefix Extra Space >> 12 Columns +----------------------------------------------------------------------------------------------------*/ + +.container_12 .prefix_1 { + padding-left: 80px; +} + +.container_12 .prefix_2 { + padding-left: 160px; +} + +.container_12 .prefix_3 { + padding-left: 240px; +} + +.container_12 .prefix_4 { + padding-left: 320px; +} + +.container_12 .prefix_5 { + padding-left: 400px; +} + +.container_12 .prefix_6 { + padding-left: 480px; +} + +.container_12 .prefix_7 { + padding-left: 560px; +} + +.container_12 .prefix_8 { + padding-left: 640px; +} + +.container_12 .prefix_9 { + padding-left: 720px; +} + +.container_12 .prefix_10 { + padding-left: 800px; +} + +.container_12 .prefix_11 { + padding-left: 880px; +} + +/* `Suffix Extra Space >> 12 Columns +----------------------------------------------------------------------------------------------------*/ + +.container_12 .suffix_1 { + padding-right: 80px; +} + +.container_12 .suffix_2 { + padding-right: 160px; +} + +.container_12 .suffix_3 { + padding-right: 240px; +} + +.container_12 .suffix_4 { + padding-right: 320px; +} + +.container_12 .suffix_5 { + padding-right: 400px; +} + +.container_12 .suffix_6 { + padding-right: 480px; +} + +.container_12 .suffix_7 { + padding-right: 560px; +} + +.container_12 .suffix_8 { + padding-right: 640px; +} + +.container_12 .suffix_9 { + padding-right: 720px; +} + +.container_12 .suffix_10 { + padding-right: 800px; +} + +.container_12 .suffix_11 { + padding-right: 880px; +} + +/* `Push Space >> 12 Columns +----------------------------------------------------------------------------------------------------*/ + +.container_12 .push_1 { + left: 80px; +} + +.container_12 .push_2 { + left: 160px; +} + +.container_12 .push_3 { + left: 240px; +} + +.container_12 .push_4 { + left: 320px; +} + +.container_12 .push_5 { + left: 400px; +} + +.container_12 .push_6 { + left: 480px; +} + +.container_12 .push_7 { + left: 560px; +} + +.container_12 .push_8 { + left: 640px; +} + +.container_12 .push_9 { + left: 720px; +} + +.container_12 .push_10 { + left: 800px; +} + +.container_12 .push_11 { + left: 880px; +} + +/* `Pull Space >> 12 Columns +----------------------------------------------------------------------------------------------------*/ + +.container_12 .pull_1 { + left: -80px; +} + +.container_12 .pull_2 { + left: -160px; +} + +.container_12 .pull_3 { + left: -240px; +} + +.container_12 .pull_4 { + left: -320px; +} + +.container_12 .pull_5 { + left: -400px; +} + +.container_12 .pull_6 { + left: -480px; +} + +.container_12 .pull_7 { + left: -560px; +} + +.container_12 .pull_8 { + left: -640px; +} + +.container_12 .pull_9 { + left: -720px; +} + +.container_12 .pull_10 { + left: -800px; +} + +.container_12 .pull_11 { + left: -880px; +} + +/* `Clear Floated Elements +----------------------------------------------------------------------------------------------------*/ + +/* http://sonspring.com/journal/clearing-floats */ + +.clear { + clear: both; + display: block; + overflow: hidden; + visibility: hidden; + width: 0; + height: 0; +} + +/* http://www.yuiblog.com/blog/2010/09/27/clearfix-reloaded-overflowhidden-demystified */ + +.clearfix:before, +.clearfix:after, +.container_12:before, +.container_12:after { + content: '.'; + display: block; + overflow: hidden; + visibility: hidden; + font-size: 0; + line-height: 0; + width: 0; + height: 0; +} + +.clearfix:after, +.container_12:after { + clear: both; +} + +/* + The following zoom:1 rule is specifically for IE6 + IE7. + Move to separate stylesheet if invalid CSS is a problem. +*/ + +.clearfix, +.container_12 { + zoom: 1; +}
\ No newline at end of file diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index f1f625b7..712f8ab4 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -14,6 +14,8 @@ # 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/>. +from mediagoblin.util import cleaned_markdown_conversion + from mongokit import DocumentMigration @@ -33,5 +35,35 @@ class MediaEntryMigration(DocumentMigration): self.collection.update( self.target, self.update, multi=True, safe=True) + def allmigration02_add_description_html(self): + """ + Now that we can have rich descriptions via Markdown, we should + update all existing entries to record the rich description versions. + """ + self.target = {'description_html': {'$exists': False}, + 'description': {'$exists': True}} -MIGRATE_CLASSES = ['MediaEntry'] + if not self.status: + for doc in self.collection.find(self.target): + self.update = { + '$set': { + 'description_html': cleaned_markdown_conversion( + doc['description'])}} + +class UserMigration(DocumentMigration): + def allmigration01_add_bio_and_url_profile(self): + """ + User can elaborate profile with home page and biography + """ + self.target = {'url': {'$exists': False}, + 'bio': {'$exists': False}} + if not self.status: + for doc in self.collection.find(self.target): + self.update = { + '$set': {'url': '', + 'bio': ''}} + self.collection.update( + self.target, self.update, multi=True, safe=True) + + +MIGRATE_CLASSES = ['MediaEntry', 'User'] diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index d77cf619..600b79ff 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -46,6 +46,8 @@ class User(Document): 'status': unicode, 'verification_key': unicode, 'is_admin': bool, + 'url' : unicode, + 'bio' : unicode } required_fields = ['username', 'created', 'pw_hash', 'email'] @@ -56,6 +58,8 @@ class User(Document): 'status': u'needs_email_verification', 'verification_key': lambda: unicode(uuid.uuid4()), 'is_admin': False} + + migration_handler = migrations.UserMigration def check_login(self, password): """ @@ -73,7 +77,8 @@ class MediaEntry(Document): 'title': unicode, 'slug': unicode, 'created': datetime.datetime, - 'description': unicode, + '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. diff --git a/mediagoblin/db/util.py b/mediagoblin/db/util.py index 30615fca..470da531 100644 --- a/mediagoblin/db/util.py +++ b/mediagoblin/db/util.py @@ -17,4 +17,5 @@ # Imports that other modules might use from pymongo import DESCENDING +from pymongo.errors import InvalidId from mongokit import ObjectId diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index c2fe3f9f..081eda62 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -15,11 +15,10 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -from bson.errors import InvalidId from webob import exc from mediagoblin.util import redirect -from mediagoblin.db.util import ObjectId +from mediagoblin.db.util import ObjectId, InvalidId def _make_safe(decorator, original): diff --git a/mediagoblin/edit/forms.py b/mediagoblin/edit/forms.py index ea25141d..2efdb9e4 100644 --- a/mediagoblin/edit/forms.py +++ b/mediagoblin/edit/forms.py @@ -25,3 +25,10 @@ class EditForm(wtforms.Form): slug = wtforms.TextField( 'Slug') description = wtforms.TextAreaField('Description of this work') + +class EditProfileForm(wtforms.Form): + bio = wtforms.TextAreaField('Bio', + [wtforms.validators.Length(min=0, max=500)]) + url = wtforms.TextField( + 'Website', + [wtforms.validators.URL(message='Improperly formed URL')]) diff --git a/mediagoblin/edit/routing.py b/mediagoblin/edit/routing.py index bf0b2498..9771207a 100644 --- a/mediagoblin/edit/routing.py +++ b/mediagoblin/edit/routing.py @@ -19,4 +19,5 @@ from routes.route import Route edit_routes = [ # Media editing view handled in user_pages/routing.py -] + Route('mediagoblin.edit.profile', '/profile/', + controller="mediagoblin.edit.views:edit_profile")] diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index c5f0f435..a9071495 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -17,11 +17,13 @@ from webob import exc -from mediagoblin.util import render_to_response, redirect +from mediagoblin.util import render_to_response, redirect, clean_html from mediagoblin.edit import forms from mediagoblin.edit.lib import may_edit_media from mediagoblin.decorators import require_active_login, get_user_media_entry +import markdown + @get_user_media_entry @require_active_login @@ -47,7 +49,14 @@ def edit_media(request, media): u'An entry with that slug already exists for this user.') else: media['title'] = request.POST['title'] - media['description'] = request.POST['description'] + media['description'] = request.POST.get('description') + + md = markdown.Markdown( + safe_mode = 'escape') + media['description_html'] = clean_html( + md.convert( + media['description'])) + media['slug'] = request.POST['slug'] media.save() @@ -59,3 +68,25 @@ def edit_media(request, media): 'mediagoblin/edit/edit.html', {'media': media, 'form': form}) + + +@require_active_login +def edit_profile(request): + + user = request.user + form = forms.EditProfileForm(request.POST, + url = user.get('url'), + bio = user.get('bio')) + + if request.method == 'POST' and form.validate(): + user['url'] = request.POST['url'] + user['bio'] = request.POST['bio'] + user.save() + + return redirect(request, "index", user=user['username']) + + return render_to_response( + request, + 'mediagoblin/edit/edit_profile.html', + {'user': user, + 'form': form}) diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py index d1f7bfc1..0cb4d3a2 100644 --- a/mediagoblin/gmg_commands/__init__.py +++ b/mediagoblin/gmg_commands/__init__.py @@ -28,6 +28,18 @@ 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':{ + 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup', + 'func': 'mediagoblin.gmg_commands.users:adduser', + 'help': 'Creates an user'}, + 'makeadmin': { + 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup', + 'func': 'mediagoblin.gmg_commands.users:makeadmin', + 'help': 'Changes a user\'s password'}, + 'changepw': { + 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup', + 'func': 'mediagoblin.gmg_commands.users:changepw', + 'help': 'Makes admin an user'}, } @@ -56,3 +68,4 @@ def main_cli(): if __name__ == '__main__': main_cli() + diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py new file mode 100644 index 00000000..b4a6bbc1 --- /dev/null +++ b/mediagoblin/gmg_commands/users.py @@ -0,0 +1,94 @@ +from mediagoblin.gmg_commands import util as commands_util +from mediagoblin.auth import lib as auth_lib +from mediagoblin import mg_globals + + +def adduser_parser_setup(subparser): + subparser.add_argument( + 'username', + help="Username used to login") + subparser.add_argument( + 'password', + help="Your supersecret word to login") + subparser.add_argument( + 'email', + help="Email to recieve notifications") + subparser.add_argument( + '-cf', '--conf_file', default='mediagoblin.ini', + help="Config file used to set up environment") + + +def adduser(args): + #TODO: Lets trust admins this do not validate Emails :) + commands_util.setup_app(args) + + db = mg_globals.database + users_with_username = \ + db.User.find({ + 'username': args.username.lower() + }).count() + + if users_with_username: + print u'Sorry, a user with that name already exists.' + + else: + # Create the user + entry = db.User() + entry['username'] = unicode(args.username.lower()) + entry['email'] = unicode(args.email) + entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash(args.password) + entry['status'] = u'active' + entry['email_verified'] = True + entry.save(validate=True) + + print "User created (and email marked as verified)" + + +def makeadmin_parser_setup(subparser): + subparser.add_argument( + 'username', + help="Username to give admin level") + subparser.add_argument( + '-cf', '--conf_file', default='mediagoblin.ini', + help="Config file used to set up environment") + + +def makeadmin(args): + commands_util.setup_app(args) + + db = mg_globals.database + + user = db.User.one({'username':unicode(args.username.lower())}) + if user: + user['is_admin'] = True + user.save() + print 'The user is now Admin' + else: + print 'The user doesn\'t exist' + + +def changepw_parser_setup(subparser): + subparser.add_argument( + 'username', + help="Username used to login") + subparser.add_argument( + 'password', + help="Your NEW supersecret word to login") + subparser.add_argument( + '-cf', '--conf_file', default='mediagoblin.ini', + help="Config file used to set up environment") + + +def changepw(args): + commands_util.setup_app(args) + + db = mg_globals.database + + 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/static/css/base.css b/mediagoblin/static/css/base.css index 5d928b9a..0a659bb4 100644 --- a/mediagoblin/static/css/base.css +++ b/mediagoblin/static/css/base.css @@ -4,6 +4,12 @@ body { font-family: sans-serif; padding:none; margin:0px; + height:100%; +} + +form { + margin:0px; + padding:0px; } /* Carter One font */ @@ -38,6 +44,11 @@ label { /* website structure */ +.mediagoblin_body { + position:relative; + min-height:100%; +} + .mediagoblin_header { width:100%; height:36px; @@ -46,6 +57,22 @@ label { margin-bottom:40px; } +.mediagoblin_footer { + width:100%; + height:26px; + background-color:#393939; + bottom:0px; + padding-top:8px; + position:absolute; + text-align:center; + font-size:14px; + color:#999; +} + +.mediagoblin_content { + padding-bottom:74px; +} + a.mediagoblin_logo { width:34px; height:25px; @@ -59,66 +86,68 @@ a.mediagoblin_logo:hover { background-position:0px -28px; } -.mediagoblin_container { - width: 960px; - margin-left: auto; - margin-right: auto; -} - .mediagoblin_header_right { float:right; } +/* 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; min-width:99px; background-color:#86d4b1; + background-image: -webkit-gradient(linear, left top, left bottom, from(#86d4b1), to(#62caa2)); + background-image: -webkit-linear-gradient(top, #86d4b1, #62caa2); + background-image: -moz-linear-gradient(top, #86d4b1, #62caa2); + background-image: -ms-linear-gradient(top, #86d4b1, #62caa2); + background-image: -o-linear-gradient(top, #86d4b1, #62caa2); + background-image: linear-gradient(top, #86d4b1, #62caa2); box-shadow:0px 0px 4px #000; border-radius:5px; border:none; color:#272727; - margin:10px; + margin:10px 0px 10px 15px; font-size:1em; - display:block; text-align:center; padding-left:11px; padding-right:11px; } -/* common website elements */ - -.dotted_line { - width:100%; - height:0px; - border-bottom: dotted 1px #5f5f5f; - position:absolute; - left:0px; - margin-top:-20px; -} - /* forms */ .form_box { - width:300px; - margin-left:auto; - margin-right:auto; background-color:#393939; - padding:0px 83px 30px 83px; - border-top:5px solid #d49086; + background-image:url("../images/background_lines.png"); + background-repeat:repeat-x; font-size:18px; + padding-bottom:30px; + padding-top:1px; + margin-left:auto; + margin-right:auto; + display:block; + float:none; } -.submit_box { - width:600px; +.edit_box { + background-image:url("../images/background_edit.png"); } .form_box h1 { font-size:28px; } -.form_field_input input { - width:300px; +.form_field_input input, .form_field_input textarea { + width:100%; font-size:18px; } @@ -139,6 +168,10 @@ a.mediagoblin_logo:hover { margin-bottom:8px; } +.form_submit_buttons { + text-align:right; +} + /* media pages */ img.media_image { @@ -147,14 +180,17 @@ img.media_image { margin-right:auto; } +ul.media_thumbnail { + padding:0px; +} + li.media_thumbnail { - width: 200px; - min-height: 250px; - display: -moz-inline-stack; - display: inline-block; - vertical-align: top; - margin: 5px; - zoom: 1; - *display: inline; - _height: 250px; + width:200px; + height:200px; + display:-moz-inline-stack; + display:inline-block; + vertical-align:top; + margin:0px 10px 10px 0px; + zoom:1; +. *display:inline; } diff --git a/mediagoblin/static/css/contrib/960_12_col.css b/mediagoblin/static/css/contrib/960_12_col.css new file mode 120000 index 00000000..15c360e4 --- /dev/null +++ b/mediagoblin/static/css/contrib/960_12_col.css @@ -0,0 +1 @@ +../../../contrib/960_12_col.css
\ No newline at end of file diff --git a/mediagoblin/static/images/background_edit.png b/mediagoblin/static/images/background_edit.png Binary files differnew file mode 100644 index 00000000..4071fd53 --- /dev/null +++ b/mediagoblin/static/images/background_edit.png diff --git a/mediagoblin/static/images/background_lines.png b/mediagoblin/static/images/background_lines.png Binary files differnew file mode 100644 index 00000000..e1b07afe --- /dev/null +++ b/mediagoblin/static/images/background_lines.png diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index e9b5c37e..6139614e 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -19,7 +19,8 @@ from cgi import FieldStorage from werkzeug.utils import secure_filename -from mediagoblin.util import render_to_response, redirect +from mediagoblin.util import ( + render_to_response, redirect, cleaned_markdown_conversion) from mediagoblin.decorators import require_active_login from mediagoblin.submit import forms as submit_forms, security from mediagoblin.process_media import process_media_initial @@ -46,8 +47,14 @@ def submit_start(request): # create entry and save in database entry = request.db.MediaEntry() - entry['title'] = request.POST['title'] or unicode(splitext(filename)[0]) + entry['title'] = ( + request.POST['title'] + or unicode(splitext(filename)[0])) + entry['description'] = request.POST.get('description') + entry['description_html'] = cleaned_markdown_conversion( + entry['description']) + entry['media_type'] = u'image' # heh entry['uploader'] = request.user['_id'] diff --git a/mediagoblin/templates/mediagoblin/auth/login.html b/mediagoblin/templates/mediagoblin/auth/login.html index c2e27c15..f6ee7166 100644 --- a/mediagoblin/templates/mediagoblin/auth/login.html +++ b/mediagoblin/templates/mediagoblin/auth/login.html @@ -23,7 +23,7 @@ <form action="{{ request.urlgen('mediagoblin.auth.login') }}" method="POST" enctype="multipart/form-data"> - <div class="login_box form_box"> + <div class="grid_4 prefix_1 suffix_1 form_box"> <h1>Log in</h1> {% if login_failed %} <div class="form_field_error">Login failed!</div> @@ -36,7 +36,7 @@ <input type="hidden" name="next" value="{{ next }}" class="button" style="display: none;"/> {% endif %} - <p>Don't have an account yet? <a href="{{ request.urlgen('mediagoblin.auth.register') }}">Create one here!</a></p> + <p>Don't have an account yet?<br /><a href="{{ request.urlgen('mediagoblin.auth.register') }}">Create one here!</a></p> </div> </form> {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/auth/register.html b/mediagoblin/templates/mediagoblin/auth/register.html index 730d684d..7e18ca58 100644 --- a/mediagoblin/templates/mediagoblin/auth/register.html +++ b/mediagoblin/templates/mediagoblin/auth/register.html @@ -23,7 +23,7 @@ <form action="{{ request.urlgen('mediagoblin.auth.register') }}" method="POST" enctype="multipart/form-data"> - <div class="register_box form_box"> + <div class="grid_4 prefix_1 suffix_1 form_box"> <h1>Create an account!</h1> {{ wtforms_util.render_divs(register_form) }} <div class="form_submit_buttons"> diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index c7313173..63749f68 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -19,6 +19,8 @@ <head> <title>{% block title %}GNU MediaGoblin{% endblock title %}</title> <link rel="stylesheet" type="text/css" + href="{{ request.staticdirect('/css/contrib/960_12_col.css') }}"/> + <link rel="stylesheet" type="text/css" href="{{ request.staticdirect('/css/base.css') }}"/> {% block mediagoblin_head %} {% endblock mediagoblin_head %} @@ -26,30 +28,45 @@ <body> {% block mediagoblin_body %} + <div class="mediagoblin_body"> {% block mediagoblin_header %} <div class="mediagoblin_header"> - <div class="mediagoblin_container"> - {% block mediagoblin_logo %} - <a class="mediagoblin_logo" href="{{ request.urlgen('index') }}"></a> - {% endblock %}{% block mediagoblin_header_title %}{% endblock %} - <div class="mediagoblin_header_right"> - {% if request.user %} - {{ request.user['username'] }}'s account - <a href="{{ request.urlgen('mediagoblin.user_pages.user_gallery', - user= request.user['username']) }}">gallery</a> - (<a href="{{ request.urlgen('mediagoblin.auth.logout') }}">logout</a>) - {% else %} - <a href="{{ request.urlgen('mediagoblin.auth.login') }}"> - Login</a> - {% endif %} + <div class="container_12"> + <div class="grid_12"> + {% block mediagoblin_logo %} + <a class="mediagoblin_logo" href="{{ request.urlgen('index') }}"></a> + {% endblock %}{% block mediagoblin_header_title %}{% endblock %} + <div class="mediagoblin_header_right"> + {% if request.user %} + <a href="{{ request.urlgen('mediagoblin.user_pages.user_home', + user= request.user['username']) }}"> + {{ request.user['username'] }}</a>'s account + (<a href="{{ request.urlgen('mediagoblin.auth.logout') }}">logout</a>) + {% else %} + <a href="{{ request.urlgen('mediagoblin.auth.login') }}"> + Login</a> + {% endif %} + </div> + </div> </div> </div> - </div> {% endblock %} - <div class="mediagoblin_container"> - {% block mediagoblin_content %} - {% endblock mediagoblin_content %} + <div class="container_12 mediagoblin_content"> + <div class="grid_12"> + {% block mediagoblin_content %} + {% endblock mediagoblin_content %} + </div> </div> + {% block mediagoblin_footer %} + <div class="mediagoblin_footer"> + <div class="container_12"> + <div class="grid_12"> + Powered by <a href="http://mediagoblin.org">MediaGoblin</a>, a <a href="http://gnu.org/">GNU project</a> + </div> + </div> + </div> + {% endblock %} {% endblock mediagoblin_body %} + </div> </body> </html> diff --git a/mediagoblin/templates/mediagoblin/edit/edit.html b/mediagoblin/templates/mediagoblin/edit/edit.html index 295d57eb..8ee09bd5 100644 --- a/mediagoblin/templates/mediagoblin/edit/edit.html +++ b/mediagoblin/templates/mediagoblin/edit/edit.html @@ -20,19 +20,23 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% block mediagoblin_content %} - <h1>Edit details for {{ media.title }}</h1> <form action="{{ request.urlgen('mediagoblin.edit.edit_media', user= media.uploader().username, media= media._id) }}" method="POST" enctype="multipart/form-data"> - <div class="submit_box form_box"> + <div class="grid_6 prefix_1 suffix_1 edit_box form_box"> + <h1>Editing {{ media.title }}</h1> + <div style="text-align: center;" > + <img src="{{ request.app.public_store.file_url( + media['media_files']['thumb']) }}" /> + </div> {{ wtforms_util.render_divs(form) }} <div class="form_submit_buttons"> - <input type="submit" value="submit" class="button" /> + <a href="{{ media.url_for_self(request.urlgen) }}">Cancel</a> + <input type="submit" value="Save changes" class="button" /> </div> </div> </form> - <img src="{{ request.app.public_store.file_url( - media['media_files']['thumb']) }}" /> + {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/edit/edit_profile.html b/mediagoblin/templates/mediagoblin/edit/edit_profile.html new file mode 100644 index 00000000..7efd0ee3 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/edit/edit_profile.html @@ -0,0 +1,35 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# 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 <http://www.gnu.org/licenses/>. +#} +{% extends "mediagoblin/base.html" %} + +{% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} + +{% block mediagoblin_content %} + + <form action="{{ request.urlgen('mediagoblin.edit.profile', + user=user.username) }}" + method="POST" enctype="multipart/form-data"> + <div class="grid_6 prefix_1 suffix_1 edit_box form_box"> + <h1>Editing {{ user['username'] }}'s profile</h1> + {{ wtforms_util.render_divs(form) }} + <div class="form_submit_buttons"> + <input type="submit" value="submit" class="button" /> + </div> + </div> + </form> +{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/media_details.html b/mediagoblin/templates/mediagoblin/media_details.html index bd63a289..8cb23e81 100644 --- a/mediagoblin/templates/mediagoblin/media_details.html +++ b/mediagoblin/templates/mediagoblin/media_details.html @@ -17,9 +17,9 @@ #} {% extends "mediagoblin/base.html" %} {% block mediagoblin_content %} - {# temporarily, an "image gallery" that isn't one really ;) #} {% if media %} + <h1>Media details for {{media.title}}</h1> <div> <img src="{{ request.app.public_store.file_url( diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html index e5344e08..e29abd51 100644 --- a/mediagoblin/templates/mediagoblin/root.html +++ b/mediagoblin/templates/mediagoblin/root.html @@ -18,30 +18,25 @@ {% extends "mediagoblin/base.html" %} {% block mediagoblin_content %} - <h1>{% trans %}Welcome to GNU MediaGoblin!{% endtrans %}</h1> {% if request.user %} - <p> - <a href="{{ request.urlgen('mediagoblin.submit.start') }}">Submit an item</a>. - </p> - + <p> + <a href="{{ request.urlgen('mediagoblin.submit.start') }}">Submit an item</a> + <a href="{{ request.urlgen('mediagoblin.edit.profile') }}">Edit profile</a> + </p> {% else %} - <p> - If you have an account, you can - <a href="{{ request.urlgen('mediagoblin.auth.login') }}">Login</a>. - </p> - <p> - If you don't have an account, please - <a href="{{ request.urlgen('mediagoblin.auth.register') }}">Register</a>. - </p> - + <p> + If you have an account, you can + <a href="{{ request.urlgen('mediagoblin.auth.login') }}">Login</a>. + </p> + <p> + If you don't have an account, please + <a href="{{ request.urlgen('mediagoblin.auth.register') }}">Register</a>. + </p> {% endif %} {# temporarily, an "image gallery" that isn't one really ;) #} - <div> {% include "mediagoblin/utils/object_gallery.html" %} - </div> - {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/submit/start.html b/mediagoblin/templates/mediagoblin/submit/start.html index 75c31df4..f34bf2af 100644 --- a/mediagoblin/templates/mediagoblin/submit/start.html +++ b/mediagoblin/templates/mediagoblin/submit/start.html @@ -23,11 +23,13 @@ <form action="{{ request.urlgen('mediagoblin.submit.start') }}" method="POST" enctype="multipart/form-data"> - <div class="submit_box form_box"> + <div class="grid_6 prefix_1 suffix_1 form_box"> <h1>Submit yer media</h1> - {{ wtforms_util.render_divs(submit_form) }} + {{ wtforms_util.render_field_div(submit_form.title) }} + {{ wtforms_util.render_textarea_div(submit_form.description) }} + {{ wtforms_util.render_field_div(submit_form.file) }} <div class="form_submit_buttons"> - <input type="submit" value="submit" class="button" /> + <input type="submit" value="Submit" class="button" /> </div> </div> </form> diff --git a/mediagoblin/templates/mediagoblin/user_pages/gallery.html b/mediagoblin/templates/mediagoblin/user_pages/gallery.html index 6f68a41f..28290cfd 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/gallery.html +++ b/mediagoblin/templates/mediagoblin/user_pages/gallery.html @@ -20,16 +20,16 @@ {% block mediagoblin_head %} <link rel="alternate" type="application/atom+xml" href="{{ request.urlgen( - 'mediagoblin.user_pages.atom_feed', + 'mediagoblin.user_pages.atom_feed', user=user.username) }}"> {% endblock mediagoblin_head %} {% block mediagoblin_content -%} {% if user %} - <h1>gallery for - <a href="{{ request.urlgen( - 'mediagoblin.user_pages.user_home', - user=user.username) }}">{{ user.username }}</a></h1> + <h1> + <a href="{{ request.urlgen( + 'mediagoblin.user_pages.user_home', + user=user.username) }}">{{ user.username }}</a>'s media</h1> {% include "mediagoblin/utils/object_gallery.html" %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index 200f13cd..d221f61e 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -25,17 +25,21 @@ </h1> <img class="media_image" src="{{ request.app.public_store.file_url( media.media_files.main) }}" /> - <p>{{ media.description }}</p> + {% autoescape False %} + <p>{{ media.description_html }}</p> + {% endautoescape %} <p>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> - <p><a href="{{ request.urlgen('mediagoblin.edit.edit_media', - user= media.uploader().username, - media= media._id) }}">Edit</a></p> + {{- media.uploader().username }}</a></p> + {% 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 %} {% else %} <p>Sorry, no such media found.<p/> {% endif %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index b3708c85..99e46a72 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -26,10 +26,16 @@ {% block mediagoblin_content -%} {% if user %} - <h1>User page for '{{ user.username }}'</h1> + <h1>{{ user.username }}'s profile</h1> + + {% include "mediagoblin/utils/profile.html" %} {% include "mediagoblin/utils/object_gallery.html" %} + <p><a href="{{ request.urlgen('mediagoblin.user_pages.user_gallery', + user= request.user['username']) }}">View all of {{ user.username }}'s media</a></p> + + <a href={{ request.urlgen( 'mediagoblin.user_pages.atom_feed', user=user.username) }}> atom feed</a> diff --git a/mediagoblin/templates/mediagoblin/utils/object_gallery.html b/mediagoblin/templates/mediagoblin/utils/object_gallery.html index c9c3e0db..8c88c174 100644 --- a/mediagoblin/templates/mediagoblin/utils/object_gallery.html +++ b/mediagoblin/templates/mediagoblin/utils/object_gallery.html @@ -19,7 +19,7 @@ {% block object_gallery_content -%} <div> {% if media_entries %} - <ul> + <ul class="media_thumbnail"> {% for entry in media_entries %} <li class="media_thumbnail"> <a href="{{ entry.url_for_self(request.urlgen) }}"> diff --git a/mediagoblin/templates/mediagoblin/utils/profile.html b/mediagoblin/templates/mediagoblin/utils/profile.html new file mode 100644 index 00000000..b3f5f0f8 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/utils/profile.html @@ -0,0 +1,35 @@ +{# +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011 Free Software Foundation, Inc +# +# 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 <http://www.gnu.org/licenses/>. +#} + +{% block profile_content -%} + <div> + <ul> + {% if user.url %} + <li> + <a href="{{ user.url }}">homepage</a> + </li> + {% endif %} + + {% if user.bio %} + <li> + {{ user.bio }} + </li> + {% endif %} + </ul> + </div> +{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/utils/wtforms.html b/mediagoblin/templates/mediagoblin/utils/wtforms.html index 9adf8e53..1d2f8619 100644 --- a/mediagoblin/templates/mediagoblin/utils/wtforms.html +++ b/mediagoblin/templates/mediagoblin/utils/wtforms.html @@ -16,23 +16,47 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. #} +{# Generically render a field #} +{% macro render_field_div(field) %} + <div class="form_field_box"> + <div class="form_field_label">{{ field.label }}</div> + {% if field.description -%} + <div class="form_field_description">{{ field.description }}</div> + {%- endif %} + <div class="form_field_input">{{ field }}</div> + {%- if field.errors -%} + {% for error in field.errors %} + <div class="form_field_error"> + {{ error }} + </div> + {% endfor %} + {%- endif %} + </div> +{%- endmacro %} + +{# Generically render a textarea + # ... mostly the same thing except it includes rows and cols #} +{% macro render_textarea_div(field, rows=8, cols=20) %} + <div class="form_field_box"> + <div class="form_field_label">{{ field.label }}</div> + {% if field.description -%} + <div class="form_field_description">{{ field.description }}</div> + {%- endif %} + <div class="form_field_input">{{ field(rows=rows, cols=cols) }}</div> + {%- if field.errors -%} + {% for error in field.errors %} + <div class="form_field_error"> + {{ error }} + </div> + {% endfor %} + {%- endif %} + </div> +{%- endmacro %} + {# Auto-render a form as a series of divs #} {% macro render_divs(form) -%} {% for field in form %} - <div class="form_field_box"> - <div class="form_field_label">{{ field.label }}</div> - {% if field.description -%} - <div class="form_field_description">{{ field.description }}</div> - {%- endif %} - <div class="form_field_input">{{ field }}</div> - {%- if field.errors -%} - {% for error in field.errors %} - <div class="form_field_error"> - {{ error }} - </div> - {% endfor %} - {%- endif %} - </div> + {{ render_field_div(field) }} {% endfor %} {%- endmacro %} diff --git a/mediagoblin/tests/__init__.py b/mediagoblin/tests/__init__.py index 1f1e23e9..adb6a1b3 100644 --- a/mediagoblin/tests/__init__.py +++ b/mediagoblin/tests/__init__.py @@ -16,12 +16,17 @@ from mediagoblin import mg_globals +from mediagoblin.tests.tools import ( + MEDIAGOBLIN_TEST_DB_NAME, suicide_if_bad_celery_environ) + def setup_package(): - pass + suicide_if_bad_celery_environ() + def teardown_package(): - if mg_globals.db_connection: - print "Killing db ..." - mg_globals.db_connection.drop_database(mg_globals.database.name) - print "... done" + if ((mg_globals.db_connection + and mg_globals.database.name == MEDIAGOBLIN_TEST_DB_NAME)): + print "Killing db ..." + mg_globals.db_connection.drop_database(MEDIAGOBLIN_TEST_DB_NAME) + print "... done" diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index b8389f8d..3a13cbb1 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -242,17 +242,69 @@ def test_authentication_views(test_app): test_user.save() # Get login + # --------- test_app.get('/auth/login/') - # Make sure it rendered with the appropriate template assert util.TEMPLATE_TEST_CONTEXT.has_key( 'mediagoblin/auth/login.html') - # Log in as that user + # Failed login - blank form + # ------------------------- + util.clear_test_template_context() + response = test_app.post('/auth/login/') + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html'] + form = context['login_form'] + assert form.username.errors == [u'This field is required.'] + assert form.password.errors == [u'This field is required.'] + + # Failed login - blank user + # ------------------------- + util.clear_test_template_context() + response = test_app.post( + '/auth/login/', { + 'password': u'toast'}) + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html'] + form = context['login_form'] + assert form.username.errors == [u'This field is required.'] + + # Failed login - blank password + # ----------------------------- + util.clear_test_template_context() + response = test_app.post( + '/auth/login/', { + 'username': u'chris'}) + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html'] + form = context['login_form'] + assert form.password.errors == [u'This field is required.'] + + # Failed login - bad user + # ----------------------- + util.clear_test_template_context() + response = test_app.post( + '/auth/login/', { + 'username': u'steve', + 'password': 'toast'}) + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html'] + assert context['login_failed'] + + # Failed login - bad password + # --------------------------- + util.clear_test_template_context() + response = test_app.post( + '/auth/login/', { + 'username': u'chris', + 'password': 'jam'}) + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html'] + assert context['login_failed'] + + # Successful login + # ---------------- util.clear_test_template_context() response = test_app.post( '/auth/login/', { 'username': u'chris', 'password': 'toast'}) + + # User should be redirected response.follow() assert_equal( urlparse.urlsplit(response.location)[2], @@ -260,10 +312,38 @@ def test_authentication_views(test_app): assert util.TEMPLATE_TEST_CONTEXT.has_key( 'mediagoblin/root.html') - # Make sure we're in the session or something - session = util.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']['request'].session + # Make sure user is in the session + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html'] + session = context['request'].session assert session['user_id'] == unicode(test_user['_id']) - # Log out as that user - # Make sure we're not in the session + # Successful logout + # ----------------- + util.clear_test_template_context() + response = test_app.get('/auth/logout/') + + # Should be redirected to index page + response.follow() + assert_equal( + urlparse.urlsplit(response.location)[2], + '/') + assert util.TEMPLATE_TEST_CONTEXT.has_key( + 'mediagoblin/root.html') + + # Make sure the user is not in the session + context = util.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html'] + session = context['request'].session + assert session.has_key('user_id') == False + + # User is redirected to custom URL if POST['next'] is set + # ------------------------------------------------------- + util.clear_test_template_context() + response = test_app.post( + '/auth/login/', { + 'username': u'chris', + 'password': 'toast', + 'next' : '/u/chris/'}) + assert_equal( + urlparse.urlsplit(response.location)[2], + '/u/chris/') diff --git a/mediagoblin/tests/test_server.ini b/mediagoblin/tests/test_paste.ini index 929a1ccf..929a1ccf 100644 --- a/mediagoblin/tests/test_server.ini +++ b/mediagoblin/tests/test_paste.ini diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py index 515bccd4..ebb5f1b5 100644 --- a/mediagoblin/tests/tools.py +++ b/mediagoblin/tests/tools.py @@ -28,9 +28,9 @@ from mediagoblin.decorators import _make_safe from mediagoblin.db.open import setup_connection_and_db_from_config -MEDIAGOBLIN_TEST_DB_NAME = '__mediagoblinunittests__' +MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__' TEST_SERVER_CONFIG = pkg_resources.resource_filename( - 'mediagoblin.tests', 'test_server.ini') + 'mediagoblin.tests', 'test_paste.ini') TEST_APP_CONFIG = pkg_resources.resource_filename( 'mediagoblin.tests', 'test_mgoblin_app.ini') TEST_USER_DEV = pkg_resources.resource_filename( @@ -42,17 +42,23 @@ USER_DEV_DIRECTORIES_TO_SETUP = [ 'media/public', 'media/queue', 'beaker/sessions/data', 'beaker/sessions/lock'] +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""" + class BadCeleryEnviron(Exception): pass -def get_test_app(dump_old_app=True): +def suicide_if_bad_celery_environ(): if not os.environ.get('CELERY_CONFIG_MODULE') == \ 'mediagoblin.celery_setup.from_tests': - raise BadCeleryEnviron( - u"Sorry, you *absolutely* must run nosetests with the\n" - u"mediagoblin.celery_setup.from_tests module. Like so:\n" - u"$ CELERY_CONFIG_MODULE=mediagoblin.celery_setup.from_tests ./bin/nosetests") + raise BadCeleryEnviron(BAD_CELERY_MESSAGE) + + +def get_test_app(dump_old_app=True): + suicide_if_bad_celery_environ() global MGOBLIN_APP global CELERY_SETUP @@ -78,6 +84,7 @@ def get_test_app(dump_old_app=True): # @@: For now we're dropping collections, but we could also just # collection.remove() ? connection, db = setup_connection_and_db_from_config(app_config) + assert db.name == MEDIAGOBLIN_TEST_DB_NAME collections_to_wipe = [ collection @@ -87,10 +94,6 @@ def get_test_app(dump_old_app=True): for collection in collections_to_wipe: db.drop_collection(collection) - # Don't need these anymore... - del(connection) - del(db) - # TODO: Drop and recreate indexes # setup app and return diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 88b5dfe5..d6cd6034 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -108,10 +108,10 @@ 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'), + entry.get('description_html'), content_type='html', author=request.matchdict['user'], updated=entry.get('created'), diff --git a/mediagoblin/util.py b/mediagoblin/util.py index 349bc027..91fbee0a 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -29,11 +29,11 @@ import jinja2 import translitcodec from webob import Response, exc from lxml.html.clean import Cleaner +import markdown from mediagoblin import mg_globals from mediagoblin.db.util import ObjectId - TESTS_ENABLED = False def _activate_testing(): """ @@ -98,7 +98,7 @@ def get_jinja_env(template_loader, locale): template_env = jinja2.Environment( loader=template_loader, autoescape=True, - extensions=['jinja2.ext.i18n']) + extensions=['jinja2.ext.i18n', 'jinja2.ext.autoescape']) template_env.install_gettext_callables( mg_globals.translations.gettext, @@ -373,9 +373,28 @@ HTML_CLEANER = Cleaner( def clean_html(html): + # clean_html barfs on an empty string + if not html: + return u'' + return HTML_CLEANER.clean_html(html) +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. + """ + # Markdown will do nothing with and clean_html can do nothing with + # an empty string :) + if not text: + return u'' + + return clean_html(MARKDOWN_INSTANCE.convert(text)) + + SETUP_GETTEXTS = {} def setup_gettext(locale): @@ -43,6 +43,7 @@ setup( 'argparse', 'webtest', 'ConfigObj', + 'Markdown', ## For now we're expecting that users will install this from ## their package managers. # 'lxml', |