Compare commits
No commits in common. "ai-dev" and "master" have entirely different histories.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,24 +1,3 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Announcement, Comment, Event, Resource
|
|
||||||
|
|
||||||
@admin.register(Announcement)
|
# Register your models here.
|
||||||
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')
|
|
||||||
|
|||||||
@ -1,68 +0,0 @@
|
|||||||
# 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'],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
Binary file not shown.
@ -1,55 +1,3 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
|
||||||
|
|
||||||
class Announcement(models.Model):
|
# Create your models here.
|
||||||
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
|
|
||||||
|
|||||||
@ -1,38 +1,25 @@
|
|||||||
import os
|
import os
|
||||||
from django.shortcuts import render, redirect, get_object_or_404
|
import platform
|
||||||
from django.utils import timezone
|
|
||||||
from .models import Announcement, Comment, Event, Resource
|
|
||||||
from django.contrib import messages
|
|
||||||
|
|
||||||
def index(request):
|
from django import get_version as django_version
|
||||||
"""Render the Barangay Portal landing page."""
|
from django.shortcuts import render
|
||||||
announcements = Announcement.objects.prefetch_related('comments').all()
|
from django.utils import timezone
|
||||||
upcoming_events = Event.objects.filter(start_date__gte=timezone.now())[:5]
|
|
||||||
resources = Resource.objects.all()
|
|
||||||
|
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()
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"announcements": announcements,
|
"project_name": "New Style",
|
||||||
"upcoming_events": upcoming_events,
|
"agent_brand": agent_brand,
|
||||||
"resources": resources,
|
"django_version": django_version(),
|
||||||
"project_name": "Barangay Portal",
|
"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", ""),
|
||||||
}
|
}
|
||||||
return render(request, "core/index.html", context)
|
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")
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user