|
1 | | -import pytz |
2 | | -from enum import Enum |
3 | 1 | from datetime import datetime |
4 | | -from framework import status |
| 2 | +from enum import Enum |
5 | 3 |
|
6 | | -from django.utils import timezone |
7 | | -from django.core.exceptions import PermissionDenied, ValidationError |
8 | | -from django.urls import NoReverseMatch |
9 | | -from django.db.models import F, Case, When, IntegerField |
| 4 | +import pytz |
10 | 5 | from django.contrib import messages |
11 | 6 | from django.contrib.auth.mixins import PermissionRequiredMixin |
| 7 | +from django.core.exceptions import PermissionDenied, ValidationError |
| 8 | +from django.db.models import F, Case, When, IntegerField |
12 | 9 | from django.http import HttpResponse |
| 10 | +from django.shortcuts import redirect, reverse, get_object_or_404 |
| 11 | +from django.urls import NoReverseMatch |
| 12 | +from django.urls import reverse_lazy |
| 13 | +from django.utils import timezone |
13 | 14 | from django.views.generic import ( |
14 | 15 | View, |
15 | 16 | FormView, |
16 | 17 | ListView, |
17 | 18 | ) |
18 | | -from django.shortcuts import redirect, reverse, get_object_or_404 |
19 | | -from django.urls import reverse_lazy |
20 | 19 |
|
| 20 | +from admin.base.forms import GuidForm |
21 | 21 | from admin.base.utils import change_embargo_date |
22 | 22 | from admin.base.views import GuidView |
23 | | -from admin.base.forms import GuidForm |
24 | | -from admin.notifications.views import detect_duplicate_notifications, delete_selected_notifications |
25 | 23 | from admin.nodes.forms import AddSystemTagForm, RegistrationDateForm |
26 | | - |
27 | | -from api.share.utils import update_share |
| 24 | +from admin.notifications.views import detect_duplicate_notifications, delete_selected_notifications |
28 | 25 | from api.caching.tasks import update_storage_usage_cache |
29 | | - |
| 26 | +from api.share.utils import update_share |
| 27 | +from framework import status |
30 | 28 | from osf.exceptions import NodeStateError, RegistrationStuckError |
31 | 29 | from osf.models import ( |
32 | 30 | OSFUser, |
|
49 | 47 | REINDEX_ELASTIC, |
50 | 48 | ) |
51 | 49 | from osf.utils.permissions import ADMIN, API_CONTRIBUTOR_PERMISSIONS |
52 | | - |
53 | 50 | from scripts.approve_registrations import approve_past_pendings |
54 | | - |
55 | 51 | from website import settings, search |
56 | 52 | from website.archiver.tasks import force_archive |
57 | 53 |
|
@@ -146,7 +142,8 @@ def get_context_data(self, **kwargs): |
146 | 142 | 'STORAGE_LIMITS': settings.StorageLimits, |
147 | 143 | 'node': node, |
148 | 144 | # to edit contributors we should have guid as django prohibits _id usage as it starts with an underscore |
149 | | - 'annotated_contributors': node.contributor_set.prefetch_related('user__guids').annotate(guid=F('user__guids___id')), |
| 145 | + 'annotated_contributors': node.contributor_set.prefetch_related('user__guids').annotate( |
| 146 | + guid=F('user__guids___id')), |
150 | 147 | 'children': children, |
151 | 148 | 'permissions': API_CONTRIBUTOR_PERMISSIONS, |
152 | 149 | 'has_update_permission': self.request.user.has_perm('osf.change_node'), |
@@ -207,7 +204,9 @@ class NodeRemoveContributorView(NodeMixin, View): |
207 | 204 | def post(self, request, *args, **kwargs): |
208 | 205 | node = self.get_object() |
209 | 206 | user = OSFUser.objects.get(id=self.kwargs.get('user_id')) |
210 | | - if node.has_permission(user, ADMIN) and not node._get_admin_contributors_query(node._contributors.all(), require_active=False).exclude(user=user).exists(): |
| 207 | + if node.has_permission(user, ADMIN) and not node._get_admin_contributors_query(node._contributors.all(), |
| 208 | + require_active=False).exclude( |
| 209 | + user=user).exists(): |
211 | 210 | messages.error(self.request, 'Must be at least one admin on this node.') |
212 | 211 | return redirect(self.get_success_url()) |
213 | 212 |
|
@@ -866,7 +865,7 @@ class ForceArchiveRegistrationsView(NodeMixin, View): |
866 | 865 |
|
867 | 866 | def post(self, request, *args, **kwargs): |
868 | 867 | # Prevents circular imports that cause admin app to hang at startup |
869 | | - from osf.management.commands.force_archive import verify, archive, DEFAULT_PERMISSIBLE_ADDONS |
| 868 | + from osf.management.commands.force_archive import verify, DEFAULT_PERMISSIBLE_ADDONS |
870 | 869 | from osf.models.admin_log_entry import update_admin_log, MANUAL_ARCHIVE_RESTART |
871 | 870 |
|
872 | 871 | registration = self.get_object() |
@@ -909,11 +908,12 @@ def post(self, request, *args, **kwargs): |
909 | 908 | ) |
910 | 909 | messages.success( |
911 | 910 | request, |
912 | | - f'Registration archive process has started. Task id: {force_archive_task.id}.' |
913 | | - ) |
| 911 | + f'Registration archive process has started. Task id: {force_archive_task.id}.' |
| 912 | + ) |
914 | 913 | except Exception as exc: |
915 | | - messages.error(request, f'This registration cannot be archived due to {exc.__class__.__name__}: {str(exc)}. ' |
916 | | - f'If the problem persists get a developer to fix it.') |
| 914 | + messages.error(request, |
| 915 | + f'This registration cannot be archived due to {exc.__class__.__name__}: {str(exc)}. ' |
| 916 | + f'If the problem persists get a developer to fix it.') |
917 | 917 |
|
918 | 918 | return redirect(self.get_success_url()) |
919 | 919 |
|
|
0 commit comments