|
1 | 1 | import os |
2 | 2 | import uuid |
3 | | -from datetime import timedelta |
4 | 3 |
|
5 | 4 | from django.conf import settings |
6 | 5 | from django.contrib import messages |
|
10 | 9 | from django.core.files.base import ContentFile |
11 | 10 | from django.core.files.storage import default_storage |
12 | 11 | from django.core.paginator import Paginator |
13 | | -from django.db.models import Case, Count, F, Q, Value, When |
| 12 | +from django.db.models import Case, F, Value, When |
14 | 13 | from django.http import Http404, HttpResponse, JsonResponse |
15 | 14 | from django.shortcuts import get_object_or_404, redirect, render |
16 | | -from django.utils import timezone |
17 | 15 | from django.utils.translation import gettext_lazy as _ |
18 | 16 | from django.views.decorators.http import require_http_methods |
19 | 17 | from martor.utils import LazyEncoder |
20 | 18 |
|
21 | 19 | from project.newsletter import operations |
22 | 20 | from project.newsletter.forms import PostForm, SubscriptionForm |
23 | | -from project.newsletter.models import Category, Post, Subscription |
| 21 | +from project.newsletter.models import Post, Subscription |
24 | 22 |
|
25 | 23 | LIST_POSTS_PAGE_SIZE = 100 |
26 | 24 |
|
@@ -187,83 +185,6 @@ def toggle_post_privacy(request, slug): |
187 | 185 | return redirect("newsletter:list_posts") |
188 | 186 |
|
189 | 187 |
|
190 | | -@staff_member_required(login_url=settings.LOGIN_URL) |
191 | | -@require_http_methods(["GET"]) |
192 | | -def analytics(request): |
193 | | - """ |
194 | | - The post detail view. |
195 | | - """ |
196 | | - now = timezone.now() |
197 | | - subscription_aggregates = Subscription.objects.all().aggregate( |
198 | | - subscriptions=Count("user", distinct=True, filter=Q(categories__isnull=False)), |
199 | | - subscriptions_30_days=Count( |
200 | | - "id", |
201 | | - filter=Q(categories__isnull=False, created__gte=now - timedelta(days=30)), |
202 | | - distinct=True, |
203 | | - ), |
204 | | - subscriptions_90_days=Count( |
205 | | - "id", |
206 | | - filter=Q(categories__isnull=False, created__gte=now - timedelta(days=90)), |
207 | | - distinct=True, |
208 | | - ), |
209 | | - subscriptions_180_days=Count( |
210 | | - "id", |
211 | | - filter=Q(categories__isnull=False, created__gte=now - timedelta(days=180)), |
212 | | - distinct=True, |
213 | | - ), |
214 | | - ) |
215 | | - subscription_category_aggregates = dict( |
216 | | - Category.objects.annotate(count=Count("subscriptions")) |
217 | | - .order_by("title") |
218 | | - .values_list("title", "count") |
219 | | - ) |
220 | | - post_aggregates = Post.objects.all().aggregate( |
221 | | - posts=Count("id"), |
222 | | - posts_30_days=Count( |
223 | | - "id", |
224 | | - filter=Q(created__gte=now - timedelta(days=30)), |
225 | | - ), |
226 | | - posts_90_days=Count( |
227 | | - "id", |
228 | | - filter=Q(created__gte=now - timedelta(days=90)), |
229 | | - ), |
230 | | - posts_180_days=Count( |
231 | | - "id", |
232 | | - filter=Q(created__gte=now - timedelta(days=180)), |
233 | | - ), |
234 | | - ) |
235 | | - post_category_aggregates = dict( |
236 | | - Category.objects.annotate(count=Count("posts")) |
237 | | - .order_by("title") |
238 | | - .values_list("title", "count") |
239 | | - ) |
240 | | - |
241 | | - return render( |
242 | | - request, |
243 | | - "staff/analytics.html", |
244 | | - { |
245 | | - "aggregates": { |
246 | | - "Subscriptions": subscription_aggregates["subscriptions"], |
247 | | - "Subscriptions (30 days)": subscription_aggregates[ |
248 | | - "subscriptions_30_days" |
249 | | - ], |
250 | | - "Subscriptions (90 days)": subscription_aggregates[ |
251 | | - "subscriptions_90_days" |
252 | | - ], |
253 | | - "Subscriptions (180 days)": subscription_aggregates[ |
254 | | - "subscriptions_180_days" |
255 | | - ], |
256 | | - "Posts": post_aggregates["posts"], |
257 | | - "Posts (30 days)": post_aggregates["posts_30_days"], |
258 | | - "Posts (90 days)": post_aggregates["posts_90_days"], |
259 | | - "Posts (180 days)": post_aggregates["posts_180_days"], |
260 | | - }, |
261 | | - "subscription_category_aggregates": subscription_category_aggregates, |
262 | | - "post_category_aggregates": post_category_aggregates, |
263 | | - }, |
264 | | - ) |
265 | | - |
266 | | - |
267 | 188 | @staff_member_required(login_url=settings.LOGIN_URL) |
268 | 189 | @require_http_methods(["POST"]) |
269 | 190 | def markdown_uploader(request): |
|
0 commit comments