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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/coolpress.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# coolpress
# Fatma Nasser
CoolPress is an application to show the power of web development using Django
Empty file added coolpress/__init__.py
Empty file.
Empty file added coolpress/coolpress/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions coolpress/coolpress/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for coolpress 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.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

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

application = get_asgi_application()
10 changes: 10 additions & 0 deletions coolpress/coolpress/settings-prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

from coolpress.settings import *

DEBUG = False
ALLOWED_HOSTS = ['*']

SECRET_KEY = os.environ['DJANGO_SECRET_KEY']

STATIC_ROOT = "/var/www/coolpress/static/"
126 changes: 126 additions & 0 deletions coolpress/coolpress/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import os
from pathlib import Path

# 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/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-w$_pqet301==4$)f39qr#8*5psljee+5(07vx6&de7k$k^8ea@'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'rest_framework',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'press',
]

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 = 'coolpress.urls'

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

WSGI_APPLICATION = 'coolpress.wsgi.application'


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

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


# Password validation
# https://docs.djangoproject.com/en/3.2/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/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

HOME_INDEX = 'posts-list'
LOGIN_REDIRECT_URL = HOME_INDEX
LOGOUT_REDIRECT_URL = HOME_INDEX

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

MEDIASTACK_ACCESS_KEY = 'beecae97e6a25b2c2e0fbf79b7039510'
31 changes: 31 additions & 0 deletions coolpress/coolpress/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.contrib import admin
from django.urls import path, include

from press import views
from rest_framework import routers

router = routers.DefaultRouter()
router.register(r'categories', views.CategoryViewSet)
router.register(r'posts', views.PostViewSet)
router.register(r'authors', views.AuthorsViewSet)

urlpatterns = [
path('home/', views.home),
path('post_details/<int:post_id>', views.post_detail, name='posts-detail'),
path('post/<int:post_id>/comment-add/', views.add_post_comment, name='comment-add'),
path('post/update/<int:post_id>', views.post_update, name='post-update'),
path('post/add/', views.post_update, name='post-add'),
path('about/', views.AboutView.as_view(), name='about'),
path('categories/', views.CategoryListView.as_view(), name='category-list'),
path('posts/', views.PostClassBasedListView.as_view(), name='posts-list'),
path('posts/<str:category_slug>', views.PostClassFilteringListView.as_view(), name='posts-list-by-category'),
path('posts-author/<str:username>', views.AuthorClassFilteringListView.as_view(), name='author_list'),
path('api-category/<slug:slug>', views.category_api, name='category-api'),
path('api-categories/', views.categories_api, name='categories-api'),
path('api/', include(router.urls)),
path('post-search/', views.search_post, name='post-search'),
path('api-auth/', include('rest_framework.urls')),
path('accounts/', include('django.contrib.auth.urls')),
path('author/<int:author_id>', views.author_details, name='author-detail'),
path('admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions coolpress/coolpress/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for coolpress 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/3.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()
Binary file added coolpress/dumpdata.jason
Binary file not shown.
22 changes: 22 additions & 0 deletions coolpress/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coolpress.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()
Empty file added coolpress/press/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions coolpress/press/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.contrib import admin

# Register your models here.
from django.urls import reverse
from django.utils.html import format_html

from press.models import Category, Post, CoolUser


class CategoryAdmin(admin.ModelAdmin):
list_display = ('label', 'view_post_lisk', 'slug')

def view_post_lisk(self, obj):
post_cnt = obj.post_set.count()
url = reverse('admin:press_post_changelist') + f'?category__id={obj.id}'

return format_html(f'<a href="{url}">{post_cnt}</a>')


admin.site.register(Category, CategoryAdmin)


class PostAdmin(admin.ModelAdmin):
date_hierarchy = 'creation_date'
search_fields = ['title', 'author__user__username']
list_display = ['title', 'author']
list_filter = ['category']


admin.site.register(Post, PostAdmin)


class CoolUserAdmin(admin.ModelAdmin):
pass


admin.site.register(CoolUser, CoolUserAdmin)
6 changes: 6 additions & 0 deletions coolpress/press/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class PressConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'press'
6 changes: 6 additions & 0 deletions coolpress/press/context_processors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from press.models import Category


def categories_processor(request):
categories = Category.objects.all()
return {'categories': categories}
44 changes: 44 additions & 0 deletions coolpress/press/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django import forms
from django.forms import ModelForm

from press.models import Post, Category, CoolUser


class CommentForm(forms.Form):
body = forms.CharField(label='Add some comment',
widget=forms.Textarea(attrs={'class': 'form-control'}))
votes = forms.IntegerField(label='Vote the post', min_value=1, max_value=10,
widget=forms.NumberInput(attrs={'class': 'form-control'}))


class PostForm(ModelForm):
class Meta:
model = Post
fields = ['title', 'body', 'image_link', 'category', 'status']
widgets = {
'title': forms.TextInput(attrs={'class': 'form-control'}),
'body': forms.Textarea(attrs={'class': 'form-control'}),
'image_link': forms.TextInput(attrs={'class': 'form-control'}),
'category': forms.Select(attrs={'class': 'form-control'}),
'status': forms.Select(attrs={'class': 'form-control'}),
}


class CategoryForm(ModelForm):
class Meta:
model = Category
fields = ['slug', 'label']
widgets = {
'slug': forms.TextInput(attrs={'class': 'form-control'}),
'label': forms.TextInput(attrs={'class': 'form-control'}),
}


class CoolUserForm(ModelForm):
email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
github_profile = forms.CharField(max_length=254,
help_text='Required. Inform a valid email address.')

class Meta:
model = CoolUser
fields = ('github_profile',)
Loading