Skip to content
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
Empty file added BloggerProject/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions BloggerProject/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for BloggerProject project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BloggerProject.settings')

application = get_asgi_application()
126 changes: 126 additions & 0 deletions BloggerProject/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
"""
Django settings for BloggerProject project.

Generated by 'django-admin startproject' using Django 6.0.4.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-%mv^#i2jc0!j3w49^q)(-s$jaklcfpf1ukog^he@80n^l16q(^'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main',
'blog',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'BloggerProject.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'BloggerProject.wsgi.application'


# Database
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/6.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.0/howto/static-files/

STATIC_URL = 'static/'
STATICFILES_DIRS = [
BASE_DIR / "main" / "static",
]

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
27 changes: 27 additions & 0 deletions BloggerProject/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
URL configuration for BloggerProject project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/6.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static
from . import settings

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls')),
path('blog/', include('blog.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

16 changes: 16 additions & 0 deletions BloggerProject/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for BloggerProject project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BloggerProject.settings')

application = get_wsgi_application()
Empty file added blog/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
name = 'blog'
24 changes: 24 additions & 0 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 6.0.4 on 2026-04-14 19:01

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=2048)),
('content', models.TextField()),
('is_published', models.BooleanField(default=True)),
('published_at', models.DateTimeField(auto_now_add=True)),
],
),
]
30 changes: 30 additions & 0 deletions blog/migrations/0002_post_media_post_poster_post_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 6.0.4 on 2026-04-15 16:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blog', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='post',
name='media',
field=models.FileField(default='', upload_to='pdf/'),
preserve_default=False,
),
migrations.AddField(
model_name='post',
name='poster',
field=models.ImageField(default='images/default.jpg', upload_to='images/'),
),
migrations.AddField(
model_name='post',
name='video',
field=models.FileField(default='', upload_to='videos/'),
preserve_default=False,
),
]
23 changes: 23 additions & 0 deletions blog/migrations/0003_alter_post_media_alter_post_video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 6.0.4 on 2026-04-15 20:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('blog', '0002_post_media_post_poster_post_video'),
]

operations = [
migrations.AlterField(
model_name='post',
name='media',
field=models.FileField(blank=True, null=True, upload_to='pdf/'),
),
migrations.AlterField(
model_name='post',
name='video',
field=models.FileField(blank=True, null=True, upload_to='videos/'),
),
]
Empty file added blog/migrations/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.db import models

# Create your models here.

class Post(models.Model):

title = models.CharField(max_length=2048)

content = models.TextField()

is_published = models.BooleanField(default=True)

published_at = models.DateTimeField(auto_now_add=True)

poster = models.ImageField(upload_to="images/", default="images/default.jpg")
media = models.FileField(upload_to="pdf/", null=True, blank=True)
video = models.FileField(upload_to="videos/", null=True, blank=True)
61 changes: 61 additions & 0 deletions blog/templates/blog/add_post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends 'main/base.html' %}

{% block content %}
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="editor-container">
<div class="editor-header mb-5">
<h1 class="display-5 fw-bold">New <span class="text-accent">Chapter.</span></h1>
<p class="text-muted">Share your thoughts with the world in a clean, distraction-free environment.</p>
</div>

<form action="{% url 'main:add_post_view' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}

<div class="form-group-premium">
<input type="text" name="title" class="title-input" placeholder="Title of your story..." required>
</div>

<div class="form-group-premium">
<textarea name="content" class="content-input" placeholder="Start writing your masterpiece..." required></textarea>
</div>

<div class="form-footer mt-5 d-flex justify-content-between align-items-center flex-wrap gap-3">

<div class="d-flex gap-2">
<label for="id_poster" class="btn-action shadow-sm" style="cursor: pointer; padding: 8px 15px; font-size: 0.9rem;">
<i class="bi bi-image me-1"></i> Image
</label>
<input type="file" name="poster" id="id_poster" accept="image/*" style="display: none;">

<label for="id_video" class="btn-action shadow-sm" style="cursor: pointer; padding: 8px 15px; font-size: 0.9rem;">
<i class="bi bi-play-btn me-1"></i> Video
</label>
<input type="file" name="video" id="id_video" accept="video/*" style="display: none;">

<label for="id_media" class="btn-action shadow-sm" style="cursor: pointer; padding: 8px 15px; font-size: 0.9rem;">
<i class="bi bi-file-earmark-pdf me-1"></i> PDF
</label>
<input type="file" name="media" id="id_media" accept=".pdf" style="display: none;">
</div>

<button type="submit" class="btn-action shadow-lg">Publish Now</button>

<script>

document.querySelectorAll('input[type="file"]').forEach(input => {
input.addEventListener('change', function() {
if (this.files && this.files.length > 0) {

const label = document.querySelector(`label[for="${this.id}"]`);
const fileName = this.files[0].name;

label.style.background = "#28a745";
label.style.color = "white";
label.style.borderColor = "#28a745";
label.innerHTML = `<i class="bi bi-check-circle-fill"></i> ${fileName.substring(0, 10)}...`;
}
});
});
</script>
{% endblock %}
Loading