-
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
211 changed files
with
31,580 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/django-env | ||
/.vscode |
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,2 @@ | ||
release: python manage.py migrate | ||
web: gunicorn oneforallblog.wsgi |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,17 @@ | ||
from blog.models import Post, Tag | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
class PostAdmin(admin.ModelAdmin): | ||
list_display = ('title', 'slug', 'status', 'created_on') | ||
list_filter = ('status',) | ||
search_fields = ['title', 'content'] | ||
prepopulated_fields = {'slug': ('title',)} | ||
|
||
# class TagAdmin(admin.ModelAdmin): | ||
# list_display = ('title', 'slug', 'created_on') | ||
# search_fields = ['title'] | ||
# prepopulated_fields = {'slug': ('title',)} | ||
|
||
admin.site.register(Post, PostAdmin) | ||
admin.site.register(Tag) |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BlogConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'blog' |
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,28 @@ | ||
from django import forms | ||
from django.forms.models import ModelForm | ||
from .models import Post | ||
class PostForm(ModelForm): | ||
class Meta: | ||
model = Post | ||
fields = ['title', 'author', 'content', 'tags', 'status'] | ||
|
||
widgets = { | ||
'title' : forms.TextInput(attrs={'class': 'form-control'}), | ||
'author' : forms.Select(attrs={'class': 'form-control'}), | ||
'content' : forms.Textarea(attrs={'class': 'form-control'}), | ||
'tags' : forms.Select(attrs={'class': 'form-control'}), | ||
'status' : forms.Select(attrs={'class': 'form-control'}), | ||
} | ||
|
||
class PostEditForm(ModelForm): | ||
class Meta: | ||
model = Post | ||
fields = ['title', 'content', 'tags', 'status'] | ||
|
||
widgets = { | ||
'title' : forms.TextInput(attrs={'class': 'form-control'}), | ||
'content' : forms.Textarea(attrs={'class': 'form-control'}), | ||
'tags' : forms.Select(attrs={'class': 'form-control'}), | ||
'status' : forms.Select(attrs={'class': 'form-control'}), | ||
} | ||
|
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,46 @@ | ||
# Generated by Django 3.2 on 2021-08-03 17:14 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Tag', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=100, unique=True)), | ||
('slug', models.SlugField(max_length=200, unique=True)), | ||
('created_on', models.DateTimeField(auto_now_add=True)), | ||
], | ||
options={ | ||
'ordering': ['-created_on'], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='Post', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.CharField(max_length=200, unique=True)), | ||
('slug', models.SlugField(max_length=200, unique=True)), | ||
('updated_on', models.DateTimeField(auto_now=True)), | ||
('content', models.TextField()), | ||
('created_on', models.DateTimeField(auto_now_add=True)), | ||
('status', models.IntegerField(choices=[(0, 'Draft'), (1, 'Published')], default=0)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL)), | ||
('tags', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='blog.tag')), | ||
], | ||
options={ | ||
'ordering': ['-created_on'], | ||
}, | ||
), | ||
] |
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,17 @@ | ||
# Generated by Django 3.2.5 on 2021-08-04 10:21 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='tag', | ||
name='slug', | ||
), | ||
] |
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,66 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
from django.urls import reverse | ||
from django.template.defaultfilters import slugify | ||
from django.urls.base import reverse_lazy | ||
# Create your models here. | ||
POST_STATUS = ( | ||
(0, 'Draft'), | ||
(1, 'Published') | ||
) | ||
|
||
# non_url_safe = ['"', '#', '$', '%', '&', '+', | ||
# ',', '/', ':', ';', '=', '?', | ||
# '@', '[', '\\', ']', '^', '`', | ||
# '{', '|', '}', '~', "'"] | ||
|
||
class Tag(models.Model): | ||
title = models.CharField(max_length=100, unique=True) | ||
created_on = models.DateTimeField(auto_now_add=True) | ||
|
||
class Meta: | ||
ordering = ['-created_on'] | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
def get_absolute_url(self): | ||
return reverse('tag_list') | ||
|
||
class Post(models.Model): | ||
# def slugify(self, text): | ||
|
||
# non_safe = [c for c in text if c in non_url_safe] | ||
# if non_safe: | ||
# for c in non_safe: | ||
# text = text.replace(c, '') | ||
# text = u'-'.join(text.split()) | ||
# return text | ||
title = models.CharField(max_length=200, unique=True) | ||
slug = models.SlugField(max_length=200, unique=True) | ||
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts') | ||
updated_on = models.DateTimeField(auto_now=True) | ||
content = models.TextField() | ||
tags = models.ForeignKey(Tag, on_delete=models.CASCADE, null=True) | ||
created_on = models.DateTimeField(auto_now_add=True) | ||
status = models.IntegerField(choices=POST_STATUS, default=0) | ||
|
||
class Meta: | ||
ordering = ['-created_on'] | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
def save(self, *args, **kwargs): | ||
if not self.id: | ||
# Newly created object, so set slug | ||
self.slug = slugify(self.title) | ||
super(Post, self).save(*args, **kwargs) | ||
|
||
def get_absolute_url(self): | ||
return reverse_lazy('post_detail', args=(self.author, self.slug)) | ||
|
||
# def save(self, *args, **kwargs): | ||
# if not self.slug: | ||
# self.slug = self.slugify(self.title) | ||
# super(Post, self).save(*args, **kwargs) |
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,27 @@ | ||
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap'); | ||
:root { | ||
--light-font: #121212; | ||
--white: #ffffff; | ||
} | ||
|
||
body{ | ||
font-family: 'Poppins'; | ||
} | ||
|
||
/* Article list style start */ | ||
|
||
.list-group .card a{ | ||
text-decoration: none; | ||
color: var(--light-font); | ||
} | ||
|
||
.list-item { | ||
list-style: none; | ||
margin-inline-end: 1em; | ||
text-align: right; | ||
} | ||
.card-footer{ | ||
background-color: var(--white); | ||
} | ||
|
||
/* Article list style end */ |
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,104 @@ | ||
{% load static %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{% block title %} One for all Blog : Home {% endblock %}</title> | ||
<link rel="stylesheet" href="{% static 'css/style.css' %}"> | ||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.2/css/all.css"> | ||
<!-- CSS only --> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | ||
<!-- JavaScript Bundle with Popper --> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" | ||
crossorigin="anonymous"></script> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> | ||
<div class="container-fluid ps-3 pe-3"> | ||
<a class="navbar-brand" href="{% url 'home' %}">One for all</a> | ||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor01" | ||
aria-controls="navbarColor01" aria-expanded="true" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="navbar-collapse collapse" id="navbarColor01"> | ||
<ul class="navbar-nav me-auto mb-2 mb-lg-0"> | ||
<li class="nav-item"> | ||
<a class="nav-link active" aria-current="page" href="#">Home</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link" href="{% url 'tag_list' %}">Tags</a> | ||
</li> | ||
|
||
<li class="nav-item"> | ||
<a class="nav-link" href="#">About</a> | ||
</li> | ||
</ul> | ||
<form class="d-flex"> | ||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"> | ||
</form> | ||
{% if user.is_authenticated %} | ||
<div class="text-start mt-3 mb-3"> | ||
<a href="{% url 'create_post' user %}" class="btn btn-outline-light me-2">Create post</a> | ||
</div> | ||
<ul class="navbar-nav"> | ||
<li class="nav-item dropdown"> | ||
<a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLink" role="button" | ||
data-bs-toggle="dropdown" aria-expanded="false"> | ||
<img src="https://github.com/mdo.png" alt="mdo" width="32" height="32" class="rounded-circle"> | ||
</a> | ||
<ul class="dropdown-menu dropdown-menu-lg-end" aria-labelledby="navbarDarkDropdownMenuLink"> | ||
<li> | ||
<h6 class="dropdown-header">{{ user.first_name }} {{ user.last_name }}</h6> | ||
<a class="dropdown-item" href="">@{{ user }}</a> | ||
</li> | ||
<li></li> | ||
|
||
<li> | ||
<hr class="dropdown-divider"> | ||
</li> | ||
|
||
<li><a class="dropdown-item" href="{% url 'create_post' user %}">Create post</a></li> | ||
<li><a class="dropdown-item" href="{% url 'dashboard' user %}">Dashboard</a></li> | ||
<li><a class="dropdown-item" href="{% url 'change_password' %}">Change Password</a></li> | ||
|
||
<li> | ||
<hr class="dropdown-divider"> | ||
</li> | ||
|
||
<li><a class="dropdown-item" href="{% url 'confirm-logout' %}">Log out</a></li> | ||
</ul> | ||
</li> | ||
</ul> | ||
|
||
{% else %} | ||
<div class="text-start mt-3 mb-3"> | ||
<a href="{% url 'login' %}" class="btn btn-outline-light me-2">Login</a> | ||
<a href="{% url 'register' %}" class="btn btn-warning me-2">Sign up</a> | ||
|
||
</div> | ||
{% endif %} | ||
|
||
</div> | ||
</div> | ||
</nav> | ||
|
||
{% block content %} | ||
{% endblock %} | ||
|
||
<hr> | ||
<footer class="footer mt-auto py-3 bg-dark "> | ||
<div class="container"> | ||
<span class="m-0 text-light text-center">Copyright © magbanum</span> | ||
</div> | ||
</footer> | ||
</body> | ||
|
||
</html> |
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,21 @@ | ||
{% extends "blog/base_home.html" %} | ||
{% block title %} One for all Blog : Create post {% endblock %} | ||
{% block content %} | ||
{% if user.is_authenticated %} | ||
|
||
<br> | ||
<h3 class="pb-4 fst text-center"> | ||
Create post | ||
</h3> | ||
<hr> | ||
<div class="ms-4 me-4"> | ||
<form method="POST"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button class="btn btn-outline-dark me-2">Save</button> | ||
</form> | ||
</div> | ||
{% else %} | ||
<strong>You are not logged in.</strong> | ||
{% endif %} | ||
{% 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,27 @@ | ||
{% extends "blog/base_home.html" %} | ||
{% block title %} One for all Blog : Delete post {% endblock %} | ||
{% block content %} | ||
|
||
<br> | ||
<h3 class="pb-4 fst text-center"> | ||
{{ post.title}} | ||
</h3> | ||
<hr> | ||
{% if user.is_authenticated %} {% if user.id == post.author.id %} | ||
|
||
|
||
<div class="position-relative text-center border border-1 m-5 p-3 rounded"> | ||
<form action="" method="POST"> | ||
{% csrf_token %} | ||
<strong>Are you sure you want to delete this post? It can't be undone! </strong> | ||
<strong>Instead you can Edit the post status to "Draft".</strong><br><br> | ||
<button class="btn btn-danger">Delete Post</button> | ||
</form> | ||
<hr> | ||
<a href="{% url 'edit_post' user post.slug %}" class="btn btn-primary">Edit</a> | ||
<a href="{{ request.META.HTTP_REFERER }}" class="btn btn-secondary">Back</a> | ||
</div> | ||
|
||
{% else %} You are not allowed here {% endif %} {% else %} You are not logged in {% endif %} | ||
{% endblock %} | ||
|
Oops, something went wrong.