blob: ddf1743fef5da2635ac117f70720b860e7dc4635 [file] [log] [blame]
# Copyright 2013 the Melange authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
"""Module containing views for the Summer Of Code organization homepage."""
from google.appengine.ext import db
from google.appengine.ext import ndb
from django.utils import translation
from melange.models import organization as org_model
from melange.request import access
from melange.request import links
from melange.utils import lists as melange_lists
from soc.views import template
from soc.views.helper import lists
from soc.views.helper import url_patterns
from soc.modules.gsoc.logic import project as project_logic
from soc.modules.gsoc.views import base
from soc.modules.gsoc.views.helper import url_patterns as soc_url_patterns
from soc.modules.gsoc.views.helper import url_names
from summerofcode.views.helper import urls
ORG_HOME_PAGE_TITLE = translation.ugettext('%s')
PROJECT_LIST_DESCRIPTION = translation.ugettext(
'List of projects accepted into %s.')
_ACCEPTED_PROJECTS_LIST_TITLE = translation.ugettext('Accepted Projects')
CONTACT_TEMPLATE_PATH = 'modules/gsoc/_connect_with_us.html'
class Contact(template.Template):
"""Contact template."""
def __init__(self, template_path, data):
"""Initializes a new instance of Contact template.
template_path: Path to the template that should be rendered.
data: request_data.RequestData for the current request.
super(Contact, self).__init__(data)
self.template_path = template_path
def context(self):
"""See template.Template.context for specification."""
return {
class _ProjectDetailsRowRedirect(melange_lists.RedirectCustomRow):
"""Class which provides redirects for rows of public organization list."""
def __init__(self, data):
"""Initializes a new instance of the row redirect.
See lists.RedirectCustomRow.__init__ for specification.
data: request_data.RequestData for the current request.
super(_ProjectDetailsRowRedirect, self).__init__() = data
def getLink(self, item):
"""See lists.RedirectCustomRow.getLink for specification."""
project_key = db.Key(item['columns']['key'])
return links.LINKER.userId(
project_key.parent(),, url_names.GSOC_PROJECT_DETAILS)
# TODO(daniel): replace this class with new style list
class ProjectList(template.Template):
"""List of projects."""
def __init__(self, data, description):
"""See template.Template.__init__ for specification."""
super(ProjectList, self).__init__(data)
self._list_config = lists.ListConfiguration()
def getStudent(entity, *args):
"""Helper function to get value for student column."""
return ndb.Key.from_old_key(entity.parent_key()).get().public_name
self._list_config.addPlainTextColumn('student', 'Student', getStudent)
self._list_config.addSimpleColumn('title', 'Title')
'mentors', 'Mentors',
lambda entity, m, *args: ', '.join(
mentor.public_name for mentor in entity.getMentors()))
self._description = description
def templatePath(self):
"""See template.Template.templatePath for specification."""
return 'summerofcode/_list_component.html'
def context(self):
"""See template.Template.context for specification."""
list_configuration_response = lists.ListConfigurationResponse(, self._list_config, 0, self._description)
return {
'lists': [list_configuration_response],
class OrgHomePage(base.GSoCRequestHandler):
"""View to display organization homepage."""
access_checker = access.UrlOrgStatusAccessChecker([org_model.Status.ACCEPTED])
def templatePath(self):
"""See base.RequestHandler.templatePath for specification."""
return 'modules/gsoc/org_home/base.html'
def djangoURLPatterns(self):
"""See base.RequestHandler.djangoURLPatterns for specification."""
# TODO(daniel): should we keep all these legacy patterns here?
# TODO(daniel): remove '2' when old view is not ready
return [
soc_url_patterns.url(r'org2/%s$' % url_patterns.ORG, self,
soc_url_patterns.url(r'org2/show/%s$' % url_patterns.ORG, self),
soc_url_patterns.url(r'org2/home/%s$' % url_patterns.ORG, self),
def context(self, data, check, mutator):
"""See base.RequestHandler.context for specification."""
context = {
'page_name': ORG_HOME_PAGE_TITLE %,
'organization': data.url_ndb_org,
'contact': Contact(CONTACT_TEMPLATE_PATH, data),
if data.timeline.studentsAnnounced():
context['students_announced'] = True
context['project_list'] = ProjectList(
return context
def jsonContext(self, data, check, mutator):
"""See base.RequestHandler.jsonContext for specification."""
query = project_logic.getAcceptedProjectsQuery(
program=data.program, org=data.url_ndb_org.key.to_old_key())
response = melange_lists.JqgridResponse(
return response.getData(query)