504 'profile': profile, |
504 'profile': profile, |
505 } |
505 } |
506 |
506 |
507 context.update(csrf(request)) |
507 context.update(csrf(request)) |
508 |
508 |
509 if request.method == "POST": |
509 if request.method == 'POST': |
510 form = taskapp_forms.CreateTextbookForm(request.POST) |
510 form = taskapp_forms.CreateTextbookForm(request.POST) |
511 if form.is_valid(): |
511 if form.is_valid(): |
512 data = form.cleaned_data.copy() |
512 data = form.cleaned_data.copy() |
513 data.update({"created_by": user, |
513 data.update({"created_by": user, |
514 "creation_datetime": datetime.now()}) |
514 "creation_datetime": datetime.now()}) |
529 form = taskapp_forms.CreateTextbookForm() |
529 form = taskapp_forms.CreateTextbookForm() |
530 context.update({"form": form}) |
530 context.update({"form": form}) |
531 return shortcuts.render_to_response( |
531 return shortcuts.render_to_response( |
532 "task/edit.html", RequestContext(request, context)) |
532 "task/edit.html", RequestContext(request, context)) |
533 |
533 |
534 def view_textbook(request, task_id): |
534 def view_textbook(request, task_id, template='task/view_textbook.html'): |
535 |
535 |
536 # Shortcut to get_object_or_404 is not used since django-tagging |
536 # Shortcut to get_object_or_404 is not used since django-tagging |
537 # api expects a queryset object for tag filtering. |
537 # api expects a queryset object for tag filtering. |
538 task = taskapp_models.Task.objects.filter(pk=task_id) |
538 task = taskapp_models.Task.objects.filter(pk=task_id) |
539 |
539 |
552 "textbook": textbook, |
552 "textbook": textbook, |
553 # "chapters": chapters, |
553 # "chapters": chapters, |
554 } |
554 } |
555 |
555 |
556 if not user.is_authenticated(): |
556 if not user.is_authenticated(): |
557 return shortcuts.render_to_response("task/view_textbook.html", |
557 return shortcuts.render_to_response(template, |
558 RequestContext(request, context)) |
558 RequestContext(request, context)) |
559 |
559 |
560 profile = user.get_profile() |
560 profile = user.get_profile() |
561 |
561 |
562 context.update({"profile": profile, |
562 context.update({ |
563 "textbook": textbook, |
563 'profile': profile, |
564 }) |
564 'textbook': textbook, |
565 |
565 }) |
566 context.update(csrf(request)) |
566 |
567 |
567 context.update(csrf(request)) |
568 if (user == textbook.created_by and |
568 |
569 textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]): |
569 user_role = user.get_profile().role |
|
570 if ((user == textbook.created_by or |
|
571 user_role != profile_models.ROLES_CHOICES[3][0]) and |
|
572 textbook.status in [taskapp_models.TB_STATUS_CHOICES[0][0], |
|
573 taskapp_models.TB_STATUS_CHOICES[1][0]]): |
570 can_edit = True |
574 can_edit = True |
571 else: |
575 else: |
572 can_edit = False |
576 can_edit = False |
573 |
577 |
574 |
578 |
577 textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]): |
581 textbook.status == taskapp_models.TB_STATUS_CHOICES[0][0]): |
578 can_approve = True |
582 can_approve = True |
579 else: |
583 else: |
580 can_approve = False |
584 can_approve = False |
581 |
585 |
582 context.update({"can_edit": can_edit, |
586 context.update({ |
583 "can_approve": can_approve}) |
587 'can_edit': can_edit, |
584 return shortcuts.render_to_response("task/view_textbook.html", |
588 'can_approve': can_approve, |
|
589 'can_create_chapters': can_create_chapters, |
|
590 }) |
|
591 return shortcuts.render_to_response(template, |
585 RequestContext(request, context)) |
592 RequestContext(request, context)) |
586 |
593 |
587 def browse_textbooks(request): |
594 def browse_textbooks(request): |
588 """View to list all the open textbooks. This view fetches tasks |
595 """View to list all the open textbooks. This view fetches tasks |
589 tagged with Textbook. |
596 tagged with Textbook. |