summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2020-07-27 16:49:44 +0530
committeradityacp2020-07-27 16:49:44 +0530
commit96102991ed192ca6a0c48cad4e63b604c0ce6d70 (patch)
tree6a1d15502f45c72d99d806b043efda334b0f3184
parent47eb422c3cb2baf5386df274114019f684fa9af8 (diff)
downloadworkshop_booking-96102991ed192ca6a0c48cad4e63b604c0ce6d70.tar.gz
workshop_booking-96102991ed192ca6a0c48cad4e63b604c0ce6d70.tar.bz2
workshop_booking-96102991ed192ca6a0c48cad4e63b604c0ce6d70.zip
Change models, views, admin, template
- Add active boolean field in all models - Get the pages based on the active status - Minor code refactor in views - Add app_name in urls
-rw-r--r--cms/admin.py6
-rw-r--r--cms/models.py13
-rw-r--r--cms/templates/cms_base.html8
-rw-r--r--cms/urls.py2
-rw-r--r--cms/views.py21
5 files changed, 30 insertions, 20 deletions
diff --git a/cms/admin.py b/cms/admin.py
index 595793e..d0b7626 100644
--- a/cms/admin.py
+++ b/cms/admin.py
@@ -6,18 +6,18 @@ from cms.models import *
# Register your models here.
class NavAdmin(admin.ModelAdmin):
- list_display = ['name', 'link', 'position']
+ list_display = ['name', 'link', 'position', 'active']
ordering = ['position']
class SubNavAdmin(admin.ModelAdmin):
- list_display = ['name', 'nav', 'link', 'position']
+ list_display = ['name', 'nav', 'link', 'position', 'active']
ordering = ['nav', 'position']
list_filter = ['nav']
class PageAdmin(admin.ModelAdmin):
- list_display = ['title', 'permalink', 'pub_date']
+ list_display = ['title', 'permalink', 'pub_date', 'active']
class StaticFileAdmin(admin.ModelAdmin):
diff --git a/cms/models.py b/cms/models.py
index 05b761f..be6b054 100644
--- a/cms/models.py
+++ b/cms/models.py
@@ -9,8 +9,9 @@ from django.db import models
class Nav(models.Model):
name = models.CharField(max_length=20)
- link = models.CharField(max_length=20)
+ link = models.CharField(max_length=255)
position = models.IntegerField()
+ active = models.BooleanField(default=True)
def __str__(self):
return self.name
@@ -19,8 +20,9 @@ class Nav(models.Model):
class SubNav(models.Model):
nav = models.ForeignKey(Nav, on_delete=models.CASCADE)
name = models.CharField(max_length=20)
- link = models.CharField(max_length=100)
+ link = models.CharField(max_length=255)
position = models.IntegerField()
+ active = models.BooleanField(default=True)
def __str__(self):
return self.name
@@ -29,10 +31,13 @@ class SubNav(models.Model):
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)
+ 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)
+ active = models.BooleanField(default=True)
def __str__(self):
return self.title
diff --git a/cms/templates/cms_base.html b/cms/templates/cms_base.html
index 90d0e2b..4f43329 100644
--- a/cms/templates/cms_base.html
+++ b/cms/templates/cms_base.html
@@ -3,7 +3,7 @@
{% load static %}
<head>
<meta charset="UTF-8">
- <title>{{ page.title }}</title>
+ <title>{{ page.title|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>
@@ -14,8 +14,8 @@
</head>
<body>
-<nav class=" navbar-custom navbar navbar-expand-lg bg-light">
- <a class="navbar-brand" href="/">FOSSEE Python Workshops</a>
+<nav class=" navbar navbar-dark navbar navbar-expand-lg bg-dark fixed-top">
+ <a class="navbar-brand" href="/">FOSSEE 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>
@@ -52,6 +52,8 @@
</div>
</div>
</nav>
+<div class="base-content">
{{ page.content | safe }}
+</div>
</body>
</html> \ No newline at end of file
diff --git a/cms/urls.py b/cms/urls.py
index b0c7612..baae492 100644
--- a/cms/urls.py
+++ b/cms/urls.py
@@ -2,6 +2,8 @@ from django.conf.urls import url
from cms import views
+app_name = "cms"
+
urlpatterns = [
url('^$', views.home, name='home'),
url('^(?P<permalink>.+)$', views.home, name='home')
diff --git a/cms/views.py b/cms/views.py
index 0b74822..fc1439a 100644
--- a/cms/views.py
+++ b/cms/views.py
@@ -9,20 +9,21 @@ 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()
+ page = Page.objects.filter(permalink=permalink, active=True)
+ if page.exists():
+ page = page.first()
+ else:
+ raise Http404("The requested page does not exists")
+ nav_objs = Nav.objects.filter(active=True).order_by('-position')
navs = []
for nav in nav_objs:
nav_obj = model_to_dict(nav)
- nav_obj['subnavs'] = subnav_objects.filter(nav=nav).order_by('position')
+ nav_obj['subnavs'] = nav.subnav_set.filter(
+ active=True).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})
+ return render(
+ request, 'cms_base.html', {'page': page, 'navs': navs}
+ )