-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
164 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
from django.contrib import admin | ||
from .models import CommunityActivity | ||
from ckeditor_uploader.widgets import CKEditorUploadingWidget | ||
from django import forms | ||
|
||
# Register your models here. | ||
|
||
|
||
class CommunityActivityAdminForm(forms.ModelForm): | ||
content = forms.CharField(widget=CKEditorUploadingWidget()) | ||
|
||
class Meta: | ||
model = CommunityActivity | ||
exclude = ["slug", "fa_icon"] | ||
|
||
|
||
@admin.register(CommunityActivity) | ||
class CommunityActivityAdmin(admin.ModelAdmin): | ||
pass | ||
form = CommunityActivityAdminForm | ||
list_display = ["title", "activity_page"] |
32 changes: 32 additions & 0 deletions
32
src/activities/migrations/0002_communityactivity_content_communityactivity_slug_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 4.2.1 on 2024-01-01 20:44 | ||
|
||
import ckeditor_uploader.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("activities", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="communityactivity", | ||
name="content", | ||
field=ckeditor_uploader.fields.RichTextUploadingField( | ||
blank=True, null=True | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="communityactivity", | ||
name="slug", | ||
field=models.SlugField(blank=True, unique=True), | ||
), | ||
migrations.AlterField( | ||
model_name="communityactivity", | ||
name="description", | ||
field=models.TextField( | ||
default="Detailed activity description", max_length=1024 | ||
), | ||
), | ||
] |
20 changes: 20 additions & 0 deletions
20
src/activities/migrations/0003_alter_communityactivity_title.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 4.2.1 on 2024-01-01 20:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
( | ||
"activities", | ||
"0002_communityactivity_content_communityactivity_slug_and_more", | ||
), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="communityactivity", | ||
name="title", | ||
field=models.CharField(default="Activity Name", max_length=512), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
from django.db import models | ||
from utils.images import upload_image_to | ||
|
||
# Create your models here. | ||
from ckeditor_uploader.fields import RichTextUploadingField | ||
from utils.slugs import generate_unique_slug | ||
from django.utils.html import format_html | ||
|
||
|
||
class CommunityActivity(models.Model): | ||
title = models.CharField(max_length=512, default="Group Study") | ||
title = models.CharField(max_length=512, default="Activity Name") | ||
summary = models.CharField(max_length=1024, default="Activity description in short") | ||
slug = models.SlugField(unique=True, blank=True) | ||
|
||
description = models.TextField( | ||
max_length=10240, default="Detailed activity description" | ||
max_length=1024, default="Detailed activity description" | ||
) | ||
fa_icon = models.TextField(max_length=100, default="fa-solid fa-graduation-cap") | ||
cover_image = models.ImageField(upload_to=upload_image_to, null=True, blank=True) | ||
content = RichTextUploadingField(null=True, blank=True) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
def save(self, *args, **kwargs): | ||
if self.slug == "": | ||
self.slug = generate_unique_slug(self.title, CommunityActivity) | ||
super().save(args, kwargs) | ||
|
||
def get_absolute_url(self): | ||
return f"/activity/{self.slug}" | ||
|
||
def activity_page(self): | ||
return format_html( | ||
f'<a href="{self.get_absolute_url()}" target="_blank">View Page</a>' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{% extends "commons.html" %} | ||
{% block title %} {{blog.title}} {% endblock title%} | ||
{%block content %} | ||
|
||
<main class="pt-8 pb-16 lg:pt-16 lg:pb-24 bg-white dark:bg-gray-900 antialiased mb-4 mt-4"> | ||
<div class="flex justify-between px-4 mx-auto max-w-screen-xl m-4"> | ||
<article | ||
class="mx-auto w-full max-w-4xl format format-sm sm:format-base lg:format-lg format-amber dark:format-invert"> | ||
<header class="mb-4 lg:mb-6 not-format"> | ||
|
||
{% if ac.cover_image %} | ||
<div class=""> | ||
<img class="my-4 h-auto lg:w-full md:max-w-2xl sm:max-w-xl rounded-lg shadow-xl dark:shadow-gray-800" | ||
src="{{ac.cover_image.url}}" alt="{{ac.title}}"> | ||
</div> | ||
{%endif%} | ||
<h1 | ||
class="mb-4 text-3xl font-extrabold leading-tight text-gray-900 lg:mb-6 lg:text-4xl dark:text-white"> | ||
{{ac.title}} | ||
</h1> | ||
<address class="flex items-center mb-6 not-italic"> | ||
<div class="inline-flex items-center mr-3 text-sm text-gray-900 dark:text-white"> | ||
<div> | ||
<p class="text-base text-gray-500 dark:text-gray-400"> | ||
{{ac.summary}} | ||
</p> | ||
|
||
</div> | ||
</div> | ||
</address> | ||
|
||
</header> | ||
|
||
<div> | ||
{{ac.content | safe}} | ||
</div> | ||
|
||
</article> | ||
</div> | ||
</main> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
app_name = "activities" | ||
|
||
urlpatterns = [ | ||
path("<slug>", views.activities_item, name="activities_item"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpRequest | ||
from .models import CommunityActivity | ||
|
||
# Create your views here. | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def activities_item(request: HttpRequest, slug: str): | ||
ac = CommunityActivity.objects.get(slug=slug) | ||
context = {"ac": ac} | ||
return render(request, "activities/item.html", context=context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters