1
0
tBKwtWS 6 жил өмнө
parent
commit
a7b4019072

+ 2 - 1
.gitignore

@@ -6,4 +6,5 @@
 
 # Exclude django
 __pycache__/
-db.sqlite3
+db.sqlite3
+**/migrations/*.py

+ 1 - 0
requirements.txt

@@ -1,4 +1,5 @@
 Django==2.2.6
+django-settings-export==1.2.1
 pkg-resources==0.0.0
 pytz==2019.2
 sqlparse==0.3.0

+ 0 - 0
website/knowledgebase/__init__.py


+ 6 - 0
website/knowledgebase/admin.py

@@ -0,0 +1,6 @@
+from django.contrib import admin
+
+# Register your models here.
+from .models import Article
+
+admin.site.register(Article)

+ 5 - 0
website/knowledgebase/apps.py

@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class KnowledgebaseConfig(AppConfig):
+    name = 'knowledgebase'

+ 57 - 0
website/knowledgebase/models.py

@@ -0,0 +1,57 @@
+import datetime
+from django.db import models
+from django.core.validators import validate_unicode_slug
+from django.utils import timezone
+# Create your models here.
+
+#class ArticleCatagories(models.Model):
+#    name = models.CharField(max_length=20)
+
+
+class Article(models.Model):
+    title = models.CharField(
+        max_length=50,
+        unique=True,
+    )
+
+    CATEGORY_CHOICES = [
+        ('Linux',
+            (
+                ('nx', 'Nginx'),
+            )
+        ),
+        ('ot', 'Other'),
+    ]
+    category = models.CharField(
+        max_length=2,
+        choices=CATEGORY_CHOICES,
+        #default=FOOBAR,
+    )
+
+    created = models.DateField(
+        auto_now_add=True,
+        editable=False,
+    )
+
+    updated = models.DateField(
+        auto_now=True,
+        editable=False,
+    )
+
+    slug = models.SlugField(
+        db_index=True,
+        unique=True,
+        validators=[validate_unicode_slug],
+    )
+
+    description = models.TextField()
+
+
+    def __str__(self):
+        return self.title
+
+    def published_this_week(self):
+        return self.created >= timezone.now() - datetime.timedelta(days=7)
+
+    def updated_this_week(self):
+        return self.updated >= timezone.now() - datetime.timedelta(days=7)

+ 1 - 0
website/knowledgebase/templates/knowledgebase/article.html

@@ -0,0 +1 @@
+{{ article }}

+ 12 - 0
website/knowledgebase/templates/knowledgebase/index.html

@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+{% block content %}
+  {% if latest_article_list %}
+    <ul>
+      {% for article in latest_article_list %}
+        <li><a href="{% url 'knowledgebase:article' article.slug %}">{{ article.title }}</a></li>
+      {% endfor %}
+    </ul>
+  {% else %}
+    <<p>No articles available.</p>
+  {% endif %}
+{% endblock %}

+ 3 - 0
website/knowledgebase/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 9 - 0
website/knowledgebase/urls.py

@@ -0,0 +1,9 @@
+from django.urls import path
+
+from . import views
+
+app_name = 'knowledgebase'
+urlpatterns = [
+    path('', views.index, name='index'),
+    path('<str:article_slug>/', views.article, name='article'),
+]

+ 18 - 0
website/knowledgebase/views.py

@@ -0,0 +1,18 @@
+#from django.shortcuts import render
+from django.http import Http404
+from django.shortcuts import render, get_object_or_404
+
+from .models import Article
+
+def index(request):
+    latest_article_list = Article.objects.order_by('-created')[:5]
+    context = {
+        'latest_article_list': latest_article_list,
+        'title': 'FOOBAR',
+    }
+    #output = ', '.join([article.title for article in latest_article_list])
+    return render(request, 'knowledgebase/index.html', context)
+
+def article(request, article_slug):
+    article = get_object_or_404(Article, slug=article_slug)
+    return render(request, 'knowledgebase/article.html', {'article': article_slug})

+ 16 - 0
website/templates/base.html

@@ -0,0 +1,16 @@
+{% load staticfiles %}<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>
+      {% if title %}{{ title }} - {% endif %}
+      {% if user.is_authenticated %}{{ user.username }}@{% endif %}{{ settings.APPLICATION_NAME }}
+    </title>
+    <meta name="application-name" content="{{ settings.APPLICATION_NAME }}">
+    <meta name="author" content="tBKwtWS">
+    <meta name="description" content="{{ description }}">
+    <meta name="keywords" content="{{ keywords }}">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  </head>
+  <body>{% block content %}{% endblock content %}</body>
+</html>

+ 17 - 2
website/website/settings.py

@@ -12,6 +12,7 @@ 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__)))
 
@@ -37,6 +38,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'knowledgebase.apps.KnowledgebaseConfig',
 ]
 
 MIDDLEWARE = [
@@ -54,7 +56,7 @@ ROOT_URLCONF = 'website.urls'
 TEMPLATES = [
     {
         'BACKEND': 'django.template.backends.django.DjangoTemplates',
-        'DIRS': [],
+        'DIRS': [os.path.join(BASE_DIR, 'templates')],
         'APP_DIRS': True,
         'OPTIONS': {
             'context_processors': [
@@ -62,6 +64,8 @@ TEMPLATES = [
                 'django.template.context_processors.request',
                 'django.contrib.auth.context_processors.auth',
                 'django.contrib.messages.context_processors.messages',
+
+                'django_settings_export.settings_export',
             ],
         },
     },
@@ -105,7 +109,7 @@ AUTH_PASSWORD_VALIDATORS = [
 
 LANGUAGE_CODE = 'en-us'
 
-TIME_ZONE = 'UTC'
+TIME_ZONE = 'Europe/Amsterdam'
 
 USE_I18N = True
 
@@ -118,3 +122,14 @@ USE_TZ = True
 # https://docs.djangoproject.com/en/2.2/howto/static-files/
 
 STATIC_URL = '/static/'
+
+
+## Settings export
+# https://github.com/jkbrzt/django-settings-export
+
+SETTINGS_EXPORT = [
+    'INSTALLED_APPS',
+    'APPLICATION_NAME'
+]
+
+APPLICATION_NAME = 'h0v1n8'

+ 0 - 18
website/website/templates/base.html

@@ -1,18 +0,0 @@
-{% load staticfiles %}
-<!DOCTYPE html>
-<html lang="en">
-    <head>
-        <title>{% page_attribute "page_title" %}</title>
-        {% render_block "css" %}
-        <meta name="application-name" content="{{ settings.APPLICATION_NAME }}">
-        <meta name="author" content="tBKwtWS">
-        <meta name="description" content="{{ description }}">
-        <meta name="keywords" content="{{ keywords }}">
-        <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    </head>
-    <body>
-        {% cms_toolbar %}
-        {% placeholder "content" %}
-        {% render_block "js" %}
-    </body>
-</html>

+ 2 - 1
website/website/urls.py

@@ -14,8 +14,9 @@ Including another URLconf
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
 from django.contrib import admin
-from django.urls import path
+from django.urls import path, include
 
 urlpatterns = [
     path('admin/', admin.site.urls),
+    path('knowledgebase/', include('knowledgebase.urls')),
 ]