From fc2794aa61e6167c26f7ef35474ecdd2abc0c525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Thu, 27 Jun 2019 08:09:51 +0200 Subject: [PATCH] Implement basic bookmark page --- .gitignore | 161 ++++++++++++++++++++++ .idea/compiler.xml | 15 ++ .idea/dataSources.xml | 14 ++ .idea/encodings.xml | 4 + .idea/misc.xml | 10 ++ .idea/modules.xml | 8 ++ bookmarks/__init__.py | 0 bookmarks/admin.py | 6 + bookmarks/apps.py | 5 + bookmarks/migrations/0001_initial.py | 29 ++++ bookmarks/migrations/__init__.py | 0 bookmarks/models.py | 15 ++ bookmarks/templates/bookmarks/detail.html | 1 + bookmarks/templates/bookmarks/index.html | 22 +++ bookmarks/templates/bookmarks/layout.html | 16 +++ bookmarks/tests.py | 3 + bookmarks/urls.py | 10 ++ bookmarks/views.py | 31 +++++ linkdings.iml | 34 +++++ manage.py | 21 +++ requirements.txt | 3 + siteroot/__init__.py | 0 siteroot/settings.py | 121 ++++++++++++++++ siteroot/urls.py | 22 +++ siteroot/wsgi.py | 16 +++ 25 files changed, 567 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/dataSources.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 bookmarks/__init__.py create mode 100644 bookmarks/admin.py create mode 100644 bookmarks/apps.py create mode 100644 bookmarks/migrations/0001_initial.py create mode 100644 bookmarks/migrations/__init__.py create mode 100644 bookmarks/models.py create mode 100644 bookmarks/templates/bookmarks/detail.html create mode 100644 bookmarks/templates/bookmarks/index.html create mode 100644 bookmarks/templates/bookmarks/layout.html create mode 100644 bookmarks/tests.py create mode 100644 bookmarks/urls.py create mode 100644 bookmarks/views.py create mode 100644 linkdings.iml create mode 100755 manage.py create mode 100644 requirements.txt create mode 100644 siteroot/__init__.py create mode 100644 siteroot/settings.py create mode 100644 siteroot/urls.py create mode 100644 siteroot/wsgi.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..459b73b --- /dev/null +++ b/.gitignore @@ -0,0 +1,161 @@ +# Created by .ignore support plugin (hsz.mobi) +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/dictionaries +.idea/**/shelf + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ +cmake-build-release/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +polls diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..40ed937 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..c61958a --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,14 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/db.sqlite3 + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d09bbac --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + /usr/local/bin/ghc + /usr/local/bin/stack + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3ee3a1e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/bookmarks/__init__.py b/bookmarks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bookmarks/admin.py b/bookmarks/admin.py new file mode 100644 index 0000000..743e7f5 --- /dev/null +++ b/bookmarks/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +# Register your models here. +from .models import Bookmark + +admin.site.register(Bookmark) diff --git a/bookmarks/apps.py b/bookmarks/apps.py new file mode 100644 index 0000000..db791ce --- /dev/null +++ b/bookmarks/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class BookmarksConfig(AppConfig): + name = 'bookmarks' diff --git a/bookmarks/migrations/0001_initial.py b/bookmarks/migrations/0001_initial.py new file mode 100644 index 0000000..5036fdc --- /dev/null +++ b/bookmarks/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/bookmarks/migrations/__init__.py b/bookmarks/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bookmarks/models.py b/bookmarks/models.py new file mode 100644 index 0000000..fc0b84b --- /dev/null +++ b/bookmarks/models.py @@ -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] + '...)' diff --git a/bookmarks/templates/bookmarks/detail.html b/bookmarks/templates/bookmarks/detail.html new file mode 100644 index 0000000..fc9203e --- /dev/null +++ b/bookmarks/templates/bookmarks/detail.html @@ -0,0 +1 @@ +

Edit bookmark {{ bookmark.id }}

diff --git a/bookmarks/templates/bookmarks/index.html b/bookmarks/templates/bookmarks/index.html new file mode 100644 index 0000000..5018909 --- /dev/null +++ b/bookmarks/templates/bookmarks/index.html @@ -0,0 +1,22 @@ +{% extends "bookmarks/layout.html" %} + +{% block content %} +

Bookmarks

+ +{% endblock %} diff --git a/bookmarks/templates/bookmarks/layout.html b/bookmarks/templates/bookmarks/layout.html new file mode 100644 index 0000000..1ccffcf --- /dev/null +++ b/bookmarks/templates/bookmarks/layout.html @@ -0,0 +1,16 @@ + + + + + linkdings + + +
+

linkdings

+
+
+ {% block content %} + {% endblock %} +
+ + diff --git a/bookmarks/tests.py b/bookmarks/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/bookmarks/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/bookmarks/urls.py b/bookmarks/urls.py new file mode 100644 index 0000000..3ee10ac --- /dev/null +++ b/bookmarks/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from . import views + +app_name = 'bookmarks' +urlpatterns = [ + path('', views.index, name='index'), + path('bookmark/', views.detail, name='detail'), + path('bookmark//remove', views.remove, name='remove'), +] diff --git a/bookmarks/views.py b/bookmarks/views.py new file mode 100644 index 0000000..38c29a9 --- /dev/null +++ b/bookmarks/views.py @@ -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')) diff --git a/linkdings.iml b/linkdings.iml new file mode 100644 index 0000000..613ffc2 --- /dev/null +++ b/linkdings.iml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..dcb27ee --- /dev/null +++ b/manage.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'siteroot.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..111e4d9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Django==2.2.2 +pytz==2019.1 +sqlparse==0.3.0 diff --git a/siteroot/__init__.py b/siteroot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/siteroot/settings.py b/siteroot/settings.py new file mode 100644 index 0000000..feb20e0 --- /dev/null +++ b/siteroot/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for siteroot project. + +Generated by 'django-admin startproject' using Django 2.2.2. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'kgq$h3@!!vbb6*nzfz(dbze=*)zsroqa8gvc0#1gx$3cd8z99^' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'bookmarks.apps.BookmarksConfig', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'siteroot.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'siteroot.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.2/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/siteroot/urls.py b/siteroot/urls.py new file mode 100644 index 0000000..cf3b1d8 --- /dev/null +++ b/siteroot/urls.py @@ -0,0 +1,22 @@ +"""siteroot URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('bookmarks/', include('bookmarks.urls')), + path('admin/', admin.site.urls), +] diff --git a/siteroot/wsgi.py b/siteroot/wsgi.py new file mode 100644 index 0000000..fe2488b --- /dev/null +++ b/siteroot/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for siteroot project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'siteroot.settings') + +application = get_wsgi_application()