def _flag(self, request, foia): """Allow a user to notify us of a problem with the request""" form = FOIAFlagForm(request.POST) has_perm = foia.has_perm(request.user, 'flag') if has_perm and form.is_valid(): FlaggedTask.objects.create( user=request.user, foia=foia, text=form.cleaned_data['text'], category=form.cleaned_data['category'], ) messages.success(request, 'Problem succesfully reported') new_action(request.user, 'flagged', target=foia) return redirect(foia.get_absolute_url() + '#')
def flag(request, foia): """Allow a user to notify us of a problem with the request""" form = FOIAFlagForm(request.POST, all_choices=True) if form.is_valid(): FlaggedTask.objects.create( user=request.user if request.user.is_authenticated else None, foia=foia, text=form.cleaned_data["text"], category=form.cleaned_data["category"], ) messages.success(request, "Problem succesfully reported") if request.user.is_authenticated: new_action(request.user, "flagged", target=foia) return _get_redirect(request, foia)
def user_actions(self, user): """Provides action interfaces for users""" from muckrock.foia.forms import FOIAFlagForm, FOIAContactUserForm is_owner = self.created_by(user) is_agency_user = (user.is_authenticated() and user.profile.acct_type == 'agency') can_follow = (user.is_authenticated() and not is_owner and not is_agency_user) is_following = user.is_authenticated() and user in followers(self) is_admin = user.is_staff kwargs = { 'jurisdiction': self.jurisdiction.slug, 'jidx': self.jurisdiction.pk, 'idx': self.pk, 'slug': self.slug } clone_params = QueryDict('', mutable=True) clone_params['clone'] = self.composer.pk clone_params['agency'] = self.agency.pk return [ { 'test': not is_agency_user, 'link': '{}?{}'.format( reverse('foia-create'), clone_params.urlencode(), ), 'title': 'Clone', 'desc': 'Start a new request using this one as a base', 'class_name': 'primary', }, { 'test': can_follow, 'link': reverse('foia-follow', kwargs=kwargs), 'title': ('Unfollow' if is_following else 'Follow'), 'class_name': ('default' if is_following else 'primary'), }, { 'test': self.has_perm(user, 'zip_download'), 'link': '?zip_download=1', 'title': 'Download as Zip', 'desc': u'Download all communications and ' u'files as a zip archive', 'class_name': 'primary', }, { 'test': self.has_perm(user, 'flag'), 'title': 'Get Help', 'action': 'flag', 'desc': u'Something broken, buggy, or off? ' u'Let us know and we\'ll fix it', 'class_name': 'failure', 'modal': True, 'form': FOIAFlagForm(), }, { 'test': is_admin, 'title': 'Contact User', 'action': 'contact_user', 'desc': u'Send this request\'s owner an email', 'modal': True, 'form': FOIAContactUserForm(), }, ]