Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
renancamm committed Sep 15, 2017
0 parents commit 550e9d7
Show file tree
Hide file tree
Showing 37 changed files with 849 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
99 changes: 99 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Renan Cammarosano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# mozblog
Empty file added blog/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions blog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import Author, Post, Comment


admin.site.register(Author)
admin.site.register(Post)
admin.site.register(Comment)
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'
50 changes: 50 additions & 0 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-11 22:25
from __future__ import unicode_literals

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='Author',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('bio', models.TextField(blank=True, max_length=500, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField(max_length=500)),
('published_at', models.DateTimeField(auto_now=True)),
('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField(max_length=4000)),
('published_at', models.DateTimeField()),
('author', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='comment',
name='post',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.Post'),
),
]
33 changes: 33 additions & 0 deletions blog/migrations/0002_auto_20170911_2324.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-11 23:24
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

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

operations = [
migrations.AlterModelOptions(
name='author',
options={'ordering': ['user']},
),
migrations.AlterModelOptions(
name='comment',
options={'ordering': ['published_at']},
),
migrations.AlterModelOptions(
name='post',
options={'ordering': ['-published_at']},
),
migrations.AddField(
model_name='post',
name='title',
field=models.CharField(default='', max_length=200),
preserve_default=False,
),
]
21 changes: 21 additions & 0 deletions blog/migrations/0003_auto_20170911_2326.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-11 23:26
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

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

operations = [
migrations.AlterField(
model_name='post',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='blog.Author'),
),
]
23 changes: 23 additions & 0 deletions blog/migrations/0004_auto_20170912_0039.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-11 23:39
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('blog', '0003_auto_20170911_2326'),
]

operations = [
migrations.AlterField(
model_name='comment',
name='author',
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
preserve_default=False,
),
]
Empty file added blog/migrations/__init__.py
Empty file.
52 changes: 52 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse


class Author(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.TextField(max_length=500, blank=True, null=True)

class Meta:
ordering = ['user']

def __str__(self):
return self.get_full_name()

def get_absolute_url(self):
return reverse('author_detail', args=[str(self.id)])

def get_full_name(self):
return '%s %s' % (self.user.first_name, self.user.last_name)


class Post(models.Model):
title = models.CharField(max_length=200)
content = models.TextField(max_length=4000, )
published_at = models.DateTimeField()
author = models.ForeignKey(Author, on_delete=models.SET_NULL, null=True, blank=True)

class Meta:
ordering = ['-published_at']

def __str__(self):
return self.title

def get_absolute_url(self):
return reverse('post_detail', args=[str(self.id)])


class Comment(models.Model):
content = models.TextField(max_length=500, verbose_name='Comment')
published_at = models.DateTimeField(auto_now=True)
post = models.ForeignKey(Post, on_delete=models.CASCADE)
author = models.ForeignKey(User, on_delete=models.CASCADE)

class Meta:
ordering = ['published_at']

def __str__(self):
return self.content

def get_absolute_url(self):
return reverse('post_detail', args=[str(self.post.id)])
Binary file added blog/static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions blog/templates/blog/author_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% extends "base.html" %}

{% block content %}

<h2>{{ author }}</h2>
<p>{{ author.bio }}</p>

<hr>

<h5 class="mb-3"><small>ALL POSTS</small></h5>

{% for post in author.post_set.all %}
<div>
<h5 class="mb-0"><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h4>
<p class="text-secondary m-0"><small>{{ post.published_at }}</small></p>
<p>{{ post.content|truncatewords:10 }}</p>
</div>
{% endfor %}

{% endblock %}
19 changes: 19 additions & 0 deletions blog/templates/blog/author_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "base.html" %}

{% block content %}

<h5 class="mb-3"><small>AUTHORS</small></h5>

{% if author_list %}
{% for author in author_list %}
<div>
<h5><a href="{{ author.get_absolute_url }}">{{ author }}</a></h5>
</div>
{% endfor %}
{% else %}
<div>
<p>There are no authors.</p>
</div>
{% endif %}

{% endblock %}
18 changes: 18 additions & 0 deletions blog/templates/blog/comment_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "base.html" %}

{% block content %}


<h5 class="mt-0 mb-5">{{ post.title }}</h5>

{% load bootstrap4 %}
<form action="" method="post">
{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">Submit</button>
{% endbuttons %}

</form>

{% endblock %}
Loading

0 comments on commit 550e9d7

Please sign in to comment.