diff --git a/examples/django/.gitignore b/examples/django/.gitignore new file mode 100644 index 0000000..5675dfe --- /dev/null +++ b/examples/django/.gitignore @@ -0,0 +1,2 @@ +*.py +*.DotSettings.user diff --git a/examples/django/Django.fsproj b/examples/django/Django.fsproj new file mode 100644 index 0000000..179dca5 --- /dev/null +++ b/examples/django/Django.fsproj @@ -0,0 +1,19 @@ + + + + Exe + net5.0 + 3390;$(WarnOn) + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/django/Manage.fs b/examples/django/Manage.fs new file mode 100644 index 0000000..4d3634a --- /dev/null +++ b/examples/django/Manage.fs @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +module Django.Manage + +//Django command-line utility for administrative tasks. + +open Fable.Core +open Fable.Core.PyInterop + +type IEnviron = + [] + abstract setdefault : string * string -> unit + +[] +let environ: IEnviron = nativeOnly + +[] +let sys : obj = nativeOnly + +[] +let execute_from_command_line: string [] -> int = nativeOnly + +[] +let main argv = + environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings") + execute_from_command_line sys?argv diff --git a/examples/django/README.md b/examples/django/README.md new file mode 100644 index 0000000..0b3d7aa --- /dev/null +++ b/examples/django/README.md @@ -0,0 +1,31 @@ +# Fable Python on Django + +## Info + +The project is a copy of Django's `python manage.py startproject tproj` output. +The compiled version should be almost identical to the above command. + + +## Install Dependencies + +```sh +> dotnet tool restore +> dotnet restore + +> pip3 install -r Django +``` + +## Build + +``` +> dotnet fable-py +``` + +## Run + +```sh +> python3 manage.py runserver +``` + +Visit http://127.0.0.1:8000/ + diff --git a/examples/django/requirements.txt b/examples/django/requirements.txt new file mode 100644 index 0000000..699ce5c --- /dev/null +++ b/examples/django/requirements.txt @@ -0,0 +1 @@ +Django>=3.2.8,<4.0.0 \ No newline at end of file diff --git a/examples/django/tproj/Asgi.fs b/examples/django/tproj/Asgi.fs new file mode 100644 index 0000000..f0f4788 --- /dev/null +++ b/examples/django/tproj/Asgi.fs @@ -0,0 +1,26 @@ +module Django.tproj.Asgi + +open Fable.Core +//ASGI config for testproj 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/ + +type IEnviron = + [] + abstract setdefault : string * string -> unit + +[] +let environ: IEnviron = nativeOnly + +type IASGI = + [] + abstract get_asgi_application: unit -> unit + +[] +let asgi: IASGI= nativeOnly + +environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings") +let application = asgi.get_asgi_application() \ No newline at end of file diff --git a/examples/django/tproj/Settings.fs b/examples/django/tproj/Settings.fs new file mode 100644 index 0000000..bc59327 --- /dev/null +++ b/examples/django/tproj/Settings.fs @@ -0,0 +1,131 @@ +module Django.tproj.Settings + +open Fable.Core +open Fable.Core.PyInterop +open Fable.Python + +//Django settings for tproj project. +// +//Generated by "django-admin startproject " using Django 3.2.8. +// +//For more information on this file, see +//https://docs.djangoproject.com/en/3.2/topics/settings/ +// +//For the full list of settings and their values, see +//https://docs.djangoproject.com/en/3.2/ref/settings/ + + +[] +let __file__: string = nativeOnly + +[] +let Path: string -> obj = nativeOnly + +// Build paths inside the project like this: BASE_DIR / "subdir ". +let BASE_DIR:string = string (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! +let SECRET_KEY = "django-insecure-8@-!^t#jw8svblg!%z5meh+#48nvd)me-*^im))uvy6pfweb" +// +// SECURITY WARNING: don "t run with debug turned on in production! +let DEBUG = true + +let ALLOWED_HOSTS: string[] = [||] + + +// Application definition +// +let INSTALLED_APPS = [| + "django.contrib.admin" + "django.contrib.auth" + "django.contrib.contenttypes" + "django.contrib.sessions" + "django.contrib.messages" + "django.contrib.staticfiles" +|] + +let 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" +|] + +let ROOT_URLCONF = "tproj.urls" + +let TEMPLATES: {| APP_DIRS: bool; BACKEND: string; DIRS: string []; OPTIONS: {| context_processors: string [] |} |} [] = + [| + {| 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" + |] + |} + + |} + |] + +let WSGI_APPLICATION = "tproj.wsgi.application" + +// Database +// https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +let 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 + +let 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/ + +let LANGUAGE_CODE = "en-us" + +let TIME_ZONE = "UTC" + +let USE_I18N = true + +let USE_L10N = true + +let USE_TZ = true + +// Static files (CSS, JavaScript, Images) +// https://docs.djangoproject.com/en/3.2/howto/static-files/ + +let STATIC_URL = "/static/" + +// Default primary key field type +// https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +let DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" diff --git a/examples/django/tproj/Urls.fs b/examples/django/tproj/Urls.fs new file mode 100644 index 0000000..1852637 --- /dev/null +++ b/examples/django/tproj/Urls.fs @@ -0,0 +1,31 @@ +module Django.tproj.Urls + +open Fable.Core +open Fable.Core.PyInterop + +//tproj URL Configuration +// +//The `urlpatterns` list routes URLs to views. For more information please see: +// https://docs.djangoproject.com/en/3.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')) + +[] +let admin: obj = nativeOnly + +type IPath = + abstract path : url: string * view: obj -> obj + +[] +let urls: IPath = nativeOnly +let urlpatterns = [| + urls.path("admin/", admin?site?urls) +|] \ No newline at end of file diff --git a/examples/django/tproj/Wsgi.fs b/examples/django/tproj/Wsgi.fs new file mode 100644 index 0000000..c2e777c --- /dev/null +++ b/examples/django/tproj/Wsgi.fs @@ -0,0 +1,28 @@ +module Django.tproj.Wsgi + +open Fable.Core +//WSGI config for testproj 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/ + + + +type IEnviron = + [] + abstract setdefault : string * string -> unit + +[] +let environ: IEnviron = nativeOnly + +type IWSGI = + [] + abstract get_wsgi_application: unit -> unit + +[] +let wsgi: IWSGI= nativeOnly + +environ.setdefault("DJANGO_SETTINGS_MODULE", "tproj.settings") +let application = wsgi.get_wsgi_application()