Skip to content

Commit

Permalink
wip: crud command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Dec 17, 2023
1 parent 92061cd commit e78f730
Show file tree
Hide file tree
Showing 57 changed files with 469 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ repos:
# args:
# - "."
# - "--line-length=120"
# - "--exclude=src/falco_templates/project_name/*"
# - "--exclude=src/falco_blueprints/project_name/*"
File renamed without changes.
15 changes: 15 additions & 0 deletions demo/demo/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
ASGI config for demo 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/4.2/howto/deployment/asgi/
"""
import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")

application = get_asgi_application()
123 changes: 123 additions & 0 deletions demo/demo/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Django settings for demo project.
Generated by 'django-admin startproject' using Django 4.2.8.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
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/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-4dg_sw7m&pb*k)^35n727yvl*br0s)x)@uafo0nqfs7ht90jyt"

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

ALLOWED_HOSTS = []


# Application definition

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

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 = "demo.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",
],
},
},
]

WSGI_APPLICATION = "demo.wsgi.application"


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

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


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

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


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

STATIC_URL = "static/"

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

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
22 changes: 22 additions & 0 deletions demo/demo/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
URL configuration for demo project.
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path("admin/", admin.site.urls),
]
15 changes: 15 additions & 0 deletions demo/demo/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
WSGI config for demo 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/4.2/howto/deployment/wsgi/
"""
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")

application = get_wsgi_application()
22 changes: 22 additions & 0 deletions demo/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", "demo.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()
File renamed without changes.
1 change: 1 addition & 0 deletions demo/products/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Register your models here.
6 changes: 6 additions & 0 deletions demo/products/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ProductsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "products"
File renamed without changes.
10 changes: 10 additions & 0 deletions demo/products/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models


class Product(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
price = models.DecimalField(max_digits=10, decimal_places=2)
image = models.ImageField(upload_to="products/", null=True, blank=True)
slug = models.SlugField(max_length=100, unique=True)
sku = models.CharField(max_length=100, unique=True)
1 change: 1 addition & 0 deletions demo/products/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Create your tests here.
6 changes: 6 additions & 0 deletions docs/guides/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,24 @@ Deployment is not a solved solution for me, it is still a pain, no matter how ma
a managed solution (the cloud), if you any reason you decide to go the self-hosting route, I'll recommand you use a P.A.A.S (Platform as a Service) solution
to ease your burden or a least docker as a bare minimum. Deployment is not worth your blood and energy my friend.

Paas and rent a VPS


Someone else computer a.k.a the cloud
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I don't have much experience with these, but are relatively similarly price and quite easy to use, so you can just use one.


P.A.A.S
*******

* `Fly <https://fly.io/>`_
* `Render <https://render.com/>`_
* `AWS Elastic Beanstalk <https://aws.amazon.com/elasticbeanstalk/>`_
* `Heroku <https://www.heroku.com/>`_
* `Railway <https://railway.app/>`_
* `Appliku <https://appliku.com>`_


Self hosting
Expand Down
21 changes: 13 additions & 8 deletions docs/guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ or have a better approach to solve a specific issue, I'll be happy to hear it.
.. note::
I want to use GitHub discussions mostly for the guides part, and issues (broken code) for the CLI part.

A lot of the content here is geared toward beginners to intermediate developers, but more toward the latter. It is assumed that you have at
least completed one or two django projects (like the `official Django tutorial <https://docs.djangoproject.com/en/5.0/intro/tutorial01/>`_). I believe you need to
have that level of familiarity to feel comfortable reading these guides. However, I will try to make them as digestible as possible and provide enough external resources
for deeper understanding.

Most of the stuff here is aimed at folks who are somewhere between beginners and intermediate developers, leaning more towards the intermediate side. It's kinda assumed that you've done a couple of Django projects
(like the official `Django tutorial <https://docs.djangoproject.com/en/5.0/intro/tutorial01/>`_). I reckon you need to be pretty familiar with the framework to feel comfortable reading these guides. But hey,
I'll do my best to make them as easy to digest as possible and provide enough external resources for a deeper understanding.

External Ressources
-------------------
Expand All @@ -38,12 +36,14 @@ developer in general.
.. grid-item-card:: The official Django documentation
:link: https://docs.djangoproject.com/en/dev/

Always have a tab open to the official Django documentation. It is the best source for django.
Django's documentation is arguably one of the best I have encountered. The **Topics guides** and **How-to guides** are particularly
noteworthy and should not be overlooked.

.. grid-item-card:: The HTMX documentation
:link: https://htmx.org/

The htmx documentation have everything you need to understand htmx but they also have great essays that are worth reading to broader your understanding of web development.
The htmx documentation have everything you need to understand htmx but they also have great essays that are worth reading
to broader your understanding of web development.


**Programming principles**
Expand Down Expand Up @@ -71,7 +71,7 @@ developer in general.
The twelve-factor app is a methodology for building software-as-a-service applications. These best practices are designed to enable applications to be built with portability and resilience when deployed to the web.


**Good old content: blog articles and videos**
**Blog articles and videos**

.. grid:: 2

Expand Down Expand Up @@ -102,6 +102,11 @@ developer in general.



.. admonition:: Need Help with Django?
:class: hint dropdown

For general assistance with Django-related issues, visit the `Django Community <https://www.djangoproject.com/community/>`_ page.


.. toctree::
:hidden:
Expand Down
18 changes: 18 additions & 0 deletions docs/guides/logging_and_monitoring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@

Logging and monitoring
======================


Health check your django project
--------------------------------

**Health check** is about making sure that your django application and related services are always available / running.
My go-to package for this is `django-health-check <https://github.com/revsys/django-health-check>`__.
After installing and configuring **django-health-check**, you need to associate it with an uptime monitoring service, this
is the service that will periodically call your **health-check** endpoint to make sure everything is fine.
Here is a list of available options.

- `upptime <https://github.com/upptime/upptime>`__
- `uptime-kuma <https://github.com/louislam/uptime-kuma>`__
- `uptimerobot <https://uptimerobot.com/>`__
- `better-uptime <https://betterstack.com/better-uptime>`__
- `glitchtip <https://glitchtip.com/>`__

Read more on the health check pattern `here <https://learn.microsoft.com/en-us/azure/architecture/patterns/health-endpoint-monitoring>`__.
9 changes: 9 additions & 0 deletions docs/guides/writing_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ Documentation Frameworks
------------------------


Markdown and reStructuredText
-----------------------------

https://github.github.com/gfm/

https://myst-parser.readthedocs.io/en/latest/

https://sphinx-intro-tutorial.readthedocs.io/en/latest/

Python documentation tools
--------------------------

Expand Down
22 changes: 3 additions & 19 deletions docs/tips_and_extra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,9 @@ If there is a setting in ``settings.py`` or elsewhere that you don’t understan
and press Ctrl + F to search for it. I used the `django-production <https://github.com/lincolnloop/django-production>`__ package to configure the production settings which I then customized.
I have removed the package as a dependency, but I advise you to go and check for yourself what is available.

Health check your django project
--------------------------------

**Health check** is about making sure that your django application and related services are always available / running.
My go-to package for this is `django-health-check <https://github.com/revsys/django-health-check>`__.
After installing and configuring **django-health-check**, you need to associate it with an uptime monitoring service, this
is the service that will periodically call your **health-check** endpoint to make sure everything is fine.
Here is a list of available options.

- `upptime <https://github.com/upptime/upptime>`__
- `uptime-kuma <https://github.com/louislam/uptime-kuma>`__
- `uptimerobot <https://uptimerobot.com/>`__
- `better-uptime <https://betterstack.com/better-uptime>`__
- `glitchtip <https://glitchtip.com/>`__

Read more on the health check pattern `here <https://learn.microsoft.com/en-us/azure/architecture/patterns/health-endpoint-monitoring>`__.

Monitoring your django project
------------------------------
Local email testing
--------------------
https://github.com/axllent/mailpit

Lifecycle not signals
---------------------
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dependencies = [
"honcho",
"tomli",
"python-dotenv",
"autoflake",
"black",
]

[project.scripts]
Expand All @@ -50,7 +52,7 @@ Source = "https://github.com/tobi-de/falco"
path = "src/falco/__about__.py"

[tool.hatch.build.targets.wheel]
packages = ["src/falco", "src/falco_templates"]
packages = ["src/falco", "src/falco_blueprints"]

[tool.hatch.envs.default]
dependencies = [
Expand Down
Loading

0 comments on commit e78f730

Please sign in to comment.