
did a few things. I wrote many many many new tests, either in old test files or in the three new test files I made. I also did some code-keeping work, deleting trailing whitespace and deleting vestigial code. Lastly, I fixed the parts of the code which I realized were broken thru the process of running tests. =============================================================================== Deleted trailing whitespace: =============================================================================== --\ mediagoblin/decorators.py --\ mediagoblin/auth/tools.py --\ mediagoblin/db/migrations.py --\ mediagoblin/db/models.py --\ mediagoblin/gmg_commands/users.py --\ mediagoblin/moderation/forms.py --\ mediagoblin/moderation/tools.py --\ mediagoblin/moderation/views.py --\ mediagoblin/templates/mediagoblin/moderation/media_panel.html --\ mediagoblin/templates/mediagoblin/moderation/report.html --\ mediagoblin/templates/mediagoblin/moderation/report_panel.html --\ mediagoblin/templates/mediagoblin/moderation/user.html --\ mediagoblin/templates/mediagoblin/moderation/user_panel.html --\ mediagoblin/templates/mediagoblin/user_pages/report.html --\ mediagoblin/templates/mediagoblin/utils/report.html --\ mediagoblin/user_pages/lib.py --\ mediagoblin/user_pages/views.py =============================================================================== Deleted Vestigial Code =============================================================================== --\ mediagoblin/db/util.py --\ mediagoblin/tests/test_notifications.py =============================================================================== Modified the Code: =============================================================================== --\ mediagoblin/moderation/tools.py --| Encapsulated the code around giving/taking away privileges into two | funtions. --\ mediagoblin/moderation/views.py --| Imported and used the give/take away privilege functions --| Replaced 'require_admin_or_moderator_login' with |'user_has_privilege(u"admin")' for adding/taking away privileges, only | admins are allowed to do this. --\ mediagoblin/templates/mediagoblin/banned.html --| Added relevant translation tags --| Added ability to display indefinite banning --\ mediagoblin/templates/mediagoblin/user_pages/media.html --| Made sure the add comments button was only visible for users with the | `commenter` privilege --\ mediagoblin/tests/test_submission.py --| Paroneayea fixed a DetachedInstanceError I was having with the our_user | function --\ mediagoblin/tests/tools.py --| Added a fixture_add_comment_report function for testing. --\ mediagoblin/tools/response.py --| Fixed a minor error where a necessary return statement was missing --| Fit the code within 80 columns --\ mediagoblin/user_pages/views.py --| Added a necessary decorator to ensure that only users with the 'commenter' | privilege can post comments =============================================================================== Wrote new tests for an old test file: =============================================================================== --\ mediagoblin/tests/test_auth.py --| Added a new test to make sure privilege granting on registration happens | correctly --\ mediagoblin/tests/test_modelmethods.py* --| Added a test to ensure the User method has_privilege works properly =============================================================================== Wrote entirely new files full of tests: =============================================================================== --\ mediagoblin/tests/test_moderation.py --\ mediagoblin/tests/test_privileges.py --\ mediagoblin/tests/test_reporting.py =============================================================================== =============================================================================== NOTE: Any files I've marked with a * in this commit report, were actually subm- itted in my last commit. I made that committ to fix an error I was having, so they weren't properly documented in that report. =============================================================================== ===============================================================================
77 lines
2.7 KiB
Python
77 lines
2.7 KiB
Python
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
from mediagoblin.db.base import Session
|
|
from mediagoblin.db.models import (MediaEntry, Tag, MediaTag, Collection, \
|
|
User, Privilege, FOUNDATIONS)
|
|
|
|
|
|
##########################
|
|
# Random utility functions
|
|
##########################
|
|
|
|
|
|
def atomic_update(table, query_dict, update_values):
|
|
table.query.filter_by(**query_dict).update(update_values,
|
|
synchronize_session=False)
|
|
Session.commit()
|
|
|
|
|
|
def check_media_slug_used(uploader_id, slug, ignore_m_id):
|
|
query = MediaEntry.query.filter_by(uploader=uploader_id, slug=slug)
|
|
if ignore_m_id is not None:
|
|
query = query.filter(MediaEntry.id != ignore_m_id)
|
|
does_exist = query.first() is not None
|
|
return does_exist
|
|
|
|
|
|
def media_entries_for_tag_slug(dummy_db, tag_slug):
|
|
return MediaEntry.query \
|
|
.join(MediaEntry.tags_helper) \
|
|
.join(MediaTag.tag_helper) \
|
|
.filter(
|
|
(MediaEntry.state == u'processed')
|
|
& (Tag.slug == tag_slug))
|
|
|
|
|
|
def clean_orphan_tags(commit=True):
|
|
"""Search for unused MediaTags and delete them"""
|
|
q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id==None)
|
|
for t in q1:
|
|
Session.delete(t)
|
|
# The "let the db do all the work" version:
|
|
# q1 = Session.query(Tag.id).outerjoin(MediaTag).filter(MediaTag.id==None)
|
|
# q2 = Session.query(Tag).filter(Tag.id.in_(q1))
|
|
# q2.delete(synchronize_session = False)
|
|
if commit:
|
|
Session.commit()
|
|
|
|
|
|
def check_collection_slug_used(creator_id, slug, ignore_c_id):
|
|
filt = (Collection.creator == creator_id) \
|
|
& (Collection.slug == slug)
|
|
if ignore_c_id is not None:
|
|
filt = filt & (Collection.id != ignore_c_id)
|
|
does_exist = Session.query(Collection.id).filter(filt).first() is not None
|
|
return does_exist
|
|
|
|
if __name__ == '__main__':
|
|
from mediagoblin.db.open import setup_connection_and_db_from_config
|
|
|
|
db = setup_connection_and_db_from_config({'sql_engine':'sqlite:///mediagoblin.db'})
|
|
|
|
clean_orphan_tags()
|