This commit is contained in:
Flatlogic Bot 2026-01-27 01:50:13 +00:00
parent 7736354eeb
commit fce8b78128
8 changed files with 175 additions and 21 deletions

View File

@ -1,3 +1,24 @@
from django.contrib import admin
from .models import Announcement, Comment, Event, Resource
# Register your models here.
@admin.register(Announcement)
class AnnouncementAdmin(admin.ModelAdmin):
list_display = ('title', 'type', 'created_at')
list_filter = ('type', 'created_at')
search_fields = ('title', 'content')
@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
list_display = ('author_name', 'announcement', 'created_at')
search_fields = ('author_name', 'content')
@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
list_display = ('title', 'start_date', 'location')
list_filter = ('start_date',)
search_fields = ('title', 'description', 'location')
@admin.register(Resource)
class ResourceAdmin(admin.ModelAdmin):
list_display = ('title', 'url')
search_fields = ('title', 'description')

View File

@ -0,0 +1,68 @@
# Generated by Django 5.2.7 on 2026-01-27 01:49
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Announcement',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('content', models.TextField()),
('type', models.CharField(choices=[('announcement', 'Announcement'), ('news', 'News')], default='announcement', max_length=20)),
('image_url', models.URLField(blank=True, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
options={
'ordering': ['-created_at'],
},
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=255)),
('description', models.TextField()),
('start_date', models.DateTimeField()),
('end_date', models.DateTimeField(blank=True, null=True)),
('location', models.CharField(blank=True, max_length=255, null=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
],
options={
'ordering': ['start_date'],
},
),
migrations.CreateModel(
name='Resource',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('description', models.CharField(blank=True, max_length=255, null=True)),
('url', models.URLField()),
('icon_class', models.CharField(default='bi-link-45deg', help_text='Bootstrap Icon class', max_length=50)),
],
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('author_name', models.CharField(max_length=100)),
('content', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('announcement', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='core.announcement')),
],
options={
'ordering': ['created_at'],
},
),
]

View File

@ -1,3 +1,55 @@
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Announcement(models.Model):
TYPE_CHOICES = [
('announcement', 'Announcement'),
('news', 'News'),
]
title = models.CharField(max_length=255)
content = models.TextField()
type = models.CharField(max_length=20, choices=TYPE_CHOICES, default='announcement')
image_url = models.URLField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.title
class Meta:
ordering = ['-created_at']
class Comment(models.Model):
announcement = models.ForeignKey(Announcement, on_delete=models.CASCADE, related_name='comments')
author_name = models.CharField(max_length=100)
content = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"Comment by {self.author_name} on {self.announcement.title}"
class Meta:
ordering = ['created_at']
class Event(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
start_date = models.DateTimeField()
end_date = models.DateTimeField(null=True, blank=True)
location = models.CharField(max_length=255, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.title
class Meta:
ordering = ['start_date']
class Resource(models.Model):
title = models.CharField(max_length=100)
description = models.CharField(max_length=255, null=True, blank=True)
url = models.URLField()
icon_class = models.CharField(max_length=50, default='bi-link-45deg', help_text='Bootstrap Icon class')
def __str__(self):
return self.title

View File

@ -1,25 +1,38 @@
import os
import platform
from django import get_version as django_version
from django.shortcuts import render
from django.shortcuts import render, redirect, get_object_or_404
from django.utils import timezone
from .models import Announcement, Comment, Event, Resource
from django.contrib import messages
def home(request):
"""Render the landing screen with loader and environment details."""
host_name = request.get_host().lower()
agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic"
now = timezone.now()
def index(request):
"""Render the Barangay Portal landing page."""
announcements = Announcement.objects.prefetch_related('comments').all()
upcoming_events = Event.objects.filter(start_date__gte=timezone.now())[:5]
resources = Resource.objects.all()
context = {
"project_name": "New Style",
"agent_brand": agent_brand,
"django_version": django_version(),
"python_version": platform.python_version(),
"current_time": now,
"host_name": host_name,
"project_description": os.getenv("PROJECT_DESCRIPTION", ""),
"project_image_url": os.getenv("PROJECT_IMAGE_URL", ""),
"announcements": announcements,
"upcoming_events": upcoming_events,
"resources": resources,
"project_name": "Barangay Portal",
}
return render(request, "core/index.html", context)
def add_comment(request, announcement_id):
"""Handle adding a comment to an announcement."""
if request.method == "POST":
announcement = get_object_or_404(Announcement, id=announcement_id)
author_name = request.POST.get("author_name", "Anonymous")
content = request.POST.get("content")
if content:
Comment.objects.create(
announcement=announcement,
author_name=author_name,
content=content
)
messages.success(request, "Your comment has been posted!")
else:
messages.error(request, "Comment content cannot be empty.")
return redirect("index")