From 69323cafd109bf5d2f4f50bbd9d4931c04c02426 Mon Sep 17 00:00:00 2001 From: pnshiralkar Date: Mon, 11 May 2020 20:08:23 +0530 Subject: Init cms app, added models --- cms/__init__.py | 0 cms/admin.py | 3 +++ cms/apps.py | 5 +++++ cms/models.py | 43 +++++++++++++++++++++++++++++++++++++++++++ cms/tests.py | 3 +++ cms/views.py | 3 +++ 6 files changed, 57 insertions(+) create mode 100644 cms/__init__.py create mode 100644 cms/admin.py create mode 100644 cms/apps.py create mode 100644 cms/models.py create mode 100644 cms/tests.py create mode 100644 cms/views.py diff --git a/cms/__init__.py b/cms/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cms/admin.py b/cms/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/cms/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. 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..1811a70 --- /dev/null +++ b/cms/models.py @@ -0,0 +1,43 @@ +from django.db import models + + +# Create your models here. + +class Nav(models.Model): + name = models.CharField(max=20) + link = models.CharField(max=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=20) + link = models.CharField(max=100) + position = models.IntegerField() + + def __str__(self): + return self.name + + +class Page(models.Model): + permalink = models.CharField(max=100, unique=True) + title = models.CharField(max=50) + imports = models.TextField(help_text='External imports like css,js files, will be placed in
tag (already ' + 'includes bootstrap4 and jQuery)') + 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 + + +class StaticFiles(models.Model): + filename = models.CharField(max=70, unique=True) + file = models.FileField(upload_to='static/{}'.format(filename), blank=False, + help_text='Please upload static files (images, css, js, etc) one by one') + + def __str__(self): + return self.filename 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/views.py b/cms/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/cms/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. -- cgit From 778a1d2d8100ad0e2bfc2ce98bf610c9961f4a5e Mon Sep 17 00:00:00 2001 From: pnshiralkar Date: Wed, 13 May 2020 12:36:25 +0530 Subject: feat: CMS App - Added cms app to INSTALLED_APPS in settings - Removed index URL from workshop_app/urls.py - Added cms urls to workshop_portal/urls.py - Added cms_base html for renderring cms - Modified static file model to save uploaded files into static location --- cms/admin.py | 6 +++++ cms/models.py | 38 +++++++++++++++++++-------- cms/templates/cms_base.html | 63 +++++++++++++++++++++++++++++++++++++++++++++ cms/urls.py | 8 ++++++ cms/views.py | 29 ++++++++++++++++++++- workshop_app/urls.py | 1 - workshop_portal/settings.py | 1 + workshop_portal/urls.py | 1 + 8 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 cms/templates/cms_base.html create mode 100644 cms/urls.py diff --git a/cms/admin.py b/cms/admin.py index 8c38f3f..8918797 100644 --- a/cms/admin.py +++ b/cms/admin.py @@ -1,3 +1,9 @@ from django.contrib import admin +from cms.models import * # Register your models here. + +admin.site.register(Nav) +admin.site.register(SubNav) +admin.site.register(Page) +admin.site.register(StaticFile) diff --git a/cms/models.py b/cms/models.py index 1811a70..05b761f 100644 --- a/cms/models.py +++ b/cms/models.py @@ -1,11 +1,15 @@ +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=20) - link = models.CharField(max=20) + name = models.CharField(max_length=20) + link = models.CharField(max_length=20) position = models.IntegerField() def __str__(self): @@ -14,8 +18,8 @@ class Nav(models.Model): class SubNav(models.Model): nav = models.ForeignKey(Nav, on_delete=models.CASCADE) - name = models.CharField(max=20) - link = models.CharField(max=100) + name = models.CharField(max_length=20) + link = models.CharField(max_length=100) position = models.IntegerField() def __str__(self): @@ -23,10 +27,10 @@ class SubNav(models.Model): class Page(models.Model): - permalink = models.CharField(max=100, unique=True) - title = models.CharField(max=50) + 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 tag (already ' - 'includes bootstrap4 and jQuery)') + '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) @@ -34,10 +38,22 @@ class Page(models.Model): return self.title -class StaticFiles(models.Model): - filename = models.CharField(max=70, unique=True) - file = models.FileField(upload_to='static/{}'.format(filename), blank=False, - help_text='Please upload static files (images, css, js, etc) one by one') +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..c2683f3 --- /dev/null +++ b/cms/templates/cms_base.html @@ -0,0 +1,63 @@ + + + + +