Browse Source

beautifed code and added descriptive comments

master
Esther Kleinhenz 6 years ago
parent
commit
faaa66aa8e

+ 5
- 5
application/admin.py View File



from .models import Post, CustomUser from .models import Post, CustomUser



#external code customised #external code customised
#import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model #import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model
#start ---
class CustomUserInline(admin.StackedInline): class CustomUserInline(admin.StackedInline):
model = CustomUser model = CustomUser
can_delete = False can_delete = False
verbose_name_plural = 'customUsers' 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 # Define a new User admin
class UserAdmin(BaseUserAdmin): class UserAdmin(BaseUserAdmin):
inlines = (CustomUserInline, ) inlines = (CustomUserInline, )


#external code customised
#import from https://docs.djangoproject.com/en/dev/topics/auth/customizing/#extending-the-existing-user-model

# Re-register UserAdmin # Re-register UserAdmin
admin.site.unregister(User) admin.site.unregister(User)
admin.site.register(User, UserAdmin) admin.site.register(User, UserAdmin)
admin.site.register(Post) admin.site.register(Post)
#end ---

+ 1
- 0
application/forms.py View File



from taggit.forms import * from taggit.forms import *



#extended code customised #extended code customised
#import from https://tutorial.djangogirls.org/en/django_forms/ #import from https://tutorial.djangogirls.org/en/django_forms/
class PostForm(forms.ModelForm): class PostForm(forms.ModelForm):

+ 11
- 6
application/models.py View File

from django.db import models from django.db import models

from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils import timezone from django.utils import timezone

from taggit.managers import TaggableManager from taggit.managers import TaggableManager
from datetime import datetime 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): class CustomUser(models.Model):
user = models.OneToOneField(User, null=True, on_delete=models.CASCADE) user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
#add tags to User Model with possibility to leave empty
tags = TaggableManager(blank=True) tags = TaggableManager(blank=True)



#external code customised
#import from https://tutorial.djangogirls.org/en/django_models/
class Post(models.Model): class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE) author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200) title = models.CharField(max_length=200)
text = models.TextField() 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() tags = TaggableManager()


def publish(self): def publish(self):

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

</div> </div>
</nav> </nav>


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

</html> </html>

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

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

<!-- imported start -->
<div class="post"> <div class="post">
{% if post.published_date %} {% if post.published_date %}
<div class="date"> <div class="date">
</div> </div>
{% else %} {% else %}
<a class="btn btn-outline-dark" href="{% url 'post_publish' pk=post.pk %}">Publish</a> <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 %} {% endif %} {% if user.is_staff and user == post.author %}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<div style="padding-bottom:40px;"> <div style="padding-bottom:40px;">
</div> </div>
Tag-Suche Tag-Suche
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

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

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

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

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

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

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

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

<p>{{ post.text|linebreaks }}</p> <p>{{ post.text|linebreaks }}</p>
Tags: {% for tag in post.tags.all %} Tags: {% for tag in post.tags.all %}
<a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a> <a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a>
</a> </a>
</div> </div>
</div> </div>

</div> </div>
{% endblock %} {% endblock %}

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

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

from taggit_templatetags2 import urls as taggit_templatetags2_urls from taggit_templatetags2 import urls as taggit_templatetags2_urls
import debug_toolbar import debug_toolbar




urlpatterns = [ urlpatterns = [
url(r'^$', views.tag_list, name='tag_list'), url(r'^$', views.tag_list, name='tag_list'),
url(r'^tag/(?P<slug>[-\w]+)/$', views.post_list, name='post_list_by_tag'), url(r'^tag/(?P<slug>[-\w]+)/$', views.post_list, name='post_list_by_tag'),
url(r'^tags/', include('taggit_templatetags2.urls')), url(r'^tags/', include('taggit_templatetags2.urls')),
] ]



#external code #external code
#import from https://django-debug-toolbar.readthedocs.io/en/latest/installation.html #import from https://django-debug-toolbar.readthedocs.io/en/latest/installation.html
if settings.DEBUG: if settings.DEBUG:

+ 18
- 19
application/views.py View File

import logging
import mysite.settings

from django.shortcuts import render, get_object_or_404 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.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 .models import Post, CustomUser
from taggit.models import Tag from taggit.models import Tag
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from .forms import PostForm, NewTagForm 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 django.contrib import messages
from post_office.models import EmailTemplate
from post_office import mail from post_office import mail

from hitcount.models import HitCount from hitcount.models import HitCount
from hitcount.views import HitCountMixin from hitcount.views import HitCountMixin




import logging
import mysite.settings
import operator


def navlogin(request): def navlogin(request):
log = logging.getLogger('mysite') log = logging.getLogger('mysite')
logout(request) logout(request)
context = {'error': error} context = {'error': error}
return render(request, 'index.html', context) return render(request, 'index.html', context)



#external code customised
#import from https://tutorial.djangogirls.org/en/django_forms/
#start ---
@login_required @login_required
def post_list(request, slug=None): def post_list(request, slug=None):
log = logging.getLogger('mysite') log = logging.getLogger('mysite')
messages.info(request, 'Der Artikel "' + post.title + '" wurde gelöscht') messages.info(request, 'Der Artikel "' + post.title + '" wurde gelöscht')
post.delete() post.delete()
return redirect('post_list') return redirect('post_list')
#end ---


@login_required @login_required
def tag_list(request): def tag_list(request):
form = NewTagForm() form = NewTagForm()
return render(request, 'search_add.html', locals()) return render(request, 'search_add.html', locals())



#external code customised
#import from https://github.com/ui/django-post_office
mail.send( 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', 'esther.kleinhenz@web.de',
subject='My email', subject='My email',
message='Hi there!', message='Hi there!',

+ 10
- 0
log.txt View File

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



AUTH_PROFILE_MODULE = 'application.CustomUser' AUTH_PROFILE_MODULE = 'application.CustomUser'



#Log Configuration #Log Configuration
#external code
#import form https://docs.djangoproject.com/en/2.1/topics/logging/

LOGGING = { LOGGING = {
'version': 1, 'version': 1,
'disable_existing_loggers': True, 'disable_existing_loggers': True,
} }
} }


#Logging Addon
#external code
#import from https://django-debug-toolbar.readthedocs.io/en/latest/installation.html


if DEBUG: if DEBUG:
INTERNAL_IPS = ('127.0.0.1', 'localhost',) INTERNAL_IPS = ('127.0.0.1', 'localhost',)
'INTERCEPT_REDIRECTS': False, '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 = 'smtp.web.de'
EMAIL_HOST_USER = "esther.kleinhenz@web.de" EMAIL_HOST_USER = "esther.kleinhenz@web.de"
EMAIL_PORT = 25 # default smtp port EMAIL_PORT = 25 # default smtp port

+ 0
- 1
mysite/urls.py View File

from django.conf.urls import include, url from django.conf.urls import include, url
from django.views.generic import TemplateView from django.views.generic import TemplateView



from django.contrib.auth import views from django.contrib.auth import views
import application.views import application.views



Loading…
Cancel
Save