Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge my local changes #13

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a3d8c60
Finish Introduction and Django Admin
a0123055u Dec 23, 2023
bf230da
Finish generic relationships
a0123055u Dec 24, 2023
a6fa77a
Finish html frameworks
a0123055u Dec 25, 2023
a992392
local changes
a0123055u Dec 25, 2023
6418dbc
Local model fix
a0123055u Dec 26, 2023
04d12b8
Finish custom filters
a0123055u Dec 26, 2023
e3bfd39
Finish django configurations
a0123055u Dec 31, 2023
dd31858
Finish logging
a0123055u Jan 1, 2024
c82267f
Finish security ad passwords
a0123055u Jan 1, 2024
458094c
master branch cache codes
a0123055u Jan 1, 2024
ac1611d
Finish caching
a0123055u Jan 1, 2024
73ab682
Finish database optimization
a0123055u Jan 1, 2024
8240ab9
Finish custom User model
a0123055u Jan 2, 2024
5027c4b
Finish django registration
a0123055u Jan 2, 2024
c57b68d
Finish django Allauth
a0123055u Jan 2, 2024
9ecb9e8
Finish First-Party Django REST API
a0123055u Jan 2, 2024
cdc2835
Merge pull request #1 from a0123055u/local-branch
a0123055u Jan 2, 2024
9309799
Finish Serializers
a0123055u Jan 3, 2024
52dcdec
Finish DRF views
a0123055u Jan 3, 2024
e49349c
Merge pull request #2 from a0123055u/master
a0123055u Jan 3, 2024
bde7a9b
Local Changes
a0123055u Jan 5, 2024
56b54c9
Finish authentication
a0123055u Jan 5, 2024
ad835c4
Merge pull request #3 from a0123055u/local-branch
a0123055u Jan 5, 2024
1862d3c
Finish permissions
a0123055u Jan 5, 2024
627eedc
Finish related fields
a0123055u Jan 6, 2024
d557a2d
Finish nested relationships
a0123055u Jan 6, 2024
28e1e42
Merge pull request #4 from a0123055u/local-branch
a0123055u Jan 8, 2024
40574f7
Finish browsable API
a0123055u Jan 8, 2024
92b5b8d
Finish viewsets and routers
a0123055u Jan 9, 2024
556b99b
Finish testing DRF with mocks
a0123055u Jan 13, 2024
9b3dfb3
Finish testing DRF with requests
a0123055u Jan 13, 2024
8057cf1
Finish caching
a0123055u Jan 14, 2024
c762103
Finish throttling
a0123055u Jan 14, 2024
838128b
Finish filtering
a0123055u Jan 14, 2024
049670c
Finish pagination and django filter
a0123055u Jan 14, 2024
937d930
Finish simplejwt
a0123055u Jan 14, 2024
727d328
Finish django-versatileimagefield
a0123055u Jan 15, 2024
caed19e
Finish JavaScript intro and fundamentals
a0123055u Jan 17, 2024
661e69f
Finish JavaScript functions
a0123055u Jan 17, 2024
aea9c15
Finish JavaScript classes
a0123055u Jan 17, 2024
609fccc
Finish JavaScript promises
a0123055u Jan 17, 2024
5b45b79
Finish ReactJS
a0123055u Jan 19, 2024
1b8056d
Finish JSX
a0123055u Jan 19, 2024
d4a1757
Finish fetch and React hooks
a0123055u Jan 19, 2024
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
Binary file added blango/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file added blango/__pycache__/wsgi.cpython-36.pyc
Binary file not shown.
137 changes: 128 additions & 9 deletions blango/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Django settings for blango project.

Generated by 'django-admin startproject' using Django 3.2.7.
Generated by 'django-admin startproject' using Django 3.2.5.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
Expand All @@ -10,7 +10,13 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os
from pathlib import Path
from configurations import Configuration
from configurations import values
from datetime import timedelta

# class Dev:

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -20,13 +26,19 @@
# 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-+sn%dpa!086+g+%44z9*^j^q-u4n!j(#wl)x9a%_1op@zz2+1-'
SECRET_KEY = 'django-insecure-&!=9y436&^-bc$qia-mxngyf&xx)@ct)8lu@)=qxg_07-=z01w'

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

ALLOWED_HOSTS = []

ALLOWED_HOSTS = ['*']
X_FRAME_OPTIONS = 'ALLOW-FROM ' + os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io'
CSRF_COOKIE_SAMESITE = None
CSRF_TRUSTED_ORIGINS = [os.environ.get('CODIO_HOSTNAME') + '-8000.codio.io']
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SAMESITE = 'None'
SESSION_COOKIE_SAMESITE = 'None'

# Application definition

Expand All @@ -37,24 +49,39 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'blog',
'crispy_forms',
'crispy_bootstrap5',
'debug_toolbar',
'blango_auth',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'rest_framework.authtoken',
'drf_yasg',
'django_filters',
'versatileimagefield',
]

MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'blango.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
"DIRS": [BASE_DIR / "templates"],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -99,14 +126,21 @@
},
]

PASSWORD_HASHERS = [
'django.contrib.auth.hashers.Argon2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
]



# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

TIME_ZONE = "UTC"
USE_I18N = True

USE_L10N = True
Expand All @@ -123,3 +157,88 @@
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"

# CACHES = {
# "default": {
# "BACKEND": "django.core.cache.backends.db.DatabaseCache",
# "LOCATION": "my_cache_table",
# }
# }
INTERNAL_IPS = ["192.168.10.226"]
AUTH_USER_MODEL = "blango_auth.User"
ACCOUNT_ACTIVATION_DAYS = 7
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

#

# class Prod(Dev):
# DEBUG = False
# SECRET_KEY = values.SecretValue()
# ALLOWED_HOSTS = values.ListValue(["localhost", "0.0.0.0", ".codio.io"])
# DATABASES = {
# "default": dj_database_url.config(default=f"sqlite:///{BASE_DIR}/db.sqlite3"),
# "alternative": dj_database_url.config(
# "ALTERNATIVE_DATABASE_URL",
# default=f"sqlite:///{BASE_DIR}/alternative_db.sqlite3",
# ),
# }

SITE_ID = 1

ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = "email"
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
# "rest_framework.permissions.IsAuthenticated",
"rest_framework.authentication.BasicAuthentication",
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.TokenAuthentication",
"rest_framework_simplejwt.authentication.JWTAuthentication"
# 'rest_framework.permissions.IsAuthenticated'
],
# "DEFAULT_PERMISSION_CLASSES": [
# "rest_framework.permissions.IsAuthenticatedOrReadOnly"
# ],

"DEFAULT_THROTTLE_CLASSES": [
"blog.api.throttling.AnonSustainedThrottle",
"blog.api.throttling.AnonBurstThrottle",
"blog.api.throttling.UserSustainedThrottle",
"blog.api.throttling.UserBurstThrottle",
],
"DEFAULT_THROTTLE_RATES": {
"anon_sustained": "500/day",
"anon_burst": "10/minute",
"user_sustained": "5000/day",
"user_burst": "100/minute",
},
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 100,
"DEFAULT_FILTER_BACKENDS": [
"django_filters.rest_framework.DjangoFilterBackend",
"rest_framework.filters.OrderingFilter"
],


}


SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {
"Token": {"type": "apiKey", "name": "Authorization", "in": "header"},
"Basic": {"type": "basic"},
}
}

SIMPLE_JWT = {
"ACCESS_TOKEN_LIFETIME": timedelta(days=1),
"REFRESH_TOKEN_LIFETIME": timedelta(days=7),
}

MEDIA_ROOT = BASE_DIR / "media"
MEDIA_URL = "/media/"

16 changes: 16 additions & 0 deletions blango/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
{% block content %}

{% endblock %}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
Empty file.
17 changes: 17 additions & 0 deletions blango/templates/rest_framework/api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "rest_framework/base.html" %}
{% block title %}{% if name %}{{ name }} – {% endif %} Blango REST API{% endblock %}

{% block branding %}
<a href="/" class="navbar-brand">
Blango REST API
</a>
{% endblock %}

{% block style %}
{{ block.super }}
<style>
div .navbar {
border-top-color: #1E90FF;
}
</style>
{% endblock %}
82 changes: 81 additions & 1 deletion blango/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import blog.views

"""blango URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
Expand All @@ -13,9 +15,87 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
import debug_toolbar
from django.conf import settings
from django.contrib import admin
from django.urls import path
from django.urls import path, include

import blog.views
import blango_auth.views
from django_registration.backends.activation.views import RegistrationView
from blango_auth.forms import BlangoRegistrationForm
from django.conf.urls.static import static


import logging

logger = logging.getLogger(__name__)

from django.urls import re_path


from drf_yasg import openapi
from drf_yasg.views import get_schema_view

schema_view = get_schema_view(
openapi.Info(
title="Blango API",
default_version="v1",
description="API for Blango Blog",
),
public=True,
)




urlpatterns = [
path('admin/', admin.site.urls),
path("", blog.views.index),
path("ip/", blog.views.get_ip),
path("accounts/", include("django.contrib.auth.urls")),
path("accounts/profile/", blango_auth.views.profile, name="profile"),
path('accounts/', include('django_registration.backends.activation.urls')),
path(
"accounts/register/",
RegistrationView.as_view(form_class=BlangoRegistrationForm),
name="django_registration_register",
),
path("accounts/", include("django_registration.backends.activation.urls")),
path("accounts/", include("allauth.urls")),
path("accounts/", include("allauth.urls")),
path("accounts/", include("allauth.urls")),
# for function based view below
# path("api/v1/", include("blog.api_urls")),
path("api/v1/", include("blog.api.urls")),
path("post-table/", blog.views.post_table, name="blog-post-table"),


# path("post/<slug>/", blog.views.post_detail, name="blog-post-detail")
]

# urlpatterns += [
# # ...
# re_path(
# r"^swagger(?P<format>\.json|\.yaml)$",
# schema_view.without_ui(cache_timeout=0),
# name="schema-json",
# ),
# # ...
# ]
urlpatterns += [
# ...
path(
r"^swagger/$",
schema_view.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui",
),
# ...
]



if settings.DEBUG:
urlpatterns += [
path("__debug__/", include(debug_toolbar.urls)),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
2 changes: 2 additions & 0 deletions blango/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blango.settings')
os.environ.setdefault("DJANGO_CONFIGURATION", "Prod")


application = get_wsgi_application()
Empty file added blango_auth/__init__.py
Empty file.
Binary file added blango_auth/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/admin.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/apps.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/tests.cpython-36.pyc
Binary file not shown.
Binary file added blango_auth/__pycache__/views.cpython-36.pyc
Binary file not shown.
41 changes: 41 additions & 0 deletions blango_auth/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from blango_auth.models import User
from django.utils.translation import gettext_lazy as _

# Register your models here.
#admin.site.register(User, UserAdmin)


class BlangoUserAdmin(UserAdmin):
fieldsets = (
(None, {"fields": ("email", "password")}),
(_("Personal info"), {"fields": ("first_name", "last_name")}),
(
_("Permissions"),
{
"fields": (
"is_active",
"is_staff",
"is_superuser",
"groups",
"user_permissions",
)
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": ("email", "password1", "password2"),
},
),
)
list_display = ("email", "first_name", "last_name", "is_staff")
search_fields = ("email", "first_name", "last_name")
ordering = ("email",)

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


class BlangoAuthConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'blango_auth'
Loading