diff --git a/.gitignore b/.gitignore index bb46421..ee7dc05 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,31 @@ links/__pycache__/ staticfiles/ -# to build +# to build # cd new_theme/static_src && npm run build -new_theme/static/css/dist/* \ No newline at end of file +new_theme/static/css/dist/* + +# Xcode +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +*.xcworkspace/* +!*.xcworkspace/contents.xcworkspacedata +!*.xcworkspace/xcshareddata/ + +# User-specific Xcode files +*.xcuserstate +*.xcuserdatad/ +*.xcuserdata/ + +# Xcode build artifacts +build/ +DerivedData/ + +# Xcode Patch +*.xcodeproj.orig + +# Swift Package Manager +.swiftpm/ +.build/ diff --git a/links/urls.py b/links/urls.py index dcc6d34..22d0d22 100644 --- a/links/urls.py +++ b/links/urls.py @@ -23,7 +23,6 @@ urlpatterns = [ path('ui/tools/', views.ToolsView.as_view(), name='tools'), path('tools/export-database/', views.export_database, name='export_database'), path('ui/help/', views.HelpView.as_view(), name='help'), - path('export/', views.export_links, name='export_links'), # Pages path('ui/pages/', page_views.PageListView.as_view(), name='page-list'), diff --git a/links/views.py b/links/views.py index 5be7768..7cb0044 100644 --- a/links/views.py +++ b/links/views.py @@ -14,6 +14,7 @@ from django.utils.translation import gettext as _ from django.core.exceptions import ValidationError from django.http import JsonResponse, HttpResponse from django.core.serializers import serialize +from django.utils.dateparse import parse_datetime import random from django.utils.text import slugify import markdown @@ -400,8 +401,30 @@ class ToolsView(View): def post(self, request): if 'export' in request.POST: - links = Link.objects.all().values('alias', 'original_url', 'created_at', 'updated_at') - response = HttpResponse(json.dumps(list(links), cls=DjangoJSONEncoder), content_type='application/json') + links = Link.objects.prefetch_related('tags').all() + + formatted_data = [] + for link in links: + # Get all tag names for this link + tag_names = [tag.name for tag in link.tags.all()] + + # Build the basic link data + link_data = { + 'alias': link.alias, + 'original_url': link.original_url, + 'link_type': link.link_type, + 'created_at': link.created_at.isoformat() if link.created_at else None, + 'updated_at': link.updated_at.isoformat() if link.updated_at else None, + 'tags': tag_names + } + + # For custom types, include the text field (markdown content) + if link.link_type == Link.LinkType.CUSTOM and link.text: + link_data['text'] = link.text + + formatted_data.append(link_data) + + response = HttpResponse(json.dumps(formatted_data, indent=2), content_type='application/json') response['Content-Disposition'] = 'attachment; filename="links_export.json"' return response elif 'import' in request.POST: @@ -439,26 +462,6 @@ class ToolsView(View): return render(request, self.template_name) -def export_links(request): - links = Link.objects.all() - data = serialize('json', links, fields=('alias', 'original_url', 'created_at', 'updated_at')) - - # 将序列化的数据转换为更易读的格式 - parsed_data = json.loads(data) - formatted_data = [ - { - 'alias': item['fields']['alias'], - 'original_url': item['fields']['original_url'], - 'created_at': item['fields']['created_at'], - 'updated_at': item['fields']['updated_at'] - } - for item in parsed_data - ] - - response = HttpResponse(json.dumps(formatted_data, indent=2), content_type='application/json') - response['Content-Disposition'] = 'attachment; filename="links_export.json"' - return response - class CustomLinkView(DetailView): model = Link template_name = 'links/custom_link.html'