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.

138 lines
4.1 KiB

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