mirror of
https://github.com/sissbruecker/linkding.git
synced 2025-08-13 21:49:26 +02:00
Implement basic bookmark page
This commit is contained in:
0
bookmarks/__init__.py
Normal file
0
bookmarks/__init__.py
Normal file
6
bookmarks/admin.py
Normal file
6
bookmarks/admin.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import Bookmark
|
||||
|
||||
admin.site.register(Bookmark)
|
5
bookmarks/apps.py
Normal file
5
bookmarks/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BookmarksConfig(AppConfig):
|
||||
name = 'bookmarks'
|
29
bookmarks/migrations/0001_initial.py
Normal file
29
bookmarks/migrations/0001_initial.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# Generated by Django 2.2.2 on 2019-06-26 11:39
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Bookmark',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('url', models.TextField()),
|
||||
('title', models.CharField(max_length=512)),
|
||||
('description', models.TextField()),
|
||||
('unread', models.BooleanField(default=True)),
|
||||
('date_added', models.DateTimeField()),
|
||||
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
0
bookmarks/migrations/__init__.py
Normal file
0
bookmarks/migrations/__init__.py
Normal file
15
bookmarks/models.py
Normal file
15
bookmarks/models.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class Bookmark(models.Model):
|
||||
url = models.TextField()
|
||||
title = models.CharField(max_length=512)
|
||||
description = models.TextField()
|
||||
unread = models.BooleanField(default=True)
|
||||
date_added = models.DateTimeField()
|
||||
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.title + ' (' + self.url[:30] + '...)'
|
1
bookmarks/templates/bookmarks/detail.html
Normal file
1
bookmarks/templates/bookmarks/detail.html
Normal file
@@ -0,0 +1 @@
|
||||
<h2>Edit bookmark {{ bookmark.id }}</h2>
|
22
bookmarks/templates/bookmarks/index.html
Normal file
22
bookmarks/templates/bookmarks/index.html
Normal file
@@ -0,0 +1,22 @@
|
||||
{% extends "bookmarks/layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Bookmarks</h2>
|
||||
<ul class="bookmark-list">
|
||||
{% for bookmark in bookmarks %}
|
||||
<li>
|
||||
<p>
|
||||
<a href="{{ bookmark.url }}" target="_blank">{{ bookmark.title }}</a>
|
||||
</p>
|
||||
{% if bookmark.description is not None %}
|
||||
<p>{{ bookmark.description }}</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
<a href="{% url 'bookmarks:detail' bookmark.id %}">Edit</a>
|
||||
<a href="{% url 'bookmarks:remove' bookmark.id %}"
|
||||
onclick="return confirm('Do you really want to delete this bookmark?')">Remove</a>
|
||||
</p>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endblock %}
|
16
bookmarks/templates/bookmarks/layout.html
Normal file
16
bookmarks/templates/bookmarks/layout.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>linkdings</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>linkdings</h1>
|
||||
</header>
|
||||
<div class="content">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
3
bookmarks/tests.py
Normal file
3
bookmarks/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
10
bookmarks/urls.py
Normal file
10
bookmarks/urls.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'bookmarks'
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('bookmark/<int:bookmark_id>', views.detail, name='detail'),
|
||||
path('bookmark/<int:bookmark_id>/remove', views.remove, name='remove'),
|
||||
]
|
31
bookmarks/views.py
Normal file
31
bookmarks/views.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from django.urls import reverse
|
||||
|
||||
from .models import Bookmark
|
||||
|
||||
|
||||
def index(request):
|
||||
context = {
|
||||
'bookmarks': Bookmark.objects.all()
|
||||
}
|
||||
return render(request, 'bookmarks/index.html', context)
|
||||
|
||||
|
||||
def create(request):
|
||||
return HttpResponse('OK')
|
||||
|
||||
|
||||
def detail(request, bookmark_id):
|
||||
context = {
|
||||
'bookmark': Bookmark.objects.get(bookmark_id)
|
||||
}
|
||||
return render(request, 'bookmarks/detail.html', context)
|
||||
|
||||
|
||||
def remove(request, bookmark_id: int):
|
||||
bookmark = Bookmark.objects.get(pk=bookmark_id)
|
||||
bookmark.delete()
|
||||
return HttpResponseRedirect(reverse('bookmarks:index'))
|
Reference in New Issue
Block a user