Start implementing basic CMS functionality for main page

This commit is contained in:
Mark Veidemanis 2022-07-21 13:50:25 +01:00
parent fd310cc7e8
commit c52c3e1924
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
9 changed files with 169 additions and 11 deletions

View File

@ -2,7 +2,7 @@ from django.contrib import admin
from django.contrib.auth.admin import UserAdmin from django.contrib.auth.admin import UserAdmin
from .forms import CustomUserCreationForm from .forms import CustomUserCreationForm
from .models import Plan, Session, User from .models import ContentBlock, Plan, Session, User
# Register your models here. # Register your models here.
@ -31,3 +31,4 @@ class CustomUserAdmin(UserAdmin):
admin.site.register(User, CustomUserAdmin) admin.site.register(User, CustomUserAdmin)
admin.site.register(Plan) admin.site.register(Plan)
admin.site.register(Session) admin.site.register(Session)
admin.site.register(ContentBlock)

View File

@ -0,0 +1,26 @@
# Generated by Django 4.0.6 on 2022-07-13 13:55
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0002_session_session'),
]
operations = [
migrations.CreateModel(
name='ContentBlock',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('position', models.IntegerField()),
('column1', models.TextField()),
('column2', models.TextField(blank=True, null=True)),
('column3', models.TextField(blank=True, null=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.0.6 on 2022-07-13 14:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0003_contentblock'),
]
operations = [
migrations.AddField(
model_name='contentblock',
name='title',
field=models.TextField(blank=True, null=True),
),
]

View File

@ -0,0 +1,38 @@
# Generated by Django 4.0.6 on 2022-07-13 14:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_contentblock_title'),
]
operations = [
migrations.AddField(
model_name='contentblock',
name='image1',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='contentblock',
name='image2',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='contentblock',
name='image3',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='contentblock',
name='column1',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='contentblock',
name='title',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

View File

@ -67,3 +67,28 @@ class Session(models.Model):
session = models.CharField(max_length=255, null=True, blank=True) session = models.CharField(max_length=255, null=True, blank=True)
subscription_id = models.CharField(max_length=255, null=True, blank=True) subscription_id = models.CharField(max_length=255, null=True, blank=True)
plan = models.ForeignKey(Plan, null=True, blank=True, on_delete=models.CASCADE) plan = models.ForeignKey(Plan, null=True, blank=True, on_delete=models.CASCADE)
class ContentBlock(models.Model):
user = models.ForeignKey(User, on_delete=models.PROTECT)
position = models.IntegerField()
title = models.CharField(max_length=255, null=True, blank=True)
column1 = models.TextField(null=True, blank=True)
column2 = models.TextField(null=True, blank=True)
column3 = models.TextField(null=True, blank=True)
image1 = models.CharField(max_length=255, null=True, blank=True)
image2 = models.CharField(max_length=255, null=True, blank=True)
image3 = models.CharField(max_length=255, null=True, blank=True)
def save(self, *args, **kwargs):
"""
Override the save function to blank fields.
"""
if self.column1 == "NONE":
self.column1 = None
if self.column2 == "NONE":
self.column2 = None
if self.column3 == "NONE":
self.column3 = None
super().save(*args, **kwargs)

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -1,12 +1,58 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load static %}
{% block content %} {% block content %}
<div class="block">
{% for block in blocks %}
{% if block.title is not None %}
<h1 class="title">{{ block.title }}</h1>
{% endif %}
<div class="columns">
{% if block.column1 is not None %}
<div class="column">
<div class="box"> <div class="box">
<h1 class="title">Pathogen Data Insights</h1> {{ block.column1 }}
<div class="container">
<h2 class="subtitle">Welcome to the Neptune system</h2>
<div class="col">
<h2 class="subtitle">Hello!</h2>
</div> </div>
</div> </div>
{% endif %}
{% if block.column2 is not None %}
<div class="column">
<div class="box">
{{ block.column2 }}
</div> </div>
</div>
{% endif %}
{% if block.column3 is not None %}
<div class="column">
<div class="box">
{{ block.column3 }}
</div>
</div>
{% endif %}
</div>
<div class="columns">
{% if block.image1 is not None %}
<div class="column">
<div class="box">
<img src="{% static block.image1 %}">
</div>
</div>
{% endif %}
{% if block.image2 is not None %}
<div class="column">
<div class="box">
{{ block.image2 }}
</div>
</div>
{% endif %}
{% if block.image3 is not None %}
<div class="column">
<div class="box">
{{ block.image3 }}
</div>
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% endblock %} {% endblock %}

View File

@ -11,7 +11,7 @@ from django.views.generic.edit import CreateView
from core.forms import NewUserForm from core.forms import NewUserForm
from core.lib.products import assemble_plan_map from core.lib.products import assemble_plan_map
from core.models import Plan, Session from core.models import ContentBlock, Plan, Session
pp = pprint.PrettyPrinter(indent=4) pp = pprint.PrettyPrinter(indent=4)
@ -22,7 +22,11 @@ class Home(View):
template_name = "index.html" template_name = "index.html"
def get(self, request): def get(self, request):
return render(request, self.template_name) blocks = ContentBlock.objects.all().order_by("position")
print("BLOCKS", blocks)
print("ITER", [x.position for x in blocks])
context = {"blocks": blocks}
return render(request, self.template_name, context)
class Billing(LoginRequiredMixin, View): class Billing(LoginRequiredMixin, View):