513 context = responses.getUniversalContext(request) |
516 context = responses.getUniversalContext(request) |
514 responses.useJavaScript(context, params['js_uses_all']) |
517 responses.useJavaScript(context, params['js_uses_all']) |
515 context['page_name'] = "%s titled '%s'" % (page_name, entity.title) |
518 context['page_name'] = "%s titled '%s'" % (page_name, entity.title) |
516 context['entity'] = entity |
519 context['entity'] = entity |
517 |
520 |
|
521 user_entity = user_logic.getForCurrentAccount() |
|
522 |
|
523 # try to get an existing SurveyRecord for the current user |
|
524 # TODO(ljvderijk) deal with the SurveyProperty name in subclasses |
|
525 filter = {'survey': entity, |
|
526 'user': user_entity} |
|
527 survey_record = record_logic.getForFields(filter, unique=True) |
|
528 |
518 if request.POST: |
529 if request.POST: |
519 return self.takePost(request, template, context, params, entity, |
530 return self.takePost(request, template, context, params, entity, |
520 **kwargs) |
531 survey_record, **kwargs) |
521 else: #request.GET |
532 else: #request.GET |
522 return self.takeGet(request, template, context, params, entity, |
533 return self.takeGet(request, template, context, params, entity, |
523 **kwargs) |
534 survey_record, **kwargs) |
524 |
535 |
525 def takeGet(self, request, template, context, params, entity, **kwargs): |
536 def takeGet(self, request, template, context, params, entity, record, |
|
537 **kwargs): |
526 """Handles the GET request for the Survey's take page. |
538 """Handles the GET request for the Survey's take page. |
527 |
539 |
528 Args: |
540 Args: |
529 template: the template used for this view |
541 template: the template used for this view |
530 entity: the student project entity |
542 entity: the Survey entity |
531 rest: see base.View.public() |
543 rest: see base.View.public() |
532 """ |
544 """ |
533 |
545 |
534 # TODO(ljvderijk) implement takeGet |
546 survey_form = surveys.SurveyForm(survey_content=entity.survey_content, |
535 |
547 survey_record=record, |
536 return http.HttpResponse("Work in Progress") |
548 survey_logic=self._params['logic']) |
537 |
549 |
538 def takePost(self, request, template, context, params, entity, **kwargs): |
550 survey_form.getFields() |
|
551 |
|
552 # fill context with the survey and additional information |
|
553 context['survey_form'] = survey_form |
|
554 self.setHelpAndStatus(context, entity, record) |
|
555 |
|
556 return responses.respond(request, template, context) |
|
557 |
|
558 def takePost(self, request, template, context, params, entity, record, |
|
559 **kwargs): |
539 """Handles the POST request for the Survey's take page. |
560 """Handles the POST request for the Survey's take page. |
540 |
561 |
541 Args: |
562 Args: |
542 template: the template used for this view |
563 template: the template used for this view |
543 entity: the student project entity |
564 entity: the Survey entity |
544 rest: see base.View.public() |
565 rest: see base.View.public() |
545 """ |
566 """ |
546 |
567 |
547 # TODO(ljvderijk) implement takePost |
568 # TODO(ljvderijk) implement takePost |
548 |
569 |
549 return httpHttpResponse("Work in Progress") |
570 return http.HttpResponse("Work in Progress") |
|
571 |
|
572 def setHelpAndStatus(self, context, survey, survey_record): |
|
573 """Get help_text and status for template use. |
|
574 |
|
575 Args: |
|
576 context: the context for the view to update |
|
577 survey: a Survey entity |
|
578 survey_record: a SurveyRecordEntity |
|
579 """ |
|
580 |
|
581 if not survey.survey_end: |
|
582 survey_end_text = "" |
|
583 else: |
|
584 survey_end_text = " by " + str( |
|
585 survey.survey_end.strftime("%A, %d. %B %Y %I:%M%p")) |
|
586 |
|
587 if survey_record: |
|
588 help_text = "Edit and re-submit this survey" + survey_end_text + "." |
|
589 status = "edit" |
|
590 else: |
|
591 help_text = "Please complete this survey" + survey_end_text + "." |
|
592 status = "create" |
|
593 |
|
594 # update the context with the help_text and status |
|
595 context_update = dict(status=status, help_text=help_text) |
|
596 context.update(context_update) |
550 |
597 |
551 def activate(self, request, **kwargs): |
598 def activate(self, request, **kwargs): |
552 """This is a hack to support the 'Enable grades' button. |
599 """This is a hack to support the 'Enable grades' button. |
553 """ |
600 """ |
554 self.activateGrades(request) |
601 self.activateGrades(request) |