def export_users(self, request): if not request.method == 'GET': raise PermissionDenied if not request.user.is_superuser: raise PermissionDenied fr_ids = set( VenueRequestItem.objects.filter( timestamp__year__gte=2019).values_list('foirequest_id', flat=True)) # -first_message, so last value overwrites user_id first_req_timestamp = dict( FoiRequest.objects.filter( id__in=fr_ids).order_by('-first_message').values_list( 'user_id', 'first_message')) queryset = User.objects.filter( id__in=list(first_req_timestamp.keys()), is_active=True, date_joined__year__gte=2019, ) def generator(queryset): for u in queryset: f = u.foirequest_set.all().order_by('first_message')[0] if f.id not in fr_ids: continue diff = abs((first_req_timestamp[u.id] - u.date_joined).seconds) if diff < 2: yield u fields = ('id', "first_name", "last_name", "email", 'date_joined') stream = User.export_csv(generator(queryset), fields=fields) return export_csv_response(stream)
def export_users(self, request): if not request.method == "GET": raise PermissionDenied if not request.user.is_superuser: raise PermissionDenied four_months_ago = timezone.now() - timedelta(days=4 * 31) queryset = User.objects.filter( is_active=True, tags__in=UserTag.objects.filter(slug="food-first"), date_joined__gte=four_months_ago, ) fields = ("id", "first_name", "last_name", "email", "date_joined") stream = User.export_csv(queryset, fields=fields) return export_csv_response(stream)
def export_csv(self, request, queryset): from froide.publicbody.models import PublicBody def get_stream(queryset): for tag in queryset: pbs = PublicBody.objects.filter( send_messages__tags=tag).annotate( tag_count=models.Count('send_messages', filter=models.Q( send_messages__tags=tag))) for pb in pbs: yield { 'tag': tag.name, 'publicbody_id': pb.id, 'publicbody_name': pb.name, 'tag_count': pb.tag_count } csv_stream = dict_to_csv_stream(get_stream(queryset)) return export_csv_response(csv_stream, name='tag_stats.csv')
def export_csv(self, request, queryset): from froide.publicbody.models import PublicBody def get_stream(queryset): for tag in queryset: pbs = PublicBody.objects.filter( send_messages__tags=tag ).annotate( tag_count=models.Count( 'send_messages', filter=models.Q( send_messages__tags=tag ) ) ) for pb in pbs: yield { 'tag': tag.name, 'publicbody_id': pb.id, 'publicbody_name': pb.name, 'tag_count': pb.tag_count } csv_stream = dict_to_csv_stream(get_stream(queryset)) return export_csv_response(csv_stream, name='tag_stats.csv')
def export_csv(self, request, queryset): return export_csv_response(User.export_csv(queryset))
def export_csv(self, request, queryset): if not request.user.is_superuser: raise PermissionDenied return export_csv_response(User.export_csv(queryset))
def validate_publicbodies(self, request, queryset): csv_stream = dict_to_csv_stream(validate_publicbodies(queryset)) return export_csv_response(csv_stream, name='validation.csv')
def export_csv(self, request, queryset): return export_csv_response(PublicBody.export_csv(queryset))
def export_subscribers_csv(self, request, queryset): fields = ( "id", "email_field", "name_field", "newsletter_id", "user_id", "subscribed", "subscribe_date", ) return export_csv_response(export_csv(queryset, fields))
def export_csv(self, request, queryset): queryset = queryset.select_related('foirequest', 'publicbody') csv_generator = InformationObject.objects.export_csv(queryset) return export_csv_response(csv_generator)