make nicedb work
This commit is contained in:
parent
d4c1a00f15
commit
e4e150b6b1
9 changed files with 34 additions and 33 deletions
|
@ -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/')
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
-----------------------
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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': "", })
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -276,6 +276,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{% if allow_any_site %}
|
||||
<div class="main-section-wrapper">
|
||||
<div class="tools-section-wrapper">
|
||||
<div class="import-panel">
|
||||
|
@ -295,6 +296,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="main-section-wrapper">
|
||||
<div class="tools-section-wrapper">
|
||||
|
|
|
@ -58,8 +58,9 @@
|
|||
<div>
|
||||
{% if user.is_authenticated %}
|
||||
<a href="{% url 'common:home' %}" class="button">{% trans '前往首页' %}</a>
|
||||
{% elif allow_any_site %}
|
||||
{% else %}
|
||||
<form action="/users/connect">
|
||||
{% if allow_any_site %}
|
||||
<input type="search" name="domain" id="domain"
|
||||
pattern="(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,})"
|
||||
title="实例域名(不含@和@之前的部分),如mastodon.social"
|
||||
|
@ -67,38 +68,18 @@
|
|||
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" />
|
||||
<input type='submit' value="{% trans '授权登录' %}" id="loginButton" disabled />
|
||||
<br><a target="_blank" href="https://about.neodb.social/doc/howto/">{% trans '了解更多' %}</a>
|
||||
</form>
|
||||
<script type="text/javascript">if (Cookies.get('mastodon_domain')) $('#domain').val(Cookies.get('mastodon_domain'));</script>
|
||||
{% else %}
|
||||
<select name="sites" id="sitesSelect" placeholder="test">
|
||||
<select name="domain" placeholder="test">
|
||||
{% for site in sites %}
|
||||
<option value="{{ site.domain_name }}" data-client-id="{{ site.client_id }}">@{{ site.domain_name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button name='login'>{% trans '授权登录' %}</button>
|
||||
<input type='submit' value="{% trans '授权登录' %}" id="loginButton" />
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
<div class="delayed">网页加载超时,请检查网络(翻墙)设置。</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if not user.is_authenticated and not allow_any_site %}
|
||||
<script>
|
||||
{% if selected_site %}
|
||||
$("#sitesSelect").val("{{ selected_site }}");
|
||||
{% else %}
|
||||
$("#sitesSelect").val($("#sitesSelect option:first").val());
|
||||
{% endif %}
|
||||
$("button[name=login]").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
let selected = $("#sitesSelect").find(":selected");
|
||||
let client_id = selected.data("client-id");
|
||||
let domain = selected.val();
|
||||
|
||||
Cookies.set('mastodon_domain', domain);
|
||||
location.href = "https://" + domain + "/oauth/authorize?client_id=" + client_id +
|
||||
"&scope={{ scope }}&redirect_uri={{ request.scheme }}://{{ request.get_host }}{% url 'users:OAuth2_login' %}" +
|
||||
"&response_type=code";
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue