summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2020-07-21 14:33:10 +0530
committeradityacp2020-07-21 14:33:10 +0530
commit120ff8c5e6a90c5c02af7f9266e1fd9a6435350f (patch)
treed758293ba442cffa3930aea081e4fd63ed34d00d
parent5b593457c0d07a6c11884c33ec7c676de9510b9d (diff)
parent9dad3388d07af45c885fbe5b713294a19d7d6b2e (diff)
downloadworkshop_booking-120ff8c5e6a90c5c02af7f9266e1fd9a6435350f.tar.gz
workshop_booking-120ff8c5e6a90c5c02af7f9266e1fd9a6435350f.tar.bz2
workshop_booking-120ff8c5e6a90c5c02af7f9266e1fd9a6435350f.zip
Get latest changes and resolve conflicts
-rw-r--r--cms/__init__.py0
-rw-r--r--cms/admin.py30
-rw-r--r--cms/apps.py5
-rw-r--r--cms/models.py59
-rw-r--r--cms/templates/cms_base.html57
-rw-r--r--cms/tests.py3
-rw-r--r--cms/urls.py8
-rw-r--r--cms/views.py28
-rw-r--r--workshop_portal/settings.py1
-rw-r--r--workshop_portal/urls.py1
10 files changed, 192 insertions, 0 deletions
diff --git a/cms/__init__.py b/cms/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cms/__init__.py
diff --git a/cms/admin.py b/cms/admin.py
new file mode 100644
index 0000000..595793e
--- /dev/null
+++ b/cms/admin.py
@@ -0,0 +1,30 @@
+from django.contrib import admin
+
+from cms.models import *
+
+
+# Register your models here.
+
+class NavAdmin(admin.ModelAdmin):
+ list_display = ['name', 'link', 'position']
+ ordering = ['position']
+
+
+class SubNavAdmin(admin.ModelAdmin):
+ list_display = ['name', 'nav', 'link', 'position']
+ ordering = ['nav', 'position']
+ list_filter = ['nav']
+
+
+class PageAdmin(admin.ModelAdmin):
+ list_display = ['title', 'permalink', 'pub_date']
+
+
+class StaticFileAdmin(admin.ModelAdmin):
+ list_display = ['filename', 'file']
+
+
+admin.site.register(Nav, NavAdmin)
+admin.site.register(SubNav, SubNavAdmin)
+admin.site.register(Page, PageAdmin)
+admin.site.register(StaticFile, StaticFileAdmin)
diff --git a/cms/apps.py b/cms/apps.py
new file mode 100644
index 0000000..7ef3fea
--- /dev/null
+++ b/cms/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class CmsConfig(AppConfig):
+ name = 'cms'
diff --git a/cms/models.py b/cms/models.py
new file mode 100644
index 0000000..05b761f
--- /dev/null
+++ b/cms/models.py
@@ -0,0 +1,59 @@
+import os
+
+from django.core.exceptions import ValidationError
+from django.core.files.storage import FileSystemStorage
+from django.db import models
+
+
+# Create your models here.
+
+class Nav(models.Model):
+ name = models.CharField(max_length=20)
+ link = models.CharField(max_length=20)
+ position = models.IntegerField()
+
+ def __str__(self):
+ return self.name
+
+
+class SubNav(models.Model):
+ nav = models.ForeignKey(Nav, on_delete=models.CASCADE)
+ name = models.CharField(max_length=20)
+ link = models.CharField(max_length=100)
+ position = models.IntegerField()
+
+ def __str__(self):
+ return self.name
+
+
+class Page(models.Model):
+ permalink = models.CharField(max_length=100, unique=True)
+ title = models.CharField(max_length=50)
+ imports = models.TextField(help_text='External imports like css,js files, will be placed in <head> tag (already '
+ 'includes bootstrap4 and jQuery)', null=True, blank=True)
+ content = models.TextField(help_text='Body of the page')
+ pub_date = models.DateTimeField('date published', auto_now_add=True)
+
+ def __str__(self):
+ return self.title
+
+
+def get_filename(instance, _):
+ return 'static/cms/' + str(instance.filename)
+
+
+def validate_filename(value):
+ if os.path.exists('workshop_app/static/' + value):
+ raise ValidationError('Static file with that name already exists! Please choose a unique name. You may use '
+ 'foldername/filename to upload to a folder')
+
+
+class StaticFile(models.Model):
+ filename = models.CharField(max_length=70, unique=True, validators=[validate_filename])
+ file = models.FileField(upload_to=get_filename, storage=FileSystemStorage(location='workshop_app', base_url='/'),
+ blank=False,
+ help_text='Please upload static file (image, css, js, etc). This file will be accessible '
+ 'at static/cms/filename')
+
+ def __str__(self):
+ return self.filename
diff --git a/cms/templates/cms_base.html b/cms/templates/cms_base.html
new file mode 100644
index 0000000..90d0e2b
--- /dev/null
+++ b/cms/templates/cms_base.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html lang="en">
+{% load static %}
+<head>
+ <meta charset="UTF-8">
+ <title>{{ page.title }}</title>
+ <link rel="stylesheet" href="{% static 'cms/css/bootstrap.min.css' %}">
+
+ <script src="{% static 'cms/js/jquery-3.4.1.slim.min.js' %}"></script>
+ <script src="{% static 'cms/js/popper.min.js' %}"></script>
+ {{ page.imports | safe }}
+ <script src="{% static 'cms/js/bootstrap.min.js' %}"></script>
+ <link rel="stylesheet" href="{% static 'workshop_app/css/base.css' %}" type="text/css"/>
+</head>
+<body>
+
+<nav class=" navbar-custom navbar navbar-expand-lg bg-light">
+ <a class="navbar-brand" href="/">FOSSEE Python Workshops</a>
+ <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
+ aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+
+ <div class="collapse navbar-collapse" id="navbarSupportedContent">
+ <ul class="navbar-nav mr-auto">
+ </ul>
+ <div class="my-2 my-lg-0">
+ <ul class="navbar-nav mr-auto">
+ {% for nav in navs %}
+ <li class="nav-item">
+ {% if nav.subnavs %}
+ <ul class="navbar-nav mr-auto">
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
+ data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span
+ class="material-icons" style="vertical-align: middle">{{ nav.name }}</span>
+ </a>
+ <div class="dropdown-menu" aria-labelledby="navbarDropdown">
+ {% for subnav in nav.subnavs %}
+ <a class="dropdown-item" href="{{ subnav.link }}">{{ subnav.name }}</a>
+ {% endfor %}
+ </div>
+ </li>
+ </ul>
+ {% else %}
+ <a class="nav-link" href="{{ nav.link }}">{{ nav.name }}</a>
+ {% endif %}
+ </li>
+ {% endfor %}
+
+ </ul>
+ </div>
+ </div>
+</nav>
+{{ page.content | safe }}
+</body>
+</html> \ No newline at end of file
diff --git a/cms/tests.py b/cms/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/cms/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/cms/urls.py b/cms/urls.py
new file mode 100644
index 0000000..b0c7612
--- /dev/null
+++ b/cms/urls.py
@@ -0,0 +1,8 @@
+from django.conf.urls import url
+
+from cms import views
+
+urlpatterns = [
+ url('^$', views.home, name='home'),
+ url('^(?P<permalink>.+)$', views.home, name='home')
+] \ No newline at end of file
diff --git a/cms/views.py b/cms/views.py
new file mode 100644
index 0000000..0b74822
--- /dev/null
+++ b/cms/views.py
@@ -0,0 +1,28 @@
+# Create your views here.
+from django.forms import model_to_dict
+from django.http import Http404
+from django.shortcuts import render
+
+from cms.models import Page, Nav, SubNav
+
+
+def home(request, permalink=''):
+ if permalink == '':
+ permalink = 'home'
+ page = Page.objects.filter(permalink=permalink)
+ nav_objs = Nav.objects.all().order_by('-position')
+ subnav_objects = SubNav.objects.all()
+
+ navs = []
+
+ for nav in nav_objs:
+ nav_obj = model_to_dict(nav)
+ nav_obj['subnavs'] = subnav_objects.filter(nav=nav).order_by('position')
+ navs.insert(-1, nav_obj)
+
+ if page.exists():
+ page = page.first()
+ else:
+ raise Http404()
+
+ return render(request, 'cms_base.html', {'page': page, 'navs': navs})
diff --git a/workshop_portal/settings.py b/workshop_portal/settings.py
index abf58f5..ad727af 100644
--- a/workshop_portal/settings.py
+++ b/workshop_portal/settings.py
@@ -47,6 +47,7 @@ INSTALLED_APPS = [
'workshop_app',
'statistics_app',
'teams',
+ 'cms',
]
MIDDLEWARE = [
diff --git a/workshop_portal/urls.py b/workshop_portal/urls.py
index 464b98c..703a9ed 100644
--- a/workshop_portal/urls.py
+++ b/workshop_portal/urls.py
@@ -21,4 +21,5 @@ urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('workshop_app.urls')),
url(r'^reset/', include('django.contrib.auth.urls')),
+ url(r'^', include('cms.urls')),
]