diff --git a/application/admin.py b/application/admin.py index 4e9212b..435c9ef 100644 --- a/application/admin.py +++ b/application/admin.py @@ -6,23 +6,23 @@ from django.contrib.auth.models import User from .models import Post, CustomUser + #external code customised #import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model +#start --- class CustomUserInline(admin.StackedInline): model = CustomUser can_delete = False verbose_name_plural = 'customUsers' -#external code customised -#import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model + # Define a new User admin class UserAdmin(BaseUserAdmin): inlines = (CustomUserInline, ) -#external code customised -#import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model + # Re-register UserAdmin admin.site.unregister(User) admin.site.register(User, UserAdmin) admin.site.register(Post) - +#end --- \ No newline at end of file diff --git a/application/forms.py b/application/forms.py index 9491cab..b43c3fc 100644 --- a/application/forms.py +++ b/application/forms.py @@ -6,6 +6,7 @@ from django.forms import ModelForm, ValidationError from taggit.forms import * + #extended code customised #import from https://tutorial.djangogirls.org/en/django_forms/ class PostForm(forms.ModelForm): diff --git a/application/models.py b/application/models.py index 3ec8911..95c7b73 100644 --- a/application/models.py +++ b/application/models.py @@ -1,24 +1,29 @@ from django.db import models + from django.contrib.auth.models import User from django.utils import timezone + from taggit.managers import TaggableManager from datetime import datetime -from croniter import croniter - +#external code customised +#import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model class CustomUser(models.Model): user = models.OneToOneField(User, null=True, on_delete=models.CASCADE) + #add tags to User Model with possibility to leave empty tags = TaggableManager(blank=True) + +#external code customised +#import from https://tutorial.djangogirls.org/en/django_models/ class Post(models.Model): author = models.ForeignKey('auth.User', on_delete=models.CASCADE) title = models.CharField(max_length=200) text = models.TextField() - created_date = models.DateTimeField( - default=timezone.now) - published_date = models.DateTimeField( - blank=True, null=True) + created_date = models.DateTimeField(default=timezone.now) + published_date = models.DateTimeField(blank=True, null=True) + #add tags to Post Model tags = TaggableManager() def publish(self): diff --git a/application/templates/base.html b/application/templates/base.html index 85e3555..67ee0d4 100644 --- a/application/templates/base.html +++ b/application/templates/base.html @@ -112,6 +112,7 @@ +
@@ -125,5 +126,4 @@ - \ No newline at end of file diff --git a/application/templates/post_detail.html b/application/templates/post_detail.html index 983d865..ea3a0d5 100644 --- a/application/templates/post_detail.html +++ b/application/templates/post_detail.html @@ -1,6 +1,12 @@ + {% extends 'base.html' %}{% block content %} {% load hitcount_tags %}
+ +
{% if post.published_date %}
@@ -8,7 +14,11 @@
{% else %} Publish + + {% endif %} {% if user.is_staff and user == post.author %} + + Bearbeiten @@ -18,6 +28,7 @@ {% endif %}

{{ post.title }}

{{ post.text|linebreaksbr }}

+

Tags: {% for tag in post.tags.all %} diff --git a/application/templates/post_draft_list.html b/application/templates/post_draft_list.html index 8b4f26a..a038531 100644 --- a/application/templates/post_draft_list.html +++ b/application/templates/post_draft_list.html @@ -1,5 +1,8 @@ + {% extends 'base.html' %} - {% block content %}

diff --git a/application/templates/post_edit.html b/application/templates/post_edit.html index d1b6f18..f206572 100644 --- a/application/templates/post_edit.html +++ b/application/templates/post_edit.html @@ -1,5 +1,8 @@ + {% extends 'base.html' %} - {% block content %}
diff --git a/application/templates/post_list.html b/application/templates/post_list.html index 06c5ec2..9f8a745 100644 --- a/application/templates/post_list.html +++ b/application/templates/post_list.html @@ -1,24 +1,31 @@ + {% extends 'base.html' %} {% block content %}
{% if tag %}

Artikel mit dem Tag "{{ tag.name }}"

{% endif %}
+

Artikleübersicht

-
+ +
- - {% if messages %} + {% if messages %}
{% for message in messages %}

{{ message }}

{% endfor %}
+ + {% endif %} {% for post in posts %}
@@ -29,6 +36,8 @@ {{ post.title }}

{{ post.text|linebreaks }}

+ + Tags: {% for tag in post.tags.all %} {{ tag.name }} {% if not forloop.last %}, {% endif %} {% endfor %}

diff --git a/application/templates/search_add.html b/application/templates/search_add.html index 488d72d..7caab96 100644 --- a/application/templates/search_add.html +++ b/application/templates/search_add.html @@ -1,8 +1,14 @@ + {% extends "base.html" %} {% block content %} + + {% load taggit_templatetags2_tags %}

-
+

Alle Tags im Überblick

@@ -11,6 +17,8 @@ {% include_tagcloud 'application.Post' %}
+ +
Tag-Suche @@ -43,7 +51,6 @@ {% endfor %}
-

Bereits abonnierten Tags @@ -54,14 +61,12 @@ {% for tag in tagsuser %} {{ tag.name }} {% endfor %} -

{% endif %}
-
Abonniere deine Tags hier!
@@ -69,7 +74,6 @@ {% csrf_token %} {{form.as_p}} - {% if messages %} {% for message in messages %}
{{ message }}
diff --git a/application/templates/tag_list.html b/application/templates/tag_list.html index c84d2da..afeb9dc 100644 --- a/application/templates/tag_list.html +++ b/application/templates/tag_list.html @@ -1,3 +1,7 @@ + {% extends "base.html" %} {% block content %} {% load taggit_templatetags2_tags %}
@@ -10,6 +14,8 @@
+ + {% for post in posts %}
@@ -18,6 +24,8 @@

{{ post.title }}

+ +

{{ post.text|linebreaks }}

Tags: {% for tag in post.tags.all %} {{ tag.name }} @@ -34,6 +42,5 @@
-
{% endblock %} \ No newline at end of file diff --git a/application/templates/tag_remove.html b/application/templates/tag_remove.html deleted file mode 100644 index 11a97bd..0000000 --- a/application/templates/tag_remove.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends 'base.html' %} {% block content %} -{% if tag %} Posts tagged with "{{ tag.name }}" {% endif %} -{% for post in posts %} -
-
- {{ post.published_date }} -
-

- {{ post.title }} -

-

{{ post.text|linebreaks }}

- Tags: {% for tag in post.tags.all %} - {{ tag.name }} - {% if not forloop.last %}, {% endif %} {% endfor %}

- {{ post.author }} -

-
-{% endfor %} -
-{% endblock %} \ No newline at end of file diff --git a/application/urls.py b/application/urls.py index 4e0bfb9..843dcc5 100644 --- a/application/urls.py +++ b/application/urls.py @@ -8,8 +8,6 @@ from . import views from taggit_templatetags2 import urls as taggit_templatetags2_urls import debug_toolbar - - urlpatterns = [ url(r'^$', views.tag_list, name='tag_list'), url(r'^tag/(?P[-\w]+)/$', views.post_list, name='post_list_by_tag'), @@ -25,7 +23,6 @@ urlpatterns = [ url(r'^tags/', include('taggit_templatetags2.urls')), ] - #external code #import from https://django-debug-toolbar.readthedocs.io/en/latest/installation.html if settings.DEBUG: diff --git a/application/views.py b/application/views.py index 99f101d..9710fc9 100644 --- a/application/views.py +++ b/application/views.py @@ -1,28 +1,21 @@ -from django.shortcuts import render, get_object_or_404 -from django.utils import timezone -from .models import Post, CustomUser -from taggit.models import Tag -from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger -from .forms import PostForm, NewTagForm -from django.shortcuts import redirect -from django.contrib.auth.decorators import login_required -from django.contrib.admin.views.decorators import staff_member_required -from django.contrib.auth import authenticate, login, logout -import sys -import collections -from taggit_templatetags2.views import TagCanvasListView -from django.contrib.auth.models import User -from django.contrib import messages -from post_office.models import EmailTemplate -from post_office import mail - -from hitcount.models import HitCount -from hitcount.views import HitCountMixin - - import logging import mysite.settings -import operator + +from django.shortcuts import render, get_object_or_404 +from django.contrib.auth import authenticate, login, logout +from django.contrib.auth.decorators import login_required +from django.shortcuts import redirect +from django.utils import timezone +from django.contrib.admin.views.decorators import staff_member_required +from django.contrib.auth.models import User + +from .models import Post, CustomUser +from taggit.models import Tag +from .forms import PostForm, NewTagForm +from django.contrib import messages +from post_office import mail +from hitcount.models import HitCount +from hitcount.views import HitCountMixin def navlogin(request): @@ -47,7 +40,9 @@ def navlogin(request): context = {'error': error} return render(request, 'index.html', context) - +#external code customised +#import from https://tutorial.djangogirls.org/en/django_forms/ +#start --- @login_required def post_list(request, slug=None): log = logging.getLogger('mysite') @@ -122,7 +117,7 @@ def post_remove(request, pk): messages.info(request, 'Der Artikel "' + post.title + '" wurde gelöscht') post.delete() return redirect('post_list') - +#end --- @login_required def tag_list(request): @@ -165,8 +160,12 @@ def search_add(request): form = NewTagForm() return render(request, 'search_add.html', locals()) + +#external code customised +#import from https://github.com/ui/django-post_office mail.send( - 'kleinhenz.e@gmail.com', # List of email addresses also accepted + # List of email addresses also accepted + 'kleinhenz.e@gmail.com', 'esther.kleinhenz@web.de', subject='My email', message='Hi there!', diff --git a/log.txt b/log.txt index da17191..922c4b9 100644 --- a/log.txt +++ b/log.txt @@ -447,3 +447,13 @@ [07/Dec/2018 19:55:08] INFO [mysite:147] , , , , , ]> [07/Dec/2018 19:55:08] INFO [mysite:147] [07/Dec/2018 19:55:08] INFO [mysite:147] , , , ]> +[09/Dec/2018 19:06:28] INFO [mysite:128] , , , ]> +[09/Dec/2018 19:06:29] INFO [mysite:131] , , ]> +[09/Dec/2018 19:06:29] INFO [mysite:131] , , , , , ]> +[09/Dec/2018 19:06:29] INFO [mysite:131] +[09/Dec/2018 19:06:29] INFO [mysite:131] , , , ]> +[09/Dec/2018 19:20:36] INFO [mysite:128] , , , ]> +[09/Dec/2018 19:20:37] INFO [mysite:131] , , ]> +[09/Dec/2018 19:20:37] INFO [mysite:131] , , , , , ]> +[09/Dec/2018 19:20:37] INFO [mysite:131] +[09/Dec/2018 19:20:37] INFO [mysite:131] , , , ]> diff --git a/mysite/settings.py b/mysite/settings.py index b31a053..93c534a 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -176,7 +176,11 @@ else: AUTH_PROFILE_MODULE = 'application.CustomUser' + #Log Configuration +#external code +#import form https://docs.djangoproject.com/en/2.1/topics/logging/ + LOGGING = { 'version': 1, 'disable_existing_loggers': True, @@ -224,6 +228,9 @@ LOGGING = { } } +#Logging Addon +#external code +#import from https://django-debug-toolbar.readthedocs.io/en/latest/installation.html if DEBUG: INTERNAL_IPS = ('127.0.0.1', 'localhost',) @@ -254,8 +261,11 @@ if DEBUG: 'INTERCEPT_REDIRECTS': False, } -EMAIL_BACKEND = 'post_office.EmailBackend' +#E-Mail administration +#external code customised +#import from https://github.com/ui/django-post_office +EMAIL_BACKEND = 'post_office.EmailBackend' EMAIL_HOST = 'smtp.web.de' EMAIL_HOST_USER = "esther.kleinhenz@web.de" EMAIL_PORT = 25 # default smtp port diff --git a/mysite/urls.py b/mysite/urls.py index 4d03099..547ffc8 100644 --- a/mysite/urls.py +++ b/mysite/urls.py @@ -17,7 +17,6 @@ from django.contrib import admin from django.conf.urls import include, url from django.views.generic import TemplateView - from django.contrib.auth import views import application.views