linkding/bookmarks/views/settings.py

36 lines
1.1 KiB
Python
Raw Normal View History

2019-07-05 08:04:52 +00:00
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
2019-07-05 17:26:46 +00:00
from bookmarks.services.importer import import_netscape_html
2019-07-05 08:04:52 +00:00
@login_required
2019-07-06 06:14:13 +00:00
def index(request):
2019-07-05 08:04:52 +00:00
import_message = _find_message_with_tag(messages.get_messages(request), 'bookmark_import')
return render(request, 'settings/index.html', {
'import_message': import_message
})
@login_required
2019-07-06 06:14:13 +00:00
def bookmark_import(request):
2019-07-05 08:04:52 +00:00
try:
import_file = request.FILES.get('import_file')
content = import_file.read()
import_netscape_html(content, request.user)
messages.success(request, 'Bookmarks were successfully imported.', 'bookmark_import')
except():
messages.error(request, 'An error occurred during bookmark import.', 'bookmark_import')
pass
return HttpResponseRedirect(reverse('bookmarks:settings_index'))
def _find_message_with_tag(messages, tag):
for message in messages:
if message.extra_tags == tag:
return message