Advertisement
run_009

Untitled

Mar 25th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.08 KB | None | 0 0
  1. # Copyright 2013 the Melange authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14.  
  15. """Module containing the view for GSoC participants list page."""
  16.  
  17. from django.utils import translation
  18.  
  19. from google.appengine.ext import ndb
  20. from django.utils import translation
  21.  
  22. from melange.logic import profile as profile_logic
  23. from melange.request import access
  24. from melange.request import exception
  25. from soc.views.helper import addresses
  26. from soc.views.helper import url_patterns
  27. from soc.views import template
  28. from soc.views import toggle_button
  29. from soc.views.helper import lists
  30. from soc.views.template import Template
  31. from soc.modules.gsoc.views.base import GSoCRequestHandler
  32. from soc.modules.gsoc.views.helper.url_patterns import url
  33.  
  34. from summerofcode.logic import profile as soc_profile_logic
  35. from summerofcode.request import links
  36. from summerofcode.views.helper import urls
  37. from summerofcode.views.helper import urls as soc_urls
  38. from google.appengine.ext import ndb
  39.  
  40. from django import forms as django_forms
  41. from django import http
  42. from django.utils import translation
  43.  
  44. from melange.logic import profile as profile_logic
  45. from melange.request import access
  46. from melange.request import exception
  47.  
  48. from soc.modules.gsoc.views import assign_mentor
  49. from soc.modules.gsoc.views import forms as gsoc_forms
  50. from soc.modules.gsoc.views import base as gsoc_base
  51. from soc.modules.gsoc.views.helper import url_patterns as soc_url_patterns
  52.  
  53. from soc.views import base
  54. from soc.views import template
  55. from soc.views import toggle_button
  56. from soc.views.helper import url_patterns
  57.  
  58. from summerofcode.logic import profile as soc_profile_logic
  59. from summerofcode.logic import proposal as proposal_logic
  60. from summerofcode.models import proposal as proposal_model
  61. from summerofcode.request import error
  62. from summerofcode.request import links
  63. from summerofcode.request import render
  64. from summerofcode.templates import top_message
  65. from summerofcode.views.helper import urls as soc_urls
  66.  
  67.  
  68.  
  69. class MentorsList(Template):
  70. """Template for list of mentors for admins."""
  71.  
  72. def __init__(self, data):
  73. self.data = data
  74.  
  75. def getMentorFor(entity, *args):
  76. """Helper function to get value of mentor_for column."""
  77. return ', '.join(
  78. org.name for org in ndb.get_multi(entity.mentor_for) if org)
  79.  
  80. def getAdminFor(entity, *args):
  81. """Helper function to get value of admin_for column."""
  82. return ', '.join(
  83. org.name for org in ndb.get_multi(entity.admin_for) if org)
  84.  
  85.  
  86. list_config = lists.ListConfiguration()
  87.  
  88. list_config.addPlainTextColumn(
  89. 'name', 'Name', lambda entity, *args: entity.public_name.strip())
  90. list_config.addSimpleColumn('profile_id', 'Username')
  91. list_config.addPlainTextColumn('is_admin', 'Is Admin',
  92. lambda entity, *args: 'Yes' if entity.is_admin else 'No', hidden=True)
  93. list_config.addPlainTextColumn(
  94. 'email', 'Email', lambda entity, *args: entity.contact.email)
  95. list_config.addPlainTextColumn(
  96. 'admin_for', 'Admin For', getAdminFor)
  97. list_config.addPlainTextColumn('mentor_for', 'Mentor For', getMentorFor)
  98.  
  99. addresses.addAddressColumns(list_config)
  100. list_config.addPlainTextColumn(
  101. 'tee_style', 'T-Shirt Style', lambda entity, *args: entity.tee_style)
  102. list_config.addPlainTextColumn(
  103. 'tee_size', 'T-Shirt Size', lambda entity, *args: entity.tee_size)
  104.  
  105. list_config.setDefaultPagination(False)
  106. list_config.setDefaultSort('name')
  107.  
  108. self._list_config = list_config
  109.  
  110. def context(self):
  111. description = \
  112. 'List of organization admins and mentors participating in %s' % (
  113. self.data.program.name)
  114.  
  115. return {
  116. 'lists': [lists.ListConfigurationResponse(
  117. self.data, self._list_config, 0, description)],
  118. }
  119.  
  120. def getListData(self):
  121. if lists.getListIndex(self.data.request) != 0:
  122. return None
  123.  
  124. query = profile_logic.queryAllMentorsForProgram(self.data.program.key())
  125.  
  126. starter = lists.keyStarter
  127. # TODO(daniel): enable prefetching from ndb models
  128. # ('mentor_for', 'org_admin_for')
  129. prefetcher = None
  130.  
  131. response_builder = lists.RawQueryContentResponseBuilder(
  132. self.data.request, self._list_config, query, starter,
  133. prefetcher=prefetcher)
  134.  
  135. return response_builder.buildNDB()
  136.  
  137. def templatePath(self):
  138. return 'modules/gsoc/participants/_mentors_list.html'
  139.  
  140.  
  141. class MentorsListAdminPage(GSoCRequestHandler):
  142. """View for the organization admin and mentors page for admin."""
  143.  
  144. access_checker = access.PROGRAM_ADMINISTRATOR_ACCESS_CHECKER
  145.  
  146. def templatePath(self):
  147. return 'modules/gsoc/participants/base.html'
  148.  
  149. def djangoURLPatterns(self):
  150. return [
  151. url(r'admin/list/mentors/%s$' % url_patterns.PROGRAM, self,
  152. name='gsoc_list_mentors'),
  153. ]
  154.  
  155. def jsonContext(self, data, check, mutator):
  156. list_content = MentorsList(data).getListData()
  157. if list_content:
  158. return list_content.content()
  159. else:
  160. raise exception.Forbidden(message='You do not have access to this data')
  161.  
  162. def context(self, data, check, mutator):
  163. return {
  164. 'page_name': "List of organization admins and mentors for %s" % (
  165. data.program.name),
  166. 'mentors_list': MentorsList(data),
  167. }
  168.  
  169. class ManageActions(template.Template):
  170. """Template to render the left side user actions."""
  171.  
  172. def __init__(self, data, toggle_buttons):
  173. """Initializes a new instance of this class.
  174.  
  175. Args:
  176. data: request_data.RequestData for the current request.
  177. toggle_buttons: List of toggle buttons to use for the actions.
  178. assign_mentor_field: Optional field to assign mentors for the proposal.
  179. """
  180. super(ManageActions, self).__init__(data)
  181. self.toggle_buttons = toggle_buttons
  182.  
  183. def templatePath(self):
  184. """See template.Template.templatPath for specification"""
  185. return 'modules/gsoc/proposal/_user_action.html'
  186.  
  187. def context(self):
  188. """See template.Template.context for specification."""
  189. return {
  190. 'toggle_buttons': self.toggle_buttons,
  191. }
  192.  
  193. _BUTTON_ACCEPT_AS_PROJECT_HELP_TEXT = translation.ugettext(
  194. 'Choosing Yes will mark this proposal as accepted. The proposal is '
  195. 'accepted when Yes is displayed in bright orange.')
  196.  
  197. _BUTTON_ACCEPT_AS_PROJECT_TITLE = translation.ugettext('Accept Project Student')
  198.  
  199. _BUTTON_ACCEPT_AS_PROJECT_ID = 'accept-proposal'
  200.  
  201. _MANAGE_ACTIONS_TITLE = translation.ugettext('List Actions')
  202. def _toggleButtonsForStudent(data, url_names):
  203. """Returns toggle buttons for proposal actions available for organization
  204. administrators and program administrators.
  205.  
  206. Args:
  207. data: request_data.RequestData for the current request.
  208. url_names: Instance of url_names.UrlNames.
  209.  
  210. Returns:
  211. A list of toggle_button.ToggleButtonTwoActionsTemplate instances.
  212. """
  213. toggle_buttons = []
  214. toggle_buttons.append(
  215. toggle_button.ToggleButtonTwoActionsTemplate(
  216. data, 'on_off', _BUTTON_ACCEPT_AS_PROJECT_TITLE,
  217. _BUTTON_ACCEPT_AS_PROJECT_ID,
  218. url_names.STUDENTS_ALL,
  219. url_names.STUDENTS_ALL,
  220. checked=None,
  221. labels={'checked': 'Yes', 'unchecked': 'No'},
  222. help_text=_BUTTON_ACCEPT_AS_PROJECT_HELP_TEXT))
  223. return toggle_buttons
  224.  
  225. class StudentsList(Template):
  226. """List configuration for listing all the students involved with the program.
  227. """
  228.  
  229. def __init__(self, request, data, linker, url_names):
  230. """Initializes this component."""
  231. self.data = data
  232. self.linker = linker
  233. self.url_names = url_names
  234.  
  235. def taxFormSubmitted(entity, *args):
  236. """Helper function to get value of tax_form_submitted column."""
  237. if not soc_profile_logic.hasProject(entity):
  238. return 'N/A'
  239. elif entity.student_data.tax_form:
  240. return 'Yes'
  241. else:
  242. return 'No'
  243.  
  244. def enrollmentFormSubmitted(entity, *args):
  245. """Helper function to get value of enrollment_form_submitted column."""
  246. if not soc_profile_logic.hasProject(entity):
  247. return 'N/A'
  248. elif entity.student_data.enrollment_form:
  249. return 'Yes'
  250. else:
  251. return 'No'
  252.  
  253. def allFormsSubmitted(entity, *args):
  254. """Helper function to get value of all_forms_submitted column."""
  255. if not soc_profile_logic.hasProject(entity):
  256. return 'N/A'
  257. elif entity.student_data.enrollment_form and entity.student_data.tax_form:
  258. return 'Yes'
  259. else:
  260. return 'No'
  261.  
  262. def projectsForOrgs(entity, *args):
  263. """Helper function to get value of projects_for_orgs column."""
  264. if not soc_profile_logic.hasProject(entity):
  265. return 'N/A'
  266. else:
  267. return ', '.join(
  268. org_key.get().name
  269. for org_key in entity.student_data.project_for_orgs)
  270.  
  271.  
  272.  
  273.  
  274. list_config = lists.ListConfiguration()
  275. list_config.addPlainTextColumn(
  276. 'name', 'Name', lambda entity, *args: entity.public_name.strip())
  277. list_config.addSimpleColumn('profile_id', 'Username')
  278. list_config.addPlainTextColumn(
  279. 'email', 'Email', lambda entity, *args: entity.contact.email)
  280. list_config.addSimpleColumn('gender', 'Gender', hidden=True)
  281. list_config.addSimpleColumn(
  282. 'birth_date', 'Birthdate', column_type=lists.BIRTHDATE, hidden=True)
  283. list_config.addPlainTextColumn(
  284. 'tax_form_submitted', 'Tax form submitted',
  285. taxFormSubmitted, hidden=True)
  286. list_config.addPlainTextColumn(
  287. 'enrollment_form_submitted', 'Enrollment form submitted',
  288. enrollmentFormSubmitted, hidden=True)
  289. list_config.addPlainTextColumn(
  290. 'all_forms_submitted', 'All Forms submitted', allFormsSubmitted)
  291.  
  292. addresses.addAddressColumns(list_config)
  293. list_config.addPlainTextColumn(
  294. 'tee_style', 'T-Shirt Style', lambda entity, *args: entity.tee_style)
  295. list_config.addPlainTextColumn(
  296. 'tee_size', 'T-Shirt Size', lambda entity, *args: entity.tee_size)
  297.  
  298. list_config.addPlainTextColumn(
  299. 'school_name', 'School Name',
  300. lambda entity, *args: entity.student_data.education.school_id,
  301. hidden=True)
  302. list_config.addPlainTextColumn(
  303. 'school_country', 'School Country',
  304. lambda entity, *args: entity.student_data.education.school_country,
  305. hidden=True)
  306. list_config.addPlainTextColumn(
  307. 'school_web_page', 'School Web Page',
  308. lambda entity, *args: entity.student_data.education.web_page,
  309. hidden=True)
  310. list_config.addPlainTextColumn(
  311. 'major', 'Major',
  312. lambda entity, *args: entity.student_data.education.major,
  313. hidden=True)
  314. list_config.addPlainTextColumn(
  315. 'degree', 'Degree',
  316. lambda entity, *args: entity.student_data.education.degree,
  317. hidden=True)
  318. list_config.addPlainTextColumn(
  319. 'expected_graduation', 'Expected Graduation',
  320. lambda entity, *args: entity.student_data.education.expected_graduation,
  321. hidden=True)
  322. list_config.addPlainTextColumn(
  323. 'number_of_proposals', 'Number Of Proposals',
  324. lambda entity, *args: entity.student_data.number_of_proposals,
  325. hidden=True)
  326. list_config.addNumericalColumn(
  327. 'number_of_projects', 'Number Of Projects',
  328. lambda entity, *args: entity.student_data.number_of_projects,
  329. hidden=True)
  330. list_config.addNumericalColumn(
  331. 'number_of_passed_evaluations', 'Passed Evaluations',
  332. lambda entity, *args: entity.student_data.number_of_passed_evaluations,
  333. hidden=True)
  334. list_config.addNumericalColumn(
  335. 'number_of_failed_evaluations', 'Failed Evaluations',
  336. lambda entity, *args: entity.student_data.number_of_failed_evaluations,
  337. hidden=True)
  338. list_config.addPlainTextColumn(
  339. 'project_for_orgs', 'Projects For Organizations', projectsForOrgs)
  340.  
  341. list_config.setRowAction(
  342. lambda profile, *args: self.linker.profile(
  343. profile, self.url_names.PROFILE_ADMIN))
  344.  
  345. self._list_config = list_config
  346.  
  347. def templatePath(self):
  348. """See template.Template.templatePath for specification."""
  349. return 'modules/gsoc/dashboard/list_component.html'
  350.  
  351. def getListData(self):
  352. idx = lists.getListIndex(self.data.request)
  353.  
  354. if idx != 0:
  355. return None
  356.  
  357. query = profile_logic.queryAllStudentsForProgram(self.data.program.key())
  358.  
  359. starter = lists.keyStarter
  360.  
  361. response_builder = lists.RawQueryContentResponseBuilder(
  362. self.data.request, self._list_config, query, starter)
  363.  
  364. return response_builder.buildNDB()
  365.  
  366. def context(self):
  367. """See template.Template.context for specification."""
  368. description = translation.ugettext('List of participating students')
  369. list_configuration_response = lists.ListConfigurationResponse(
  370. self.data, self._list_config, idx=0, description=description)
  371.  
  372.  
  373. return {
  374. 'name': 'students',
  375. 'title': 'Participating students',
  376. 'lists': [list_configuration_response],
  377. }
  378.  
  379.  
  380.  
  381. class StudentsListWithProject(Template):
  382. """List configuration for listing all the students involved with the program.
  383. """
  384.  
  385. def __init__(self, request, data, linker, url_names):
  386. """Initializes this component."""
  387. self.data = data
  388. self.linker = linker
  389. self.url_names = url_names
  390.  
  391. def taxFormSubmitted(entity, *args):
  392. """Helper function to get value of tax_form_submitted column."""
  393. if not soc_profile_logic.hasProject(entity):
  394. return 'N/A'
  395. elif entity.student_data.tax_form:
  396. return 'Yes'
  397. else:
  398. return 'No'
  399.  
  400. def enrollmentFormSubmitted(entity, *args):
  401. """Helper function to get value of enrollment_form_submitted column."""
  402. if not soc_profile_logic.hasProject(entity):
  403. return 'N/A'
  404. elif entity.student_data.enrollment_form:
  405. return 'Yes'
  406. else:
  407. return 'No'
  408.  
  409. def allFormsSubmitted(entity, *args):
  410. """Helper function to get value of all_forms_submitted column."""
  411. if not soc_profile_logic.hasProject(entity):
  412. return 'N/A'
  413. elif entity.student_data.enrollment_form and entity.student_data.tax_form:
  414. return 'Yes'
  415. else:
  416. return 'No'
  417.  
  418. def projectsForOrgs(entity, *args):
  419. """Helper function to get value of projects_for_orgs column."""
  420. if not soc_profile_logic.hasProject(entity):
  421. return 'N/A'
  422. else:
  423. return ', '.join(
  424. org_key.get().name
  425. for org_key in entity.student_data.project_for_orgs)
  426.  
  427.  
  428.  
  429.  
  430. list_config = lists.ListConfiguration()
  431. list_config.addPlainTextColumn(
  432. 'name', 'Name', lambda entity, *args: entity.public_name.strip())
  433. list_config.addSimpleColumn('profile_id', 'Username')
  434. list_config.addPlainTextColumn(
  435. 'email', 'Email', lambda entity, *args: entity.contact.email)
  436. list_config.addSimpleColumn('gender', 'Gender', hidden=True)
  437. list_config.addSimpleColumn(
  438. 'birth_date', 'Birthdate', column_type=lists.BIRTHDATE, hidden=True)
  439. list_config.addPlainTextColumn(
  440. 'tax_form_submitted', 'Tax form submitted',
  441. taxFormSubmitted, hidden=True)
  442. list_config.addPlainTextColumn(
  443. 'enrollment_form_submitted', 'Enrollment form submitted',
  444. enrollmentFormSubmitted, hidden=True)
  445. list_config.addPlainTextColumn(
  446. 'all_forms_submitted', 'All Forms submitted', allFormsSubmitted)
  447.  
  448. addresses.addAddressColumns(list_config)
  449. list_config.addPlainTextColumn(
  450. 'tee_style', 'T-Shirt Style', lambda entity, *args: entity.tee_style)
  451. list_config.addPlainTextColumn(
  452. 'tee_size', 'T-Shirt Size', lambda entity, *args: entity.tee_size)
  453.  
  454. list_config.addPlainTextColumn(
  455. 'school_name', 'School Name',
  456. lambda entity, *args: entity.student_data.education.school_id,
  457. hidden=True)
  458. list_config.addPlainTextColumn(
  459. 'school_country', 'School Country',
  460. lambda entity, *args: entity.student_data.education.school_country,
  461. hidden=True)
  462. list_config.addPlainTextColumn(
  463. 'school_web_page', 'School Web Page',
  464. lambda entity, *args: entity.student_data.education.web_page,
  465. hidden=True)
  466. list_config.addPlainTextColumn(
  467. 'major', 'Major',
  468. lambda entity, *args: entity.student_data.education.major,
  469. hidden=True)
  470. list_config.addPlainTextColumn(
  471. 'degree', 'Degree',
  472. lambda entity, *args: entity.student_data.education.degree,
  473. hidden=True)
  474. list_config.addPlainTextColumn(
  475. 'expected_graduation', 'Expected Graduation',
  476. lambda entity, *args: entity.student_data.education.expected_graduation,
  477. hidden=True)
  478. list_config.addPlainTextColumn(
  479. 'number_of_proposals', 'Number Of Proposals',
  480. lambda entity, *args: entity.student_data.number_of_proposals,
  481. hidden=True)
  482. list_config.addNumericalColumn(
  483. 'number_of_projects', 'Number Of Projects',
  484. lambda entity, *args: entity.student_data.number_of_projects,
  485. hidden=True)
  486. list_config.addNumericalColumn(
  487. 'number_of_passed_evaluations', 'Passed Evaluations',
  488. lambda entity, *args: entity.student_data.number_of_passed_evaluations,
  489. hidden=True)
  490. list_config.addNumericalColumn(
  491. 'number_of_failed_evaluations', 'Failed Evaluations',
  492. lambda entity, *args: entity.student_data.number_of_failed_evaluations,
  493. hidden=True)
  494. list_config.addPlainTextColumn(
  495. 'project_for_orgs', 'Projects For Organizations', projectsForOrgs)
  496.  
  497. list_config.setRowAction(
  498. lambda profile, *args: self.linker.profile(
  499. profile, self.url_names.PROFILE_ADMIN))
  500.  
  501. self._list_config = list_config
  502.  
  503. def templatePath(self):
  504. """See template.Template.templatePath for specification."""
  505. return 'modules/gsoc/dashboard/list_component.html'
  506.  
  507. def getListData(self):
  508. idx = lists.getListIndex(self.data.request)
  509.  
  510. if idx != 0:
  511. return None
  512.  
  513. query = profile_logic.queryAllStudentsWithProjectForProgram(self.data.program.key())
  514.  
  515. starter = lists.keyStarter
  516.  
  517. response_builder = lists.RawQueryContentResponseBuilder(
  518. self.data.request, self._list_config, query, starter)
  519.  
  520. return response_builder.buildNDB()
  521.  
  522. def context(self):
  523. """See template.Template.context for specification."""
  524. description = translation.ugettext('List of participating students')
  525. list_configuration_response = lists.ListConfigurationResponse(
  526. self.data, self._list_config, idx=0, description=description)
  527.  
  528.  
  529. return {
  530. 'name': 'students',
  531. 'title': 'Participating students',
  532. 'lists': [list_configuration_response],
  533. }
  534.  
  535.  
  536. class StudentsListPage(base.RequestHandler):
  537. """View that lists all the students associated with the program."""
  538.  
  539. access_checker = access.PROGRAM_ADMINISTRATOR_ACCESS_CHECKER
  540.  
  541. def __init__(self, initializer, linker, renderer, error_handler,
  542. url_pattern_constructor, url_names, template_path):
  543. """Initializes a new instance of the request handler for the specified
  544. parameters.
  545.  
  546. Args:
  547. initializer: Implementation of initialize.Initializer interface.
  548. linker: Instance of links.Linker class.
  549. renderer: Implementation of render.Renderer interface.
  550. error_handler: Implementation of error.ErrorHandler interface.
  551. url_pattern_constructor:
  552. Implementation of url_patterns.UrlPatternConstructor.
  553. url_names: Instance of url_names.UrlNames.
  554. template_path: The path of the template to be used.
  555. """
  556. super(StudentsListPage, self).__init__(
  557. initializer, linker, renderer, error_handler)
  558. self.url_pattern_constructor = url_pattern_constructor
  559. self.url_names = url_names
  560. self.template_path = template_path
  561.  
  562. def djangoURLPatterns(self):
  563. """See base.RequestHandler.djangoURLPatterns for specification."""
  564. return [
  565. self.url_pattern_constructor.construct(
  566. r'admin/students/%s$' % url_patterns.PROGRAM, self,
  567. name=self.url_names.STUDENTS_LIST),
  568. ]
  569.  
  570. def templatePath(self):
  571. """See base.RequestHandler.template_path for specification."""
  572. return self.template_path
  573.  
  574. def jsonContext(self, data, check, mutator):
  575. """See base.RequestHandler.jsonContext for specification."""
  576. list_content = StudentsList(
  577. data.request, data, links.SOC_LINKER, urls.UrlNames).getListData()
  578. if list_content:
  579. return list_content.content()
  580. else:
  581. raise exception.Forbidden(message='You do not have access to this data')
  582.  
  583. def context(self, data, check, mutator):
  584. """See base.RequestHandler.context for specification."""
  585. toggle_buttons = _toggleButtonsForStudent(data,urls.UrlNames)
  586. manage_actions = ManageActions(data,toggle_buttons)
  587. return {
  588. 'page_name': 'Students list page',
  589. # TODO(nathaniel): Drop the first parameter of StudentsList.
  590. 'list': StudentsList(data.request, data, links.SOC_LINKER, urls.UrlNames),
  591. 'manage_actions': manage_actions,
  592. }
  593. STUDENTS_LIST = (
  594. StudentsListPage(
  595. gsoc_base._GSOC_INITIALIZER, links.SOC_LINKER, render.SOC_RENDERER,
  596. error.SOC_ERROR_HANDLER, soc_url_patterns.SOC_URL_PATTERN_CONSTRUCTOR,
  597. soc_urls.UrlNames, 'modules/gsoc/admin/student_list.html'))
  598.  
  599.  
  600.  
  601. class StudentsAll(base.RequestHandler):
  602. """Handler to withdraw the proposal."""
  603.  
  604. access_checker = access.IS_URL_USER_ACCESS_CHECKER
  605.  
  606. def __init__(self, initializer, linker, renderer, error_handler,
  607. url_pattern_constructor, url_names):
  608. """Initializes a new instance of the request handler for the specified
  609. parameters.
  610.  
  611. Args:
  612. initializer: Implementation of initialize.Initializer interface.
  613. linker: Instance of links.Linker class.
  614. renderer: Implementation of render.Renderer interface.
  615. error_handler: Implementation of error.ErrorHandler interface.
  616. url_pattern_constructor:
  617. Implementation of url_patterns.UrlPatternConstructor.
  618. url_names: Instance of url_names.UrlNames.
  619. """
  620. super(StudentsAll, self).__init__(
  621. initializer, linker, renderer, error_handler)
  622. self.url_pattern_constructor = url_pattern_constructor
  623. self.url_names = url_names
  624.  
  625. def djangoURLPatterns(self):
  626. """See base.RequestHandler.djangoURLPatterns for specification."""
  627. return [
  628. self.url_pattern_constructor.construct(
  629. r'admin/students/%s$' % url_patterns.PROGRAM,
  630. self, name=self.url_names.STUDENTS_ALL),
  631. ]
  632.  
  633. def post(self, data, check, mutator):
  634. """See base.RequestHandler.post for specification."""
  635. '''result = proposal_logic.withdrawProposal(data.url_ndb_proposal.key)
  636. if not result:
  637. raise exception.BadRequest(message=result.extra)
  638. else:
  639. return http.HttpResponse()'''
  640. return http.HttpResponseRedirect(STUDENTS_LIST_WITH_PROJECT)
  641.  
  642.  
  643. STUDENTS_ALL = StudentsAll(
  644. gsoc_base._GSOC_INITIALIZER, links.SOC_LINKER, render.SOC_RENDERER,
  645. error.SOC_ERROR_HANDLER, soc_url_patterns.SOC_URL_PATTERN_CONSTRUCTOR,
  646. soc_urls.UrlNames)
  647.  
  648.  
  649.  
  650. class StudentsListPageWithProject(base.RequestHandler):
  651. """View that lists all the students associated with the program."""
  652.  
  653. access_checker = access.PROGRAM_ADMINISTRATOR_ACCESS_CHECKER
  654.  
  655. def __init__(self, initializer, linker, renderer, error_handler,
  656. url_pattern_constructor, url_names, template_path):
  657. """Initializes a new instance of the request handler for the specified
  658. parameters.
  659.  
  660. Args:
  661. initializer: Implementation of initialize.Initializer interface.
  662. linker: Instance of links.Linker class.
  663. renderer: Implementation of render.Renderer interface.
  664. error_handler: Implementation of error.ErrorHandler interface.
  665. url_pattern_constructor:
  666. Implementation of url_patterns.UrlPatternConstructor.
  667. url_names: Instance of url_names.UrlNames.
  668. template_path: The path of the template to be used.
  669. """
  670. super(StudentsListPageWithProject, self).__init__(
  671. initializer, linker, renderer, error_handler)
  672. self.url_pattern_constructor = url_pattern_constructor
  673. self.url_names = url_names
  674. self.template_path = template_path
  675.  
  676. def djangoURLPatterns(self):
  677. """See base.RequestHandler.djangoURLPatterns for specification."""
  678. return [
  679. self.url_pattern_constructor.construct(
  680. r'admin/students/%s$' % url_patterns.PROGRAM, self,
  681. name=self.url_names.STUDENTS_LIST_WITH_PROJECT),
  682. ]
  683.  
  684. def templatePath(self):
  685. """See base.RequestHandler.template_path for specification."""
  686. return self.template_path
  687.  
  688. def jsonContext(self, data, check, mutator):
  689. """See base.RequestHandler.jsonContext for specification."""
  690. list_content = StudentsListWithProject(
  691. data.request, data, links.SOC_LINKER, urls.UrlNames).getListData()
  692. if list_content:
  693. return list_content.content()
  694. else:
  695. raise exception.Forbidden(message='You do not have access to this data')
  696.  
  697. def context(self, data, check, mutator):
  698. """See base.RequestHandler.context for specification."""
  699. toggle_buttons = _toggleButtonsForStudent(data,urls.UrlNames)
  700. manage_actions = ManageActions(data,toggle_buttons)
  701. return {
  702. 'page_name': 'Students list page',
  703. # TODO(nathaniel): Drop the first parameter of StudentsList.
  704. 'list': StudentsListWithProject(data.request, data, links.SOC_LINKER, urls.UrlNames),
  705. 'manage_actions': manage_actions,
  706. }
  707.  
  708. STUDENTS_LIST_WITH_PROJECT = (
  709. StudentsListPageWithProject(
  710. gsoc_base._GSOC_INITIALIZER, links.SOC_LINKER, render.SOC_RENDERER,
  711. error.SOC_ERROR_HANDLER, soc_url_patterns.SOC_URL_PATTERN_CONSTRUCTOR,
  712. soc_urls.UrlNames, 'modules/gsoc/admin/student_list.html'))
  713.  
  714.  
  715.  
  716. class StudentsWithProject(base.RequestHandler):
  717. """Handler to withdraw the proposal."""
  718.  
  719. access_checker = access.IS_URL_USER_ACCESS_CHECKER
  720.  
  721. def __init__(self, initializer, linker, renderer, error_handler,
  722. url_pattern_constructor, url_names):
  723. """Initializes a new instance of the request handler for the specified
  724. parameters.
  725.  
  726. Args:
  727. initializer: Implementation of initialize.Initializer interface.
  728. linker: Instance of links.Linker class.
  729. renderer: Implementation of render.Renderer interface.
  730. error_handler: Implementation of error.ErrorHandler interface.
  731. url_pattern_constructor:
  732. Implementation of url_patterns.UrlPatternConstructor.
  733. url_names: Instance of url_names.UrlNames.
  734. """
  735. super(StudentsWithProject, self).__init__(
  736. initializer, linker, renderer, error_handler)
  737. self.url_pattern_constructor = url_pattern_constructor
  738. self.url_names = url_names
  739.  
  740. def djangoURLPatterns(self):
  741. """See base.RequestHandler.djangoURLPatterns for specification."""
  742. return [
  743. self.url_pattern_constructor.construct(
  744. r'admin/students/%s$' % url_patterns.PROGRAM,
  745. self, name=self.url_names.STUDENTS_WITH_PROJECT),
  746. ]
  747.  
  748. def post(self, data, check, mutator):
  749. """See base.RequestHandler.post for specification."""
  750. '''result = proposal_logic.withdrawProposal(data.url_ndb_proposal.key)
  751. if not result:
  752. raise exception.BadRequest(message=result.extra)
  753. else:
  754. return http.HttpResponse()'''
  755. return http.HttpResponseRedirect(self.url_names.STUDENTS_ALL)
  756.  
  757.  
  758. STUDENTS_WITH_PROJECT = StudentsWithProject(
  759. gsoc_base._GSOC_INITIALIZER, links.SOC_LINKER, render.SOC_RENDERER,
  760. error.SOC_ERROR_HANDLER, soc_url_patterns.SOC_URL_PATTERN_CONSTRUCTOR,
  761. soc_urls.UrlNames)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement