Skip to content

Modify Customflatpages #599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions chipy_org/apps/profiles/migrations/0010_customflatpage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 5.1.5 on 2025-03-21 15:31



from django.contrib.flatpages.models import FlatPage
from django.db import models

class CustomFlatPage(FlatPage): # ✅ Extends FlatPage
header_image = models.ImageField(upload_to="flatpage_headers/", blank=True, null=True)
static_header_image = models.CharField(
max_length=255, blank=True, null=True,
help_text="Enter a static image path if not using an uploaded image."
)

def get_header_image_url(self):
"""Return the best available header image."""
if self.header_image:
return self.header_image.url
if self.static_header_image:
return f"/static/images/headers/{self.static_header_image}"
return "/static/images/default-header.jpg"




iimport django.db.models.deletion
from django.db import migrations, models

class Migration(migrations.Migration):

dependencies = [
('flatpages', '0001_initial'), # Adjust this dependency if necessary
('profiles', '0009_alter_userprofile_role'),
]

operations = [
migrations.CreateModel(
name='CustomFlatPage',
fields=[
('flatpage_ptr', models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to='flatpages.flatpage'
)),
('header_image', models.ImageField(upload_to="flatpage_headers/", blank=True, null=True)),
('static_header_image', models.CharField(
max_length=255, blank=True, null=True,
help_text="Enter a static image path if not using an uploaded image."
)),
],
bases=('flatpages.flatpage',),
),
]


19 changes: 19 additions & 0 deletions chipy_org/apps/profiles/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver


class CustomFlatPage(FlatPage):
HEADER_IMAGE_CHOICES = [("chicago-bg.jpg", "Header 1")]

header_image = models.CharField(
max_length=255,
choices=HEADER_IMAGE_CHOICES,
blank=True,
null=True,
help_text="Select a header image for this page.",
)

def get_header_image_url(self):
"""Returns the full URL of the selected header image."""
if self.header_image:
return f"/static/images/{self.header_image}"
return "/static/images/default.jpg"


class UserProfile(models.Model):
class Role(models.TextChoices):
MEMBER = "MEMBER", "Member"
Expand Down
8 changes: 7 additions & 1 deletion chipy_org/apps/profiles/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render
from django.views.generic import ListView, UpdateView

from .forms import ProfileForm
from .models import UserProfile
from .models import CustomFlatPage, UserProfile


def custom_flatpage_view(request, url):
flatpage = get_object_or_404(CustomFlatPage, url=url)
return render(request, "shiny/slim.html", {"flatpage": flatpage})


class ProfilesList(ListView):
Expand Down
14 changes: 11 additions & 3 deletions chipy_org/templates/flatpages/default.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
{% extends "shiny/slim.html" %}
{% block page_header %}{{ flatpage.title | upper }}{% endblock %}

{% block page_header %}
{{ flatpage.title | upper }}
{% endblock %}

{% block body %}
<div class="page-header" style="background-image: url('{{ flatpage.get_header_image_url }}');">
<h1>{{ flatpage.title | upper }}</h1>
</div>

<div class="content">
{{ flatpage.content }}
</div>
{{ flatpage.content }}
</div>
{% endblock %}
10 changes: 10 additions & 0 deletions chipy_org/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.shortcuts import render

from .models import CustomFlatPage


def custom_flatpage_view(request, url):
flatpage = CustomFlatPage.objects.filter(url=url).first()
if not flatpage:
return render(request, "404.html", status=404)
return render(request, "shiny/slim.html", {"flatpage": flatpage})