diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 7141b2d9..98b973d7 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -63,6 +63,7 @@ INSTALLED_APPS = [ 'games.apps.GamesConfig', 'sync.apps.SyncConfig', 'collection.apps.CollectionConfig', + 'timeline.apps.TimelineConfig', 'easy_thumbnails', 'user_messages', 'django_slack', @@ -198,6 +199,11 @@ STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesSto AUTH_USER_MODEL = 'users.User' +SILENCED_SYSTEM_CHECKS = [ + "auth.W004", # User.username is non-unique + "admin.E404" # Required by django-user-messages +] + MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') diff --git a/common/management/commands/reindex.py b/common/management/commands/reindex.py index 125aac01..5dcc766f 100644 --- a/common/management/commands/reindex.py +++ b/common/management/commands/reindex.py @@ -18,11 +18,11 @@ BATCH_SIZE = 1000 class Command(BaseCommand): help = 'Regenerate the search index' - def add_arguments(self, parser): - parser.add_argument('hours', type=int, help='Re-index items modified in last N hours, 0 to reindex all') + # def add_arguments(self, parser): + # parser.add_argument('hours', type=int, help='Re-index items modified in last N hours, 0 to reindex all') def handle(self, *args, **options): - h = int(options['hours']) + # h = int(options['hours']) print(f'Connecting to search server') if Indexer.busy(): print('Please wait for previous updates') @@ -30,7 +30,7 @@ class Command(BaseCommand): # self.stdout.write(self.style.SUCCESS('Index settings updated.')) for c in [Book, Song, Album, Game, Movie]: print(f'Re-indexing {c}') - qs = c.objects.all() if h == 0 else c.objects.filter(edited_time__gt=timezone.now() - timedelta(hours=h)) + qs = c.objects.all() # if h == 0 else c.objects.filter(edited_time__gt=timezone.now() - timedelta(hours=h)) pg = Paginator(qs.order_by('id'), BATCH_SIZE) for p in tqdm(pg.page_range): items = list(map(lambda o: Indexer.obj_to_dict(o), pg.get_page(p).object_list)) diff --git a/doc/GUIDE.md b/doc/GUIDE.md index 89cb17d9..f6b095a7 100644 --- a/doc/GUIDE.md +++ b/doc/GUIDE.md @@ -77,6 +77,15 @@ python3 manage.py sass common/static/sass/boofilsic.sass common/static/css/boofi python3 manage.py collectstatic ``` +Index and Search +---------------- +Install TypeSense or Meilisearch, change `SEARCH_BACKEND` and coniguration for search server in `settings.py` + +Build initial index, it may take a few minutes or hours +``` +python3 manage.py init_index +python3 manage.py reindex +``` Other maintenance tasks ----------------------- diff --git a/mastodon/api.py b/mastodon/api.py index b3772432..dcab2e91 100644 --- a/mastodon/api.py +++ b/mastodon/api.py @@ -300,8 +300,12 @@ def get_mastodon_application(domain): error_msg = "实例返回内容无法识别" logger.error(f'Error creating app for {domain}: unable to parse response') else: - app = MastodonApplication.objects.create(domain_name=domain, app_id=data['id'], client_id=data['client_id'], + if settings.MASTODON_ALLOW_ANY_SITE: + app = MastodonApplication.objects.create(domain_name=domain, app_id=data['id'], client_id=data['client_id'], client_secret=data['client_secret'], vapid_key=data['vapid_key'] if 'vapid_key' in data else '') + else: + error_msg = "不支持其它实例登录" + logger.error(f'Disallowed to create app for {domain}') return app, error_msg diff --git a/requirements.txt b/requirements.txt index 2fbb8b7d..fce0825c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ dateparser -django~=3.2.15 +django~=3.2.14 django-hstore django-markdownx @ git+https://github.com/alphatownsman/django-markdownx.git@e69480c64ad9c5d0499f4a8625da78cf2bb7691b django-sass diff --git a/users/account.py b/users/account.py index 9cae3b58..6bc38e71 100644 --- a/users/account.py +++ b/users/account.py @@ -70,8 +70,6 @@ def login(request): # connect will redirect to mastodon server def connect(request): - if not settings.MASTODON_ALLOW_ANY_SITE: - return redirect(reverse("users:login")) login_domain = request.session['swap_domain'] if request.session.get('swap_login') else request.GET.get('domain') if not login_domain: return render(request, 'common/error.html', {'msg': '未指定实例域名', 'secondary_msg': "", }) diff --git a/users/data.py b/users/data.py index f296ffd7..505344c8 100644 --- a/users/data.py +++ b/users/data.py @@ -61,6 +61,7 @@ def preferences(request): @login_required def data(request): return render(request, 'users/data.html', { + 'allow_any_site': settings.MASTODON_ALLOW_ANY_SITE, 'latest_task': request.user.user_synctasks.order_by("-id").first(), 'import_status': request.user.get_preference().import_status, 'export_status': request.user.get_preference().export_status diff --git a/users/templates/users/data.html b/users/templates/users/data.html index 4677bc80..b0e62338 100644 --- a/users/templates/users/data.html +++ b/users/templates/users/data.html @@ -276,6 +276,7 @@ + {% if allow_any_site %}