コード例 #1
0
    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)
コード例 #2
0
ファイル: admin.py プロジェクト: okfde/froide-food
    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)
コード例 #3
0
    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')
コード例 #4
0
ファイル: admin.py プロジェクト: stefanw/froide
    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')
コード例 #5
0
ファイル: admin.py プロジェクト: JulianTenschert/froide
 def export_csv(self, request, queryset):
     return export_csv_response(User.export_csv(queryset))
コード例 #6
0
ファイル: admin.py プロジェクト: Alexander-Minyushkin/froide
 def export_csv(self, request, queryset):
     return export_csv_response(User.export_csv(queryset))
コード例 #7
0
 def export_csv(self, request, queryset):
     if not request.user.is_superuser:
         raise PermissionDenied
     return export_csv_response(User.export_csv(queryset))
コード例 #8
0
 def validate_publicbodies(self, request, queryset):
     csv_stream = dict_to_csv_stream(validate_publicbodies(queryset))
     return export_csv_response(csv_stream, name='validation.csv')
コード例 #9
0
 def export_csv(self, request, queryset):
     return export_csv_response(PublicBody.export_csv(queryset))
コード例 #10
0
ファイル: admin.py プロジェクト: stefanw/froide
 def export_csv(self, request, queryset):
     return export_csv_response(PublicBody.export_csv(queryset))
コード例 #11
0
 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))
コード例 #12
0
 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)