Rename DCC project into RAM

RAM: Railroad Assets Manager
This commit is contained in:
2022-04-10 21:05:02 +02:00
parent 305507a4e6
commit d594dbe47c
77 changed files with 16 additions and 16 deletions

4
ram/ram/__init__.py Normal file
View File

@@ -0,0 +1,4 @@
from ram.utils import git_suffix
__version__ = '0.0.1'
__version__ += git_suffix(__file__)

16
ram/ram/asgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
ASGI config for ram 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.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ram.settings")
application = get_asgi_application()

8
ram/ram/parsers.py Normal file
View File

@@ -0,0 +1,8 @@
from rest_framework.parsers import BaseParser
class PlainTextParser(BaseParser):
media_type = "text/plain"
def parse(self, stream, media_type=None, parser_context=None):
return stream.read()

166
ram/ram/settings.py Normal file
View File

@@ -0,0 +1,166 @@
"""
Django settings for ram project.
Generated by 'django-admin startproject' using Django 4.0.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
STORAGE_DIR = BASE_DIR / "storage"
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = (
"django-insecure-1fgtf05rwp0qp05@ef@a7%x#o+t6vk6063py=vhdmut0j!8s4u"
)
# 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",
"health_check",
"health_check.db",
"django_countries",
"solo",
"rest_framework",
"adminsortable2",
"ram",
"portal",
"driver",
"metadata",
"roster",
"consist",
]
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 = "ram.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 = "ram.wsgi.application"
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": STORAGE_DIR / "db.sqlite3",
}
}
# Password validation
# https://docs.djangoproject.com/en/4.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/4.0/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.0/howto/static-files/
STATIC_URL = "static/"
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
MEDIA_URL = "media/"
MEDIA_ROOT = STORAGE_DIR / "media"
COUNTRIES_OVERRIDE = {
"ZZ": "Freelance",
}
DECODER_INTERFACES = [
(1, "NEM651"),
(2, "NEM652"),
(3, "PluX"),
(4, "21MTC"),
(5, "Next18/Next18S"),
]
MANUFACTURER_TYPES = [
("model", "Model"),
("real", "Real")
]
ROLLING_STOCK_TYPES = [
("engine", "Engine"),
("car", "Car"),
("railcar", "Railcar"),
("equipment", "Equipment"),
("other", "Other"),
]

51
ram/ram/urls.py Normal file
View File

@@ -0,0 +1,51 @@
"""ram URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.0/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.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from portal.utils import get_site_conf
from portal.views import GetHome
site_conf = get_site_conf()
admin.site.site_header = site_conf.site_name
urlpatterns = [
path("", GetHome.as_view(), name="index"),
path("page/", include("portal.urls")),
path("ht/", include("health_check.urls")),
path("admin/", admin.site.urls),
path("api/v1/consist/", include("consist.urls")),
path("api/v1/roster/", include("roster.urls")),
path("api/v1/dcc/", include("driver.urls")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# if settings.DEBUG:
# from django.views.generic import TemplateView
# from rest_framework.schemas import get_schema_view
#
# urlpatterns += [
# path('swagger/', TemplateView.as_view(
# template_name='swagger.html',
# extra_context={'schema_url': 'openapi-schema'}
# ), name='swagger'),
# path('openapi', get_schema_view(
# title="BITE - A Basic/IoT/Example",
# description="BITE API for IoT",
# version="1.0.0"
# ), name='openapi-schema'),
# ]

37
ram/ram/utils.py Normal file
View File

@@ -0,0 +1,37 @@
import os
import subprocess
from django.utils.html import format_html
from django.utils.text import slugify as django_slugify
def git_suffix(fname):
"""
:returns: `<short git hash>` if Git repository found
"""
try:
gh = subprocess.check_output(
['git', 'rev-parse', '--short', 'HEAD'],
stderr=open(os.devnull, 'w')).strip()
gh = "-git" + gh.decode() if gh else ''
except Exception:
# trapping everything on purpose; git may not be installed or it
# may not work properly
gh = ''
return gh
def get_image_preview(url):
return format_html(
'<img src="%s" style="max-width: 150px; max-height: 150px;'
'background-color: #eee;" />' % url
)
def slugify(string, custom_separator=None):
# Make slug 'flat', both '-' and '_' are replaced with '-'
string = django_slugify(string).replace("_", "-")
if custom_separator is not None:
string = string.replace("-", custom_separator)
return string

16
ram/ram/wsgi.py Normal file
View File

@@ -0,0 +1,16 @@
"""
WSGI config for ram 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.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ram.settings")
application = get_wsgi_application()