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.

135 lines
3.9 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. import sys
  2. import logging
  3. sys.path.append('../api')
  4. from django.contrib.auth.views import LoginView as BaseLoginView
  5. from django.shortcuts import get_object_or_404
  6. from django.views.generic import TemplateView
  7. from django.views.generic.list import ListView
  8. from django.contrib.auth.mixins import LoginRequiredMixin
  9. from api.permissions import ProjectAdminMixin
  10. from api.models import Project, RoleMapping
  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. 'allow_signup': bool(settings.ALLOW_SIGNUP),
  79. }
  80. def get_context_data(self, **kwargs):
  81. context = super(LoginView, self).get_context_data(**kwargs)
  82. context['social_login_enabled'] = any(value for key, value in context.items()
  83. if key.endswith('_login'))
  84. return context
  85. class DemoTextClassification(TemplateView):
  86. template_name = 'annotation.html'
  87. extra_context = {
  88. 'bundle_name': 'demo_text_classification',
  89. }
  90. class DemoNamedEntityRecognition(TemplateView):
  91. template_name = 'annotation.html'
  92. extra_context = {
  93. 'bundle_name': 'demo_named_entity',
  94. }
  95. class DemoTranslation(TemplateView):
  96. template_name = 'annotation.html'
  97. extra_context = {
  98. 'bundle_name': 'demo_translation',
  99. }