def get_context_data(self): """Add forms for bulk actions""" context = super(MyRequestList, self).get_context_data() context['project_form'] = ProjectManagerForm(user=self.request.user) context['tag_form'] = TagManagerForm(required=False) context['share_form'] = FOIAAccessForm(required=False) context['can_embargo'] = can_embargo(self.request.user) context['can_perm_embargo'] = can_embargo_permananently( self.request.user) return context
def get_context_data(self, **kwargs): """Add extra context data""" context = super(Detail, self).get_context_data(**kwargs) foia = context['foia'] user = self.request.user user_can_edit = foia.has_perm(self.request.user, 'change') user_can_embargo = foia.has_perm(self.request.user, 'embargo') is_past_due = foia.date_due < datetime.now().date() if foia.date_due else False include_draft = user.is_staff or foia.status == 'started' context['all_tags'] = Tag.objects.all() context['past_due'] = is_past_due context['user_can_edit'] = user_can_edit context['user_can_pay'] = user_can_edit and foia.is_payable() context['embargo'] = { 'show': user_can_embargo or foia.embargo, 'edit': user_can_embargo, 'add': user_can_embargo, 'remove': user_can_edit and foia.embargo, } context['embargo_form'] = FOIAEmbargoForm(initial={ 'permanent_embargo': foia.permanent_embargo, 'date_embargo': foia.date_embargo }) context['note_form'] = FOIANoteForm() context['access_form'] = FOIAAccessForm() context['question_form'] = QuestionForm(user=user, initial={'foia': foia}) context['crowdfund_form'] = CrowdfundForm(initial={ 'name': u'Crowdfund Request: %s' % unicode(foia), 'description': 'Help cover the request fees needed to free these docs!', 'payment_required': foia.get_stripe_amount(), 'date_due': datetime.now() + timedelta(30), 'foia': foia }) context['embargo_needs_date'] = foia.status in END_STATUS context['user_actions'] = foia.user_actions(user) context['contextual_request_actions'] = \ foia.contextual_request_actions(user, user_can_edit) context['status_choices'] = STATUS if include_draft else STATUS_NODRAFT context['show_estimated_date'] = foia.status not in ['submitted', 'ack', 'done', 'rejected'] context['change_estimated_date'] = FOIAEstimatedCompletionDateForm(instance=foia) all_tasks = Task.objects.filter_by_foia(foia, user) open_tasks = [task for task in all_tasks if not task.resolved] context['task_count'] = len(all_tasks) context['open_task_count'] = len(open_tasks) context['open_tasks'] = open_tasks context['stripe_pk'] = settings.STRIPE_PUB_KEY context['sidebar_admin_url'] = reverse('admin:foia_foiarequest_change', args=(foia.pk,)) context['is_thankable'] = self.request.user.has_perm( 'foia.thank_foiarequest', foia) context['files'] = foia.files.all()[:50] if foia.sidebar_html: messages.info(self.request, foia.sidebar_html) return context
def get_context_data(self, **kwargs): """Add forms for bulk actions""" context = super(MyRequestList, self).get_context_data(**kwargs) context["project_form"] = ProjectManagerForm(user=self.request.user) # set auto_id to avoid clashing IDs with the tag filter context["tag_form"] = TagManagerForm(required=False, auto_id="id_tm_%s") context["share_form"] = FOIAAccessForm(required=False) context["can_embargo"] = can_embargo(self.request.user) context["can_perm_embargo"] = can_embargo_permananently( self.request.user) return context
def _share(self, foias, user, post): """Share the requests with the selected users""" foias = [f for f in foias if f.has_perm(user, 'change')] form = FOIAAccessForm(post) if form.is_valid(): access = form.cleaned_data['access'] users = form.cleaned_data['users'] if access == 'edit': for foia in foias: foia.read_collaborators.remove(*users) foia.edit_collaborators.add(*users) elif access == 'view': for foia in foias: foia.edit_collaborators.remove(*users) foia.read_collaborators.add(*users) return 'Requests shared'
def _share(self, foias, user, post): """Share the requests with the selected users""" foias = [f for f in foias if f.has_perm(user, "change")] form = FOIAAccessForm(post) if form.is_valid(): access = form.cleaned_data["access"] users = form.cleaned_data["users"] if access == "edit": for foia in foias: foia.read_collaborators.remove(*users) foia.edit_collaborators.add(*users) elif access == "view": for foia in foias: foia.edit_collaborators.remove(*users) foia.read_collaborators.add(*users) return "Requests shared" else: return None
def _grant_access(self, request, foia): """Grant editor access to the specified users.""" form = FOIAAccessForm(request.POST) has_perm = foia.has_perm(request.user, 'change') if not has_perm or not form.is_valid(): return redirect(foia) access = form.cleaned_data['access'] users = form.cleaned_data['users'] if access == 'edit' and users: for user in users: foia.add_editor(user) if access == 'view' and users: for user in users: foia.add_viewer(user) if len(users) > 1: success_msg = '%d people can now %s this request.' % (len(users), access) else: success_msg = '%s can now %s this request.' % (users[0].first_name, access) messages.success(request, success_msg) return redirect(foia)
def _get_form_context_data(self, context): """Get context data about forms""" context["access_form"] = FOIAAccessForm() context["admin_fix_form"] = self.admin_fix_form context["agency_passcode_form"] = self.agency_passcode_form context["agency_reply_form"] = self.agency_reply_form context["appeal_contact_info_form"] = ContactInfoForm( foia=self.foia, appeal=True, prefix="appeal" ) context["change_estimated_date"] = FOIAEstimatedCompletionDateForm( instance=self.foia ) context["contact_info_form"] = ContactInfoForm( foia=self.foia, prefix="followup" ) context["crowdfund_form"] = CrowdfundForm( initial={ "name": "Crowdfund Request: %s" % str(self.foia), "description": "Help cover the request fees needed to free these docs!", "payment_required": self.foia.get_stripe_amount(), "date_due": timezone.now() + timedelta(30), "foia": self.foia, } ) context["embargo_form"] = FOIAEmbargoForm( initial={ "permanent_embargo": self.foia.permanent_embargo, "date_embargo": self.foia.date_embargo, } ) context["fee_form"] = self.fee_form context["note_form"] = FOIANoteForm() context["portal_form"] = PortalForm(foia=self.foia) context["resend_forms"] = self.resend_forms context["tracking_id_form"] = TrackingNumberForm() # this data used in a form context["status_choices"] = [(k, v) for (k, v) in STATUS if k != "submitted"] context["user_actions"] = self.foia.user_actions( self.request.user, context["is_agency_user"] )
def grant_access(request, foia): """Grant editor access to the specified users.""" form = FOIAAccessForm(request.POST) has_perm = foia.has_perm(request.user, "change") if not has_perm or not form.is_valid(): return _get_redirect(request, foia) access = form.cleaned_data["access"] users = form.cleaned_data["users"] if access == "edit" and users: for user in users: foia.add_editor(user) if access == "view" and users: for user in users: foia.add_viewer(user) if len(users) > 1: success_msg = "%d people can now %s this request." % (len(users), access) else: success_msg = "%s can now %s this request." % ( users[0].profile.full_name, access, ) messages.success(request, success_msg) return _get_redirect(request, foia)
def get_context_data(self, **kwargs): """Add extra context data""" # pylint: disable=too-many-statements context = super(Detail, self).get_context_data(**kwargs) foia = context['foia'] user = self.request.user user_can_edit = foia.has_perm(self.request.user, 'change') user_can_embargo = foia.has_perm(self.request.user, 'embargo') is_past_due = foia.date_due < timezone.now().date( ) if foia.date_due else False context['all_tags'] = Tag.objects.all() context['past_due'] = is_past_due context['user_can_edit'] = user_can_edit context['user_can_pay'] = (foia.has_perm(self.request.user, 'pay') and foia.status == 'payment') context['embargo'] = { 'show': user_can_embargo or foia.embargo, 'edit': user_can_embargo, 'add': user_can_embargo, 'remove': user_can_edit and foia.embargo, } context['embargo_form'] = FOIAEmbargoForm( initial={ 'permanent_embargo': foia.permanent_embargo, 'date_embargo': foia.date_embargo }) context['note_form'] = FOIANoteForm() context['access_form'] = FOIAAccessForm() context['question_form'] = QuestionForm(user=user, initial={'foia': foia}) context['crowdfund_form'] = CrowdfundForm( initial={ 'name': u'Crowdfund Request: %s' % unicode(foia), 'description': 'Help cover the request fees needed to free these docs!', 'payment_required': foia.get_stripe_amount(), 'date_due': timezone.now() + timedelta(30), 'foia': foia }) context['embargo_needs_date'] = foia.status in END_STATUS context['user_actions'] = foia.user_actions(user) context['status_choices'] = STATUS context['show_estimated_date'] = foia.status not in [ 'submitted', 'ack', 'done', 'rejected' ] context['change_estimated_date'] = FOIAEstimatedCompletionDateForm( instance=foia) context['tracking_id_form'] = TrackingNumberForm() context['contact_info_form'] = ContactInfoForm(foia=foia) if user_can_edit or user.is_staff: all_tasks = Task.objects.filter_by_foia(foia, user) open_tasks = [task for task in all_tasks if not task.resolved] context['task_count'] = len(all_tasks) context['open_task_count'] = len(open_tasks) context['open_tasks'] = open_tasks context['asignees'] = User.objects.filter( is_staff=True, ).order_by('last_name') context['stripe_pk'] = settings.STRIPE_PUB_KEY context['sidebar_admin_url'] = reverse('admin:foia_foiarequest_change', args=(foia.pk, )) context['is_thankable'] = self.request.user.has_perm( 'foia.thank_foiarequest', foia) context['files'] = foia.get_files()[:50] if self.request.user.is_authenticated(): context['foia_cache_timeout'] = 0 else: context['foia_cache_timeout'] = settings.DEFAULT_CACHE_TIMEOUT context['settings'] = settings context['agency_status_choices'] = AGENCY_STATUS context['agency_reply_form'] = self.agency_reply_form context['admin_fix_form'] = self.admin_fix_form context['resend_forms'] = self.resend_forms context['cc_emails'] = json.dumps( [unicode(e) for e in foia.cc_emails.all()]) if (foia.composer.status == 'submitted' and foia.composer.datetime_submitted is not None): context['revoke_deadline'] = ( foia.composer.datetime_submitted + timedelta(seconds=COMPOSER_EDIT_DELAY)) context['can_revoke'] = foia.composer.revokable() if foia.sidebar_html: messages.info(self.request, foia.sidebar_html) return context