You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. import logging
  2. from django.contrib.auth.views import LoginView as BaseLoginView
  3. from django.shortcuts import get_object_or_404
  4. from django.views.generic import TemplateView
  5. from django.views.generic.list import ListView
  6. from django.contrib.auth.mixins import LoginRequiredMixin
  7. from .permissions import SuperUserMixin
  8. from .models import Project
  9. from app import settings
  10. logger = logging.getLogger(__name__)
  11. class IndexView(TemplateView):
  12. template_name = 'index.html'
  13. class ProjectView(LoginRequiredMixin, TemplateView):
  14. template_name = 'annotation.html'
  15. def get_context_data(self, **kwargs):
  16. context = super().get_context_data(**kwargs)
  17. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  18. context['bundle_name'] = project.get_bundle_name()
  19. return context
  20. class ProjectsView(LoginRequiredMixin, TemplateView):
  21. template_name = 'projects.html'
  22. class DatasetView(SuperUserMixin, LoginRequiredMixin, ListView):
  23. template_name = 'dataset.html'
  24. paginate_by = 5
  25. extra_context = {
  26. 'bundle_name': 'dataset'
  27. }
  28. def get_queryset(self):
  29. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  30. return project.documents.all()
  31. class LabelView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  32. template_name = 'admin.html'
  33. extra_context = {
  34. 'bundle_name': 'label'
  35. }
  36. class StatsView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  37. template_name = 'admin.html'
  38. extra_context = {
  39. 'bundle_name': 'stats'
  40. }
  41. class GuidelineView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  42. template_name = 'admin.html'
  43. extra_context = {
  44. 'bundle_name': 'guideline'
  45. }
  46. class DataUpload(SuperUserMixin, LoginRequiredMixin, TemplateView):
  47. template_name = 'admin.html'
  48. def get_context_data(self, **kwargs):
  49. context = super().get_context_data(**kwargs)
  50. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  51. context['bundle_name'] = project.get_bundle_name_upload()
  52. return context
  53. class DataDownload(SuperUserMixin, LoginRequiredMixin, TemplateView):
  54. template_name = 'admin.html'
  55. def get_context_data(self, **kwargs):
  56. context = super().get_context_data(**kwargs)
  57. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  58. context['bundle_name'] = project.get_bundle_name_download()
  59. return context
  60. class LoginView(BaseLoginView):
  61. template_name = 'login.html'
  62. redirect_authenticated_user = True
  63. extra_context = {
  64. 'github_login': bool(settings.SOCIAL_AUTH_GITHUB_KEY),
  65. 'aad_login': bool(settings.SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID),
  66. }
  67. def get_context_data(self, **kwargs):
  68. context = super(LoginView, self).get_context_data(**kwargs)
  69. context['social_login_enabled'] = any(value for key, value in context.items()
  70. if key.endswith('_login'))
  71. return context
  72. class DemoTextClassification(TemplateView):
  73. template_name = 'annotation.html'
  74. extra_context = {
  75. 'bundle_name': 'demo_text_classification',
  76. }
  77. class DemoNamedEntityRecognition(TemplateView):
  78. template_name = 'annotation.html'
  79. extra_context = {
  80. 'bundle_name': 'demo_named_entity',
  81. }
  82. class DemoTranslation(TemplateView):
  83. template_name = 'annotation.html'
  84. extra_context = {
  85. 'bundle_name': 'demo_translation',
  86. }