Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fce8b78128 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +1,24 @@
|
|||||||
from django.contrib import admin
|
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')
|
||||||
68
core/migrations/0001_initial.py
Normal file
68
core/migrations/0001_initial.py
Normal 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'],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
BIN
core/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
core/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
@ -1,3 +1,55 @@
|
|||||||
from django.db import models
|
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
|
||||||
|
|||||||
@ -1,25 +1,38 @@
|
|||||||
import os
|
import os
|
||||||
import platform
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
|
|
||||||
from django import get_version as django_version
|
|
||||||
from django.shortcuts import render
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from .models import Announcement, Comment, Event, Resource
|
||||||
|
from django.contrib import messages
|
||||||
|
|
||||||
|
def index(request):
|
||||||
def home(request):
|
"""Render the Barangay Portal landing page."""
|
||||||
"""Render the landing screen with loader and environment details."""
|
announcements = Announcement.objects.prefetch_related('comments').all()
|
||||||
host_name = request.get_host().lower()
|
upcoming_events = Event.objects.filter(start_date__gte=timezone.now())[:5]
|
||||||
agent_brand = "AppWizzy" if host_name == "appwizzy.com" else "Flatlogic"
|
resources = Resource.objects.all()
|
||||||
now = timezone.now()
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"project_name": "New Style",
|
"announcements": announcements,
|
||||||
"agent_brand": agent_brand,
|
"upcoming_events": upcoming_events,
|
||||||
"django_version": django_version(),
|
"resources": resources,
|
||||||
"python_version": platform.python_version(),
|
"project_name": "Barangay Portal",
|
||||||
"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