/app/soc/modules/gsoc/views/accepted_orgs.py

https://code.google.com/ · Python · 122 lines · 76 code · 25 blank · 21 comment · 3 complexity · 6e3cc0bbac742213248cd7301896b929 MD5 · raw file

  1. #!/usr/bin/env python2.5
  2. #
  3. # Copyright 2011 the Melange authors.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Module containing the views for GSoC accepted orgs.
  17. """
  18. from django.conf.urls.defaults import url as django_url
  19. from soc.logic.exceptions import AccessViolation
  20. from soc.views.base_templates import ProgramSelect
  21. from soc.views.helper import lists
  22. from soc.views.template import Template
  23. from soc.views.helper import url as url_helper
  24. from soc.views.helper import url_patterns
  25. from soc.modules.gsoc.models.organization import GSoCOrganization
  26. from soc.modules.gsoc.views.base import RequestHandler
  27. from soc.modules.gsoc.views.helper.url_patterns import url
  28. class AcceptedOrgsList(Template):
  29. """Template for list of accepted organizations.
  30. """
  31. def __init__(self, request, data):
  32. self.request = request
  33. self.data = data
  34. r = data.redirect
  35. list_config = lists.ListConfiguration()
  36. list_config.addColumn('name', 'Name',
  37. lambda e, *args: e.name.strip())
  38. list_config.addSimpleColumn('link_id', 'Link ID', hidden=True)
  39. list_config.setRowAction(
  40. lambda e, *args: r.organization(e).urlOf('gsoc_org_home'))
  41. list_config.addColumn('tags', 'Tags',
  42. lambda e, *args: ", ".join(e.tags))
  43. list_config.addColumn(
  44. 'ideas', 'Ideas',
  45. (lambda e, *args: url_helper.urlize(e.ideas, name="[ideas page]")),
  46. hidden=True)
  47. list_config.setDefaultPagination(False)
  48. list_config.setDefaultSort('name')
  49. self._list_config = list_config
  50. def context(self):
  51. description = 'List of organizations accepted into %s' % (
  52. self.data.program.name)
  53. list = lists.ListConfigurationResponse(
  54. self.data, self._list_config, 0, description)
  55. return {
  56. 'lists': [list],
  57. }
  58. def getListData(self):
  59. idx = lists.getListIndex(self.request)
  60. if idx == 0:
  61. q = GSoCOrganization.all()
  62. q.filter('scope', self.data.program)
  63. q.filter('status IN', ['new', 'active'])
  64. starter = lists.keyStarter
  65. response_builder = lists.RawQueryContentResponseBuilder(
  66. self.request, self._list_config, q, starter)
  67. return response_builder.build()
  68. else:
  69. return None
  70. def templatePath(self):
  71. return "v2/modules/gsoc/accepted_orgs/_project_list.html"
  72. class AcceptedOrgsPage(RequestHandler):
  73. """View for the accepted organizations page.
  74. """
  75. def templatePath(self):
  76. return 'v2/modules/gsoc/accepted_orgs/base.html'
  77. def djangoURLPatterns(self):
  78. return [
  79. url(r'accepted_orgs/%s$' % url_patterns.PROGRAM, self,
  80. name='gsoc_accepted_orgs'),
  81. url(r'program/accepted_orgs/%s$' % url_patterns.PROGRAM, self),
  82. django_url(r'^program/accepted_orgs/%s$' % url_patterns.PROGRAM, self),
  83. ]
  84. def checkAccess(self):
  85. self.check.acceptedOrgsAnnounced()
  86. def jsonContext(self):
  87. list_content = AcceptedOrgsList(self.request, self.data).getListData()
  88. if not list_content:
  89. raise AccessViolation(
  90. 'You do not have access to this data')
  91. return list_content.content()
  92. def context(self):
  93. return {
  94. 'page_name': "Accepted organizations for %s" % self.data.program.name,
  95. 'accepted_orgs_list': AcceptedOrgsList(self.request, self.data),
  96. 'program_select': ProgramSelect(self.data, 'gsoc_accepted_orgs'),
  97. }