2023-08-20 04:27:23 +00:00
|
|
|
from django.conf import settings
|
2023-04-24 00:56:13 -04:00
|
|
|
from django.contrib import messages
|
2023-08-10 11:27:31 -04:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2023-08-20 04:27:23 +00:00
|
|
|
from django.db import connection
|
|
|
|
from django.http import JsonResponse
|
2023-02-04 00:45:17 -05:00
|
|
|
from django.shortcuts import redirect, render
|
2023-01-01 23:50:57 -05:00
|
|
|
from django.urls import reverse
|
2020-05-01 22:46:15 +08:00
|
|
|
|
2023-12-03 15:40:20 -05:00
|
|
|
from boofilsic import __version__
|
2023-08-20 04:27:23 +00:00
|
|
|
from users.models import User
|
|
|
|
|
2021-10-17 22:43:56 -04:00
|
|
|
|
2020-05-01 22:46:15 +08:00
|
|
|
@login_required
|
2023-05-20 11:01:18 -04:00
|
|
|
def me(request):
|
2023-09-03 20:11:46 +00:00
|
|
|
if not request.user.registration_complete:
|
|
|
|
return redirect(reverse("users:register"))
|
2023-07-20 21:59:49 -04:00
|
|
|
return redirect(request.user.identity.url)
|
2023-05-20 11:01:18 -04:00
|
|
|
|
|
|
|
|
2020-05-01 22:46:15 +08:00
|
|
|
def home(request):
|
2023-05-20 11:01:18 -04:00
|
|
|
if request.user.is_authenticated:
|
2023-09-03 20:11:46 +00:00
|
|
|
if not request.user.registration_complete:
|
|
|
|
return redirect(reverse("users:register"))
|
2023-08-10 11:27:31 -04:00
|
|
|
home = request.user.preference.classic_homepage
|
2023-05-20 11:01:18 -04:00
|
|
|
if home == 1:
|
2023-06-30 23:53:53 -04:00
|
|
|
return redirect(request.user.url)
|
2023-05-20 11:01:18 -04:00
|
|
|
elif home == 2:
|
|
|
|
return redirect(reverse("social:feed"))
|
|
|
|
else:
|
|
|
|
return redirect(reverse("catalog:discover"))
|
2022-05-30 22:48:11 -04:00
|
|
|
else:
|
2023-04-19 22:31:27 -04:00
|
|
|
return redirect(reverse("catalog:discover"))
|
2023-02-04 00:45:17 -05:00
|
|
|
|
|
|
|
|
2023-07-20 21:59:49 -04:00
|
|
|
def ap_redirect(request, uri):
|
|
|
|
return redirect(uri)
|
|
|
|
|
|
|
|
|
2023-08-20 04:27:23 +00:00
|
|
|
def nodeinfo2(request):
|
|
|
|
usage = {"users": {"total": User.objects.count()}}
|
|
|
|
# return estimated number of marks as posts, since count the whole table is slow
|
|
|
|
# TODO filter local with SQL function in https://wiki.postgresql.org/wiki/Count_estimate
|
|
|
|
with connection.cursor() as cursor:
|
|
|
|
cursor.execute(
|
2023-12-03 15:30:21 -05:00
|
|
|
"SELECT n_live_tup FROM pg_stat_all_tables WHERE relname = 'journal_shelflogentry';"
|
2023-08-20 04:27:23 +00:00
|
|
|
)
|
|
|
|
row = cursor.fetchone()
|
|
|
|
if row:
|
|
|
|
usage["localPosts"] = row[0]
|
|
|
|
return JsonResponse(
|
|
|
|
{
|
2023-08-21 21:46:51 +00:00
|
|
|
"version": "2.0",
|
2023-08-20 04:27:23 +00:00
|
|
|
"software": {
|
|
|
|
"name": "neodb",
|
2023-12-03 15:40:20 -05:00
|
|
|
"version": __version__,
|
2023-08-20 04:27:23 +00:00
|
|
|
"repository": "https://github.com/neodb-social/neodb",
|
|
|
|
"homepage": "https://neodb.net/",
|
|
|
|
},
|
|
|
|
"protocols": ["activitypub", "neodb"],
|
2023-12-03 15:30:21 -05:00
|
|
|
"openRegistrations": not settings.INVITE_ONLY,
|
2023-08-20 04:27:23 +00:00
|
|
|
"services": {"outbound": [], "inbound": []},
|
|
|
|
"usage": usage,
|
2023-12-03 15:40:20 -05:00
|
|
|
"metadata": {
|
|
|
|
"nodeName": settings.SITE_INFO["site_name"],
|
|
|
|
"nodeRevision": settings.NEODB_VERSION,
|
|
|
|
},
|
2023-08-20 04:27:23 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-02-04 00:45:17 -05:00
|
|
|
def error_400(request, exception=None):
|
2024-04-23 23:57:49 -04:00
|
|
|
return render(request, "400.html", status=400, context={"exception": exception})
|
2023-02-04 00:45:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
def error_403(request, exception=None):
|
2024-04-23 23:57:49 -04:00
|
|
|
return render(request, "403.html", status=403, context={"exception": exception})
|
2023-02-04 00:45:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
def error_404(request, exception=None):
|
2024-04-23 23:57:49 -04:00
|
|
|
return render(request, "404.html", status=404, context={"exception": exception})
|
2023-02-04 00:45:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
def error_500(request, exception=None):
|
2024-04-23 23:57:49 -04:00
|
|
|
return render(request, "500.html", status=500, context={"exception": exception})
|