views.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # GNU MediaGoblin -- federated, autonomous media hosting
  2. # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. from mediagoblin import mg_globals
  17. from mediagoblin.db.models import MediaEntry
  18. from mediagoblin.tools.pagination import Pagination
  19. from mediagoblin.tools.pluginapi import hook_handle
  20. from mediagoblin.tools.response import render_to_response, render_404
  21. from mediagoblin.decorators import uses_pagination, user_not_banned
  22. @user_not_banned
  23. @uses_pagination
  24. def default_root_view(request, page):
  25. cursor = request.db.query(MediaEntry).filter_by(state=u'processed').\
  26. order_by(MediaEntry.created.desc())
  27. pagination = Pagination(page, cursor)
  28. media_entries = pagination()
  29. return render_to_response(
  30. request, 'mediagoblin/root.html',
  31. {'media_entries': media_entries,
  32. 'allow_registration': mg_globals.app_config["allow_registration"],
  33. 'pagination': pagination})
  34. def root_view(request):
  35. """
  36. Proxies to the real root view that's displayed
  37. """
  38. view = hook_handle("frontpage_view") or default_root_view
  39. return view(request)
  40. def simple_template_render(request):
  41. """
  42. A view for absolutely simple template rendering.
  43. Just make sure 'template' is in the matchdict!
  44. """
  45. template_name = request.matchdict['template']
  46. return render_to_response(
  47. request, template_name, {})
  48. def terms_of_service(request):
  49. if mg_globals.app_config["show_tos"] is False:
  50. return render_404(request)
  51. return render_to_response(request,
  52. 'mediagoblin/terms_of_service.html', {})