Skip to content

Commit 5c38de0

Browse files
committed
Init django comments
1 parent 513fb3a commit 5c38de0

29 files changed

+563
-0
lines changed

django-comments/.gitignore

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
.venv/
126+
env/
127+
venv/
128+
ENV/
129+
env.bak/
130+
venv.bak/
131+
132+
# Spyder project settings
133+
.spyderproject
134+
.spyproject
135+
136+
# Rope project settings
137+
.ropeproject
138+
139+
# mkdocs documentation
140+
/site
141+
142+
# mypy
143+
.mypy_cache/
144+
.dmypy.json
145+
dmypy.json
146+
147+
# Pyre type checker
148+
.pyre/
149+
150+
# pytype static type analyzer
151+
.pytype/
152+
153+
# Cython debug symbols
154+
cython_debug/
155+
156+
# PyCharm
157+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
158+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
159+
# and can be added to the global gitignore or merged into this file. For a more nuclear
160+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
161+
#.idea/
162+
163+
# Volumes
164+
node_modules/
165+

django-comments/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# django-comments
2+
3+
4+
A starter Django project with Comments model and TinyMCE
5+
6+
7+
## Setup Django Project
8+
9+
Create a Python virtual environment,
10+
11+
```bash
12+
$ python3 -m venv .venv
13+
```
14+
15+
Activate the virtual environment,
16+
17+
```bash
18+
$ source .venv/bin/activate
19+
```
20+
21+
Install Python packages,
22+
23+
```bash
24+
$ pip install -r requirements.txt
25+
```
26+
27+
## Run Django Development Server
28+
29+
Run the following command to start the development server,
30+
31+
```bash
32+
$ python manage.py runserver
33+
```
34+
35+
Then visit [`http://127.0.0.1:8000`](http://127.0.0.1:8000)

django-comments/articles/__init__.py

Whitespace-only changes.

django-comments/articles/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

django-comments/articles/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class ArticlesConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'articles'

django-comments/articles/migrations/__init__.py

Whitespace-only changes.

django-comments/articles/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% load static %}
2+
3+
<!DOCTYPE html>
4+
<html lang="en">
5+
<head>
6+
<meta charset="UTF-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
9+
<title>{% block title %}{% endblock %}</title>
10+
</head>
11+
<body>
12+
{% include 'header.html' %}
13+
{% block content %}
14+
{% endblock %}
15+
</body>
16+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="m-8">
2+
<ul class="flex text-xl flex-row justify-center space-x-16">
3+
<li>
4+
<a class="text-xl text-green-400" href="#">Home</a>
5+
</li>
6+
<li>
7+
<a class="text-xl text-blue-400" href="#">Solutions</a>
8+
</li>
9+
<li>
10+
<a class="text-xl text-blue-400" href="#">About</a>
11+
</li>
12+
<li>
13+
<button class="bg-purple-300 p-2 rounded-lg font-satisfy text-xl border-font-semibold hover:bg-transparent hover:border-purple-100 hover:border-solid hover:border-2">Free Trial</button>
14+
</li>
15+
</ul>
16+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "base.html" %}
2+
{% load static %}
3+
4+
{% block title %} Django & Comments {% endblock %}
5+
6+
{% block content %}
7+
<h1 class="text-center">Django & Comments Example</h1>
8+
<p class="m-4 text-red-400 text-center">Hello, this is an example Django project with Comments.</p>
9+
10+
11+
<h2 class="p-20 text-4xl text-center text-green-500">A simple page using TinyMCE!</h2>
12+
<h3 class="text-2xl text-center text-purple-700">Very impressive 😁</h3>
13+
{% endblock %}

django-comments/articles/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

django-comments/articles/views.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.
4+
def index(request):
5+
return render(request, "index.html")

django-comments/comments/__init__.py

Whitespace-only changes.

django-comments/comments/admin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.contrib import admin
2+
3+
from comments import Comment
4+
5+
# Register your models here.
6+
@admin.register(Comment)
7+
class CommentAdmin(admin.ModelAdmin):
8+
list_display = ['content_type', 'user', 'content', 'creation_date', 'is_removed']
9+
search_fields = ['content']
10+
readonly_fields = ['content_type', 'object_id', 'user', 'creation_date', 'content', 'content_object']

django-comments/comments/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class CommentsConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'comments'

django-comments/comments/forms.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
from django import forms
3+
4+
from crispy_forms.helper import FormHelper
5+
from crispy_forms.layout import ButtonHolder, Column, Layout, Row, Submit
6+
from tinymce.widgets import TinyMCE
7+
8+
from comments import Comment
9+
10+
11+
CUSTOM_MCE_ATTRS = {
12+
'theme': 'silver',
13+
'height': 300,
14+
'width': '100%',
15+
'menubar': False,
16+
'plugins': 'advlist,autolink,lists,link,image,charmap,print,preview,anchor,'
17+
'searchreplace,visualblocks,code,fullscreen,insertdatetime,media,table,paste'
18+
'code,help,wordcount',
19+
'toolbar': 'bold italic underline strikethrough forecolor backcolor |'
20+
'bullist numlist outdent indent | alignleft alignright alignjustify |'
21+
'link | removeformat help',
22+
}
23+
24+
25+
class CommentForm(forms.ModelForm):
26+
content = forms.CharField(label='New Comment', widget=TinyMCE(mce_attrs=CUSTOM_MCE_ATTRS))
27+
28+
class Meta:
29+
model = Comment
30+
fields = ('content',)
31+
32+
def __init__(self, *args, **kwargs):
33+
super(CommentForm, self).__init__(*args, **kwargs)
34+
self.helper = FormHelper(self)
35+
self.helper.layout = Layout(
36+
Row(Column('content', css_class='form-group col-md-12 mb-0'),),
37+
ButtonHolder(Submit(type='submit', name='buttonValue', value='Add Comment', css_class='btn btn-warning'))
38+
)

django-comments/comments/migrations/__init__.py

Whitespace-only changes.

django-comments/comments/models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from django.contrib.auth.models import User
2+
from django.contrib.contenttypes.fields import GenericForeignKey
3+
from django.contrib.contenttypes.models import ContentType
4+
from django.db import models
5+
from django.utils import timezone
6+
7+
from tinymce.models import HTMLField
8+
9+
10+
class Comment(models.Model):
11+
content = HTMLField(verbose_name='Content', max_length=512)
12+
user = models.ForeignKey(User, on_delete=models.PROTECT)
13+
creation_date = models.DateTimeField(verbose_name='Date/Time Created', default=timezone.now)
14+
is_removed = models.BooleanField(verbose_name='Is Removed', default=False)
15+
16+
# Content-object fields
17+
content_type = models.ForeignKey(ContentType, verbose_name='Content-Type', on_delete=models.CASCADE)
18+
object_id = models.PositiveBigIntegerField(verbose_name="Object ID", db_index=True)
19+
content_object = GenericForeignKey(ct_field='content_type', fk_field='object_id')
20+
21+
class Meta:
22+
verbose_name = 'Comment'
23+
verbose_name_plural = 'Comments'
24+
ordering = ('createion_date')

django-comments/comments/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

django-comments/comments/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.shortcuts import render
2+
3+
# Create your views here.

django-comments/djangoconfig/__init__.py

Whitespace-only changes.

django-comments/djangoconfig/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for djangoconfig project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoconfig.settings')
15+
16+
application = get_asgi_application()

0 commit comments

Comments
 (0)