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.

117 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. def get_queryset(self):
  26. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  27. return project.documents.all()
  28. class LabelView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  29. template_name = 'admin.html'
  30. extra_context = {
  31. 'bundle_name': 'label'
  32. }
  33. class StatsView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  34. template_name = 'admin.html'
  35. extra_context = {
  36. 'bundle_name': 'stats'
  37. }
  38. class GuidelineView(SuperUserMixin, LoginRequiredMixin, TemplateView):
  39. template_name = 'admin.html'
  40. extra_context = {
  41. 'bundle_name': 'guideline'
  42. }
  43. class DataUpload(SuperUserMixin, LoginRequiredMixin, TemplateView):
  44. template_name = 'admin.html'
  45. def get_context_data(self, **kwargs):
  46. context = super().get_context_data(**kwargs)
  47. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  48. context['bundle_name'] = project.get_bundle_name_upload()
  49. return context
  50. class DataDownload(SuperUserMixin, LoginRequiredMixin, TemplateView):
  51. template_name = 'admin.html'
  52. def get_context_data(self, **kwargs):
  53. context = super().get_context_data(**kwargs)
  54. project = get_object_or_404(Project, pk=self.kwargs['project_id'])
  55. context['bundle_name'] = project.get_bundle_name_download()
  56. return context
  57. class LoginView(BaseLoginView):
  58. template_name = 'login.html'
  59. redirect_authenticated_user = True
  60. extra_context = {
  61. 'github_login': bool(settings.SOCIAL_AUTH_GITHUB_KEY),
  62. 'aad_login': bool(settings.SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID),
  63. }
  64. def get_context_data(self, **kwargs):
  65. context = super(LoginView, self).get_context_data(**kwargs)
  66. context['social_login_enabled'] = any(value for key, value in context.items()
  67. if key.endswith('_login'))
  68. return context
  69. class DemoTextClassification(TemplateView):
  70. template_name = 'annotation.html'
  71. extra_context = {
  72. 'bundle_name': 'demo_text_classification',
  73. }
  74. class DemoNamedEntityRecognition(TemplateView):
  75. template_name = 'annotation.html'
  76. extra_context = {
  77. 'bundle_name': 'demo_named_entity',
  78. }
  79. class DemoTranslation(TemplateView):
  80. template_name = 'annotation.html'
  81. extra_context = {
  82. 'bundle_name': 'demo_translation',
  83. }