in src/olympia/reviewers/forms.py [0:0]
def __init__(self, *args, **kw):
self.helper = kw.pop('helper')
super().__init__(*args, **kw)
if any(action.get('delayable') for action in self.helper.actions.values()):
# Default delayed rejection date should be
# REVIEWER_DELAYED_REJECTION_PERIOD_DAYS_DEFAULT days in the
# future plus one hour to account for the time it's taking the
# reviewer to actually perform the review.
now = datetime.now()
self.fields['delayed_rejection_date'].initial = now + timedelta(
days=REVIEWER_DELAYED_REJECTION_PERIOD_DAYS_DEFAULT, hours=1
)
# We enforce a reasonable min value on the widget.
self.min_rejection_date = now + timedelta(days=1)
delayed_rejection_date_widget_attrs = {
'min': self.min_rejection_date.isoformat()[:16],
}
if not acl.action_allowed_for(
self.helper.handler.user, amo.permissions.REVIEWS_ADMIN
):
# Non-admin reviewers can't customize the date.
delayed_rejection_date_widget_attrs['readonly'] = 'readonly'
self.fields['delayed_rejection_date'].widget.attrs.update(
delayed_rejection_date_widget_attrs
)
else:
# No delayable action available, remove the fields entirely.
del self.fields['delayed_rejection_date']
del self.fields['delayed_rejection']
# With the helper, we now have the add-on and can set queryset on the
# versions field correctly. Small optimization: we only need to do this
# if the relevant actions are available, otherwise we don't really care
# about this field.
versions_actions = [
k
for k in self.helper.actions
if self.helper.actions[k].get('multiple_versions')
]
if versions_actions:
if self.helper.version:
channel = self.helper.version.channel
else:
channel = amo.CHANNEL_LISTED
needs_human_review_qs = NeedsHumanReview.objects.filter(
is_active=True, version=OuterRef('pk')
)
self.fields['versions'].widget.versions_actions = versions_actions
self.fields['versions'].queryset = (
self.helper.addon.versions(manager='unfiltered_for_relations')
.filter(channel=channel)
.no_transforms()
.select_related('file')
.select_related('autoapprovalsummary')
.select_related('reviewerflags')
.annotate(needs_human_review=Exists(needs_human_review_qs))
.order_by('created')
)
# Reset data-value depending on widget depending on actions available.
self.fields['versions'].widget.attrs['data-value'] = ' '.join(
versions_actions
)
# Set choices on the action field dynamically to raise an error when
# someone tries to use an action they don't have access to.
self.fields['action'].choices = [
(k, v['label']) for k, v in self.helper.actions.items()
]
# Set the queryset for reasons based on the add-on type.
self.fields['reasons'].queryset = ReviewActionReason.objects.filter(
is_active=True,
addon_type__in=[
amo.ADDON_ANY,
amo.ADDON_STATICTHEME
if self.helper.addon.type == amo.ADDON_STATICTHEME
else amo.ADDON_EXTENSION,
],
).exclude(canned_response='')
# Add actions from the helper into the action widget so we can access
# them in create_option.
self.fields['action'].widget.actions = self.helper.actions
# Set the queryset for cinderjobs to resolve
self.fields[
'cinder_jobs_to_resolve'
].queryset = self.helper.unresolved_cinderjob_qs
# Set the queryset for policies to show as options
self.fields['cinder_policies'].queryset = CinderPolicy.objects.filter(
expose_in_reviewer_tools=True
)