Browse Source

beautifed code and added descriptive comments

master
Esther Kleinhenz 2 years ago
parent
commit
faaa66aa8e

+ 5
- 5
application/admin.py View File

@@ -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 ---

+ 1
- 0
application/forms.py View File

@@ -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):

+ 11
- 6
application/models.py View File

@@ -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):

+ 1
- 1
application/templates/base.html View File

@@ -112,6 +112,7 @@
</div>
</nav>

<!-- Content -->
<div class="content container">
<div class="row">
<div class="col-md-12">
@@ -125,5 +126,4 @@
<script src="{% static 'js/app.js' %}"></script>
<script src="{% static 'bootstrap/js/bootstrap.bundle.js' %}"></script>
</body>

</html>

+ 11
- 0
application/templates/post_detail.html View File

@@ -1,6 +1,12 @@
<!--
marked parts of the template is external code
import from https://tutorial.djangogirls.org/en/template_extending/
-->
{% extends 'base.html' %}{% block content %}
{% load hitcount_tags %}
<div class="col-md-8">

<!-- imported start -->
<div class="post">
{% if post.published_date %}
<div class="date">
@@ -8,7 +14,11 @@
</div>
{% else %}
<a class="btn btn-outline-dark" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
<!-- imported end -->

{% endif %} {% if user.is_staff and user == post.author %}

<!-- imported start -->
<a class="btn btn-outline-dark" href="{% url 'post_edit' pk=post.pk %}">
<span class="glyphicon glyphicon-pencil">Bearbeiten</span>
</a>
@@ -18,6 +28,7 @@
{% endif %}
<h1>{{ post.title }}</h1>
<p>{{ post.text|linebreaksbr }}</p>
<!-- imported end -->
<p>
Tags:
{% for tag in post.tags.all %}

+ 4
- 1
application/templates/post_draft_list.html View File

@@ -1,5 +1,8 @@
<!--
external code
import from https://tutorial.djangogirls.org/en/template_extending/
-->
{% extends 'base.html' %}

{% block content %}
<div class="row">
<div class="col-md-8">

+ 4
- 1
application/templates/post_edit.html View File

@@ -1,5 +1,8 @@
<!--
external code
import from https://tutorial.djangogirls.org/en/template_extending/
-->
{% extends 'base.html' %}

{% block content %}
<div class="row">
<div class="mx-auto">

+ 12
- 3
application/templates/post_list.html View File

@@ -1,24 +1,31 @@
<!--
marked parts of the template is external code
import from https://tutorial.djangogirls.org/en/template_extending/
-->
{% extends 'base.html' %} {% block content %}
<div class="row">
{% if tag %} <div class="mx-auto">
<h2> Artikel mit dem Tag "{{ tag.name }}" </h2>
</div>{% endif %}
</div>
<!-- imported start -->
<div class="row">
<div class="mx-auto">
<h1> Artikleübersicht </h1>
</div>
</div>
</div>
<!-- imported end -->

<div class="row">
<div class="col-md-8">

{% if messages %}
{% if messages %}
<div class="messages">
{% for message in messages %}
<p {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}</p>
{% endfor %}
</div>

<!-- imported start -->
{% endif %}
{% for post in posts %}
<div class="mt-5 post">
@@ -29,6 +36,8 @@
<a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a>
</h2>
<p>{{ post.text|linebreaks }}</p>
<!-- imported end -->

Tags: {% for tag in post.tags.all %}
<a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a>
{% if not forloop.last %}, {% endif %} {% endfor %} <p>

+ 9
- 5
application/templates/search_add.html View File

@@ -1,8 +1,14 @@
<!--
marked parts of the template is external code
import from https://github.com/fizista/django-taggit-templatetags2
-->
{% extends "base.html" %} {% block content %}

<!-- imported start -->
{% load taggit_templatetags2_tags %}
<div class="container">
<div class="row equal">
<div class="col-md-6" >
<div class="col-md-6">
<h1> Alle Tags im Überblick<br>
</h1>
<div class="col-md-8" style="zoom: 1.6">
@@ -11,6 +17,8 @@
{% include_tagcloud 'application.Post' %}
</div>
</div>
<!-- imported end -->

<div style="padding-bottom:40px;">
</div>
Tag-Suche
@@ -43,7 +51,6 @@
{% endfor %}
</div>
</div>

</div>
<div class="col-md-6">
<h1> Bereits abonnierten Tags
@@ -54,14 +61,12 @@
{% for tag in tagsuser %}
<a class="text-white bg-dark p-3" href="{% url 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a>
{% endfor %}

</div>
{% endif %}
</div>
<div style="padding-bottom:145px;">
</div>
<div class="mx-auto">

<div>
Abonniere deine Tags hier!
</div>
@@ -69,7 +74,6 @@
{% csrf_token %} {{form.as_p}}
<button type="submit" class="save btn btn-outline-dark">Sichern</button>
</form>

{% if messages %}
{% for message in messages %}
<div {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}</div>

+ 8
- 1
application/templates/tag_list.html View File

@@ -1,3 +1,7 @@
<!--
marked parts of the template is external code
import from https://tutorial.djangogirls.org/en/template_extending/
-->
{% extends "base.html" %} {% block content %}
{% load taggit_templatetags2_tags %}
<div class="row">
@@ -10,6 +14,8 @@
<div class="row">
<div class="col-md-8">
<div>

<!-- imported start -->
{% for post in posts %}
<div class="mt-5 post">
<div class="date">
@@ -18,6 +24,8 @@
<h2>
<a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a>
</h2>
<!-- imported end -->

<p>{{ post.text|linebreaks }}</p>
Tags: {% for tag in post.tags.all %}
<a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a>
@@ -34,6 +42,5 @@
</a>
</div>
</div>

</div>
{% endblock %}

+ 0
- 20
application/templates/tag_remove.html View File

@@ -1,20 +0,0 @@
{% extends 'base.html' %} {% block content %}
{% if tag %} Posts tagged with "{{ tag.name }}" {% endif %}
{% for post in posts %}
<div class="post">
<div class="date">
{{ post.published_date }}
</div>
<h1>
<a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a>
</h1>
<p>{{ post.text|linebreaks }}</p>
Tags: {% for tag in post.tags.all %}
<a href="{% url 'student_page_remove' tag.slug %}">{{ tag.name }}</a>
{% if not forloop.last %}, {% endif %} {% endfor %} <p>
{{ post.author }}
</p>
</div>
{% endfor %}
</div>
{% endblock %}

+ 0
- 3
application/urls.py View File

@@ -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<slug>[-\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:

+ 18
- 19
application/views.py View File

@@ -1,30 +1,23 @@
import logging
import mysite.settings

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 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


def navlogin(request):
log = logging.getLogger('mysite')
logout(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!',

+ 10
- 0
log.txt View File

@@ -447,3 +447,13 @@
[07/Dec/2018 19:55:08] INFO [mysite:147] <QuerySet [<Post: Kein bisschen Fränkisch>, <Post: Das ist ein Titel>, <Post: Strange Things>, <Post: Hier kommt was neues>, <Post: Bavaria>, <Post: test>]>
[07/Dec/2018 19:55:08] INFO [mysite:147] <QuerySet []>
[07/Dec/2018 19:55:08] INFO [mysite:147] <QuerySet [<Post: Kein bisschen Fränkisch>, <Post: Das ist ein Titel>, <Post: Hier kommt was neues>, <Post: Bavaria>]>
[09/Dec/2018 19:06:28] INFO [mysite:128] <QuerySet [<Tag: hi>, <Tag: test>, <Tag: two>, <Tag: second>]>
[09/Dec/2018 19:06:29] INFO [mysite:131] <QuerySet [<Post: Das ist ein Titel>, <Post: Strange Things>, <Post: Hier kommt was neues>]>
[09/Dec/2018 19:06:29] INFO [mysite:131] <QuerySet [<Post: Kein bisschen Fränkisch>, <Post: Das ist ein Titel>, <Post: Strange Things>, <Post: Hier kommt was neues>, <Post: Bavaria>, <Post: test>]>
[09/Dec/2018 19:06:29] INFO [mysite:131] <QuerySet []>
[09/Dec/2018 19:06:29] INFO [mysite:131] <QuerySet [<Post: Kein bisschen Fränkisch>, <Post: Das ist ein Titel>, <Post: Hier kommt was neues>, <Post: Bavaria>]>
[09/Dec/2018 19:20:36] INFO [mysite:128] <QuerySet [<Tag: hi>, <Tag: test>, <Tag: two>, <Tag: second>]>
[09/Dec/2018 19:20:37] INFO [mysite:131] <QuerySet [<Post: Das ist ein Titel>, <Post: Strange Things>, <Post: Hier kommt was neues>]>
[09/Dec/2018 19:20:37] INFO [mysite:131] <QuerySet [<Post: Kein bisschen Fränkisch>, <Post: Das ist ein Titel>, <Post: Strange Things>, <Post: Hier kommt was neues>, <Post: Bavaria>, <Post: test>]>
[09/Dec/2018 19:20:37] INFO [mysite:131] <QuerySet []>
[09/Dec/2018 19:20:37] INFO [mysite:131] <QuerySet [<Post: Kein bisschen Fränkisch>, <Post: Das ist ein Titel>, <Post: Hier kommt was neues>, <Post: Bavaria>]>

+ 11
- 1
mysite/settings.py View File

@@ -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

+ 0
- 1
mysite/urls.py View File

@@ -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


Loading…
Cancel
Save