generated from BuildForSDG/python-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from BuildForSDG/ft-zoitblog
Ft zoitblog
- Loading branch information
Showing
27 changed files
with
733 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,15 @@ | ||
## Description | ||
This Pull Request contains the Blog application for ZOIT Emergency Accident Response project. Since one of the objective of the project is to make a social website where users can interact, post and read present and past accident information nearest and distant from them. The blog shall be updated everyday by an admin who shall gather accident complaints from accident victims and eyewitness report to validate, post and update the general public. | ||
The application was built with Django full stack with all the dependencies installed. | ||
get the Readme file of the src folder to get instructions on how to clone and install dependencies and libraries for the repository. | ||
This pull request is related to issue number #18 | ||
|
||
## How Has This Been Tested? | ||
1. First locate the application directory on the Team-102-GoodHealthAndWellBeing repo by: | ||
cd Team-102-GoodHealthAndWellBeing | ||
cd src | ||
cd mysite | ||
2. create your own virtual env or try 'workon zoitblog' | ||
3 Create superuser in other to access the admin | ||
4. Run server with python manage.py runserver | ||
5. Run python -m pip install Pillow to enable the app access ImageField |
Empty file.
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,22 @@ | ||
from django.contrib import admin | ||
from .models import Post, Comment | ||
|
||
class PostAdmin(admin.ModelAdmin): | ||
list_display = ('title', 'slug', 'status','created_on') | ||
list_filter = ("status",) | ||
search_fields = ['title', 'content'] | ||
prepopulated_fields = {'slug': ('title',)} | ||
|
||
|
||
admin.site.register(Post, PostAdmin) | ||
|
||
@admin.register(Comment) | ||
class CommentAdmin(admin.ModelAdmin): | ||
list_display = ('name', 'body', 'post', 'created_on', 'active') | ||
list_filter = ('active', 'created_on') | ||
search_fields = ('name', 'email', 'body') | ||
actions = ['approve_comments'] | ||
|
||
def approve_comments(self, request, queryset): | ||
queryset.update(active=True) | ||
# Register your models here. |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BlogConfig(AppConfig): | ||
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,8 @@ | ||
from .models import Comment | ||
from django import forms | ||
|
||
|
||
class CommentForm(forms.ModelForm): | ||
class Meta: | ||
model = Comment | ||
fields = ('name', 'email', 'body') |
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,33 @@ | ||
# Generated by Django 3.0.6 on 2020-05-27 00:42 | ||
|
||
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='Post', | ||
fields=[ | ||
('id', models.AutoField(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, 'Publish')], default=0)), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL)), | ||
], | ||
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,29 @@ | ||
# Generated by Django 3.0.6 on 2020-05-27 15:33 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=80)), | ||
('email', models.EmailField(max_length=254)), | ||
('body', models.TextField()), | ||
('created_on', models.DateTimeField(auto_now_add=True)), | ||
('active', models.BooleanField(default=False)), | ||
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='blog.Post')), | ||
], | ||
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,20 @@ | ||
# Generated by Django 3.0.6 on 2020-06-09 13:20 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0002_comment'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='post', | ||
name='cover', | ||
field=models.ImageField(default=django.utils.timezone.now, upload_to='images/'), | ||
preserve_default=False, | ||
), | ||
] |
Empty file.
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,40 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
|
||
STATUS = ( | ||
(0,"Draft"), | ||
(1,"Publish") | ||
) | ||
|
||
class Post(models.Model): | ||
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() | ||
created_on = models.DateTimeField(auto_now_add=True) | ||
status = models.IntegerField(choices=STATUS, default=0) | ||
cover = models.ImageField(upload_to='images/') | ||
|
||
class Meta: | ||
ordering = ['-created_on'] | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
class Comment(models.Model): | ||
post = models.ForeignKey(Post,on_delete=models.CASCADE,related_name='comments') | ||
name = models.CharField(max_length=80) | ||
email = models.EmailField() | ||
body = models.TextField() | ||
created_on = models.DateTimeField(auto_now_add=True) | ||
active = models.BooleanField(default=False) | ||
|
||
class Meta: | ||
ordering = ['created_on'] | ||
|
||
def __str__(self): | ||
return 'Comment {} by {}'.format(self.body, self.name) | ||
|
||
# Create your models here. |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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 . import views | ||
from django.urls import path | ||
|
||
urlpatterns = [ | ||
path('', views.PostList.as_view(), name='home'), | ||
path('<slug:slug>/', views.PostDetail.as_view(), name='post_detail'), | ||
path('<slug:slug>/', views.post_detail, name='post_detail') | ||
|
||
] |
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,50 @@ | ||
from django.views import generic | ||
from .models import Post | ||
from .forms import CommentForm | ||
from django.shortcuts import render, get_object_or_404 | ||
|
||
class PostList(generic.ListView): | ||
queryset = Post.objects.filter(status=1).order_by('-created_on') | ||
template_name = 'index.html' | ||
|
||
class PostDetail(generic.DetailView): | ||
model = Post | ||
template_name = 'post_detail.html' | ||
class PostList(generic.ListView): | ||
queryset = Post.objects.filter(status=1).order_by('-created_on') | ||
template_name = 'index.html' | ||
paginate_by = 3 | ||
|
||
class PostList(generic.ListView): | ||
queryset = Post.objects.filter(status=1).order_by('-created_on') | ||
template_name = 'index.html' | ||
|
||
class PostDetail(generic.DetailView): | ||
model = Post | ||
template_name = 'post_detail.html' | ||
def post_detail(request, slug): | ||
template_name = 'post_detail.html' | ||
post = get_object_or_404(Post, slug=slug) | ||
comments = post.comments.filter(active=True) | ||
new_comment = None | ||
# Comment posted | ||
if request.method == 'POST': | ||
comment_form = CommentForm(data=request.POST) | ||
if comment_form.is_valid(): | ||
|
||
# Create Comment object but don't save to database yet | ||
new_comment = comment_form.save(commit=False) | ||
# Assign the current post to the comment | ||
new_comment.post = post | ||
# Save the comment to the database | ||
new_comment.save() | ||
else: | ||
comment_form = CommentForm() | ||
|
||
return render(request, template_name, {'post': post, | ||
'comments': comments, | ||
'new_comment': new_comment, | ||
'comment_form': comment_form}) | ||
|
||
|
||
# Create your views here. |
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,21 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
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,16 @@ | ||
""" | ||
ASGI config for mysite 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/3.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.