Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

project structure refactored #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions .env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# django
DJANGO_DEBUG=off
DJANGO_SECRET_KEY=

# postgres
DATABASE_URL="postgres://user:password@localhost:5432/database"
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
.DS_Store
.idea
uploads
kodilan/media

# Django #
*.log
*.pot
*.pyc
__pycache__
db.sqlite3
media

# Backup files #
*.bak
Expand Down
File renamed without changes.
File renamed without changes.
136 changes: 136 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
"""
Django settings for config project.

Generated by 'django-admin startproject' using Django 3.0.6.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

import environ

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
ROOT_DIR = environ.Path(__file__) - 3
APPS_DIR = ROOT_DIR.path("kodilan")

env = environ.Env()


READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=True)
if READ_DOT_ENV_FILE:
# OS environment variables take precedence over variables from .env
env.read_env(str(ROOT_DIR.path(".env")))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env(
"DJANGO_SECRET_KEY", default="adsbz3wt%#b3n&-k2m0woxk5b-tvaz-8=3uuoim_y(j$z=-0+n"
)
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DJANGO_DEBUG", False)

# Application definition

DJANGO_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
]

THIRD_PARTY_APPS = ["rest_framework"]

LOCAL_APPS = ["kodilan.posts.apps.PostsConfig"]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS


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 = "config.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [str(ROOT_DIR.path("templates"))],
"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",
],
},
},
]

WSGI_APPLICATION = "config.wsgi.application"


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

DATABASES = {"default": env.db("DATABASE_URL")}

# Password validation
# https://docs.djangoproject.com/en/3.0/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.0/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.0/howto/static-files/

STATIC_URL = "/static/"

STATICFILES_DIRS = [str(APPS_DIR.path("static"))]

MEDIA_ROOT = str(APPS_DIR("media"))

MEDIA_URL = "/m/"


REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "kodilan.baseapp.pagination.StandardResultsSetPagination",
"PAGE_SIZE": 10,
}
3 changes: 3 additions & 0 deletions config/settings/dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .base import * # noqa

ALLOWED_HOSTS = ["*"]
5 changes: 5 additions & 0 deletions config/settings/prod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .base import * # noqa

SECRET_KEY = env("DJANGO_SECRET_KEY")

ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS")
2 changes: 1 addition & 1 deletion kodilan/urls.py → config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.contrib import admin
from django.urls import include, path
from rest_framework import routers
from posts import views
from kodilan.posts import views

router = routers.DefaultRouter()

Expand Down
4 changes: 2 additions & 2 deletions kodilan/wsgi.py → config/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
WSGI config for kodilan project.
WSGI config for config project.

It exposes the WSGI callable as a module-level variable named ``application``.

Expand All @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'kodilan.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.dev')

application = get_wsgi_application()
File renamed without changes.
19 changes: 11 additions & 8 deletions kodilan/mail.py → kodilan/baseapp/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@


def do_mail(email, title, theme, variables):
msg_plain = render_to_string('mail/{}.txt'.format(theme), variables)
msg_html = render_to_string('mail/{}.html'.format(theme), variables)
msg_plain = render_to_string("mail/{}.txt".format(theme), variables)
msg_html = render_to_string("mail/{}.html".format(theme), variables)
try:
send_mail(
'Kodilan - ' + title,
"Kodilan - " + title,
msg_plain,
getattr(settings, "SENDER_MAIL", ""),
[email],
fail_silently=False,
html_message=msg_html
html_message=msg_html,
)
except ConnectionRefusedError as e:
print('There was an error sending an email: ', e)
pass
print("There was an error sending an email: ", e)


# todo: create post will update
def send_activation(email, first_name, last_name, token):
do_mail(email, "İlan Onay", "activation",
{'first_name': first_name, 'last_name': last_name, 'code': token})
do_mail(
email,
"İlan Onay",
"activation",
{"first_name": first_name, "last_name": last_name, "code": token},
)
21 changes: 21 additions & 0 deletions kodilan/baseapp/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class StandardResultsSetPagination(PageNumberPagination):
page_size = 20
page_size_query_param = "page_size"
max_page_size = 1000

def get_paginated_response(self, data):
return Response(
{
"links": {
"next": self.get_next_link(),
"previous": self.get_previous_link(),
},
"count": self.page.paginator.count,
"results": data,
"page_number": self.page.number,
}
)
19 changes: 0 additions & 19 deletions kodilan/customs.py

This file was deleted.

Empty file added kodilan/posts/__init__.py
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion posts/apps.py → kodilan/posts/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class PostsConfig(AppConfig):
name = 'posts'
name = 'kodilan.posts'
File renamed without changes.
18 changes: 18 additions & 0 deletions kodilan/posts/migrations/0008_auto_20200604_1136.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.6 on 2020-06-04 11:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('posts', '0007_auto_20200601_1934'),
]

operations = [
migrations.AlterField(
model_name='post',
name='status',
field=models.PositiveSmallIntegerField(choices=[(0, 'ONAYLANMADI'), (1, 'ONAYLANDI'), (2, 'YAYINLANMADI')]),
),
]
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading