Skip to content

Commit b939a58

Browse files
first commit
1 parent f0cd24b commit b939a58

File tree

177 files changed

+5999
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+5999
-0
lines changed

ToDo.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
print("ToDo")
2+
3+
4+
5+
"""
6+
ToDo:
7+
** Code must be reusable
8+
1. Create Flutter base for front-end > REST > Connect Flutter with Django
9+
2. simple google alike interface for signup/login
10+
3. add JWT [and OTP]
11+
4. signup/login with google/facebook
12+
5. help section
13+
6.......
14+
-- GPS
15+
-- live weather
16+
--
17+
"""

wims/backend/django_inventory_backend/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for backend project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings.base")
15+
16+
application = get_asgi_application()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Organize Settings Module
2+
========================
3+
4+
First, transform the settings.py into a directory containing individual settings files for development, production, and testing. Here's the structure you'll create:
5+
6+
```bash
7+
8+
backend/
9+
backend/
10+
settings/
11+
__init__.py
12+
base.py # Common settings
13+
development.py # Development-specific settings
14+
production.py # Production-specific settings
15+
testing.py # Testing-specific settings
16+
```
17+
18+
- base.py: Contains settings common to all environments (e.g., INSTALLED_APPS, MIDDLEWARE).
19+
- development.py: Settings for the development environment (e.g., DEBUG = True, database configurations for development).
20+
- production.py: Production-specific settings (e.g., DEBUG = False, security settings, database configurations for production).
21+
- testing.py: Settings used for running tests (e.g., using an in-memory database like SQLite for faster test execution).
22+
23+
### Using the Settings
24+
25+
To use these settings, you'll specify the appropriate settings module when running Django commands. For example:
26+
27+
<br>
28+
29+
#### For development:
30+
31+
```bash
32+
33+
python manage.py runserver --settings=backend.settings.development
34+
```
35+
36+
<br>
37+
38+
#### For production:
39+
40+
```bash
41+
python manage.py collectstatic --settings=backend.settings.production
42+
python manage.py migrate --settings=backend.settings.production
43+
```
44+
45+
<br>
46+
47+
#### For testing:
48+
49+
```bash
50+
python manage.py test --settings=backend.settings.testing
51+
```
52+
53+
<br>
54+
55+
You can also set the DJANGO_SETTINGS_MODULE environment variable in your development, production, or CI/CD environment to point to the correct settings module, simplifying command usage.

wims/backend/django_inventory_backend/settings/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
"""
2+
Django settings for backend project.
3+
4+
Generated by 'django-admin startproject' using Django 5.0.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.0/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
from decouple import config
15+
16+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
17+
BASE_DIR = Path(__file__).resolve().parent.parent
18+
19+
20+
# Quick-start development settings - unsuitable for production
21+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
22+
23+
# SECURITY WARNING: keep the secret key used in production secret!
24+
SECRET_KEY = config('SECRET_KEY')
25+
26+
# SECURITY WARNING: don't run with debug turned on in production!
27+
DEBUG = False # By default, keep this off
28+
29+
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
30+
31+
32+
# Application definition
33+
34+
INSTALLED_APPS = [
35+
'inventory',
36+
'users',
37+
'rest_framework',
38+
'corsheaders',
39+
'drf_yasg',
40+
"django.contrib.admin",
41+
"django.contrib.auth",
42+
"django.contrib.contenttypes",
43+
"django.contrib.sessions",
44+
"django.contrib.messages",
45+
"django.contrib.staticfiles",
46+
]
47+
48+
MIDDLEWARE = [
49+
"corsheaders.middleware.CorsMiddleware",
50+
# "django.contrib.staticfiles",
51+
"django.middleware.security.SecurityMiddleware",
52+
"django.contrib.sessions.middleware.SessionMiddleware",
53+
"django.middleware.common.CommonMiddleware",
54+
"django.middleware.csrf.CsrfViewMiddleware",
55+
"django.contrib.auth.middleware.AuthenticationMiddleware",
56+
"django.contrib.messages.middleware.MessageMiddleware",
57+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
58+
]
59+
60+
ROOT_URLCONF = "backend.urls"
61+
62+
TEMPLATES = [
63+
{
64+
"BACKEND": "django.template.backends.django.DjangoTemplates",
65+
"DIRS": [BASE_DIR / "templates"],
66+
"APP_DIRS": True,
67+
"OPTIONS": {
68+
"context_processors": [
69+
"django.template.context_processors.debug",
70+
"django.template.context_processors.request",
71+
"django.contrib.auth.context_processors.auth",
72+
"django.contrib.messages.context_processors.messages",
73+
],
74+
},
75+
},
76+
]
77+
78+
WSGI_APPLICATION = "backend.wsgi.application"
79+
80+
81+
# Allow all origins for simplicity during development
82+
CORS_ALLOW_ALL_ORIGINS = True
83+
84+
85+
REST_FRAMEWORK = {
86+
'DEFAULT_AUTHENTICATION_CLASSES': (
87+
'rest_framework_simplejwt.authentication.JWTAuthentication',
88+
),
89+
}
90+
91+
92+
93+
TWILIO_ACCOUNT_SID = config('TWILIO_ACCOUNT_SID')
94+
TWILIO_AUTH_TOKEN = config('TWILIO_AUTH_TOKEN')
95+
TWILIO_WHATSAPP_NUMBER = 'whatsapp:+8801673850025' # Replace with your number in production
96+
97+
98+
99+
# Database
100+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
101+
102+
DATABASES = {
103+
"default": {
104+
"ENGINE": "django.db.backends.sqlite3",
105+
"NAME": BASE_DIR / "db.sqlite3",
106+
}
107+
}
108+
109+
110+
# Password validation
111+
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
112+
113+
AUTH_PASSWORD_VALIDATORS = [
114+
{
115+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
116+
},
117+
{
118+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
119+
},
120+
{
121+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
122+
},
123+
{
124+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
125+
},
126+
]
127+
128+
129+
# Internationalization
130+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
131+
132+
LANGUAGE_CODE = "en-us"
133+
134+
TIME_ZONE = "Asia/Dhaka"
135+
136+
USE_I18N = True
137+
138+
USE_TZ = True
139+
140+
141+
# Static files (CSS, JavaScript, Images)
142+
# https://docs.djangoproject.com/en/5.0/howto/static-files/
143+
144+
STATIC_URL = "/static/"
145+
STATIC_ROOT = BASE_DIR / 'staticfiles'
146+
147+
148+
# Default primary key field type
149+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
150+
151+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
152+
153+
154+
"""
155+
STATIC_URL = '/static/'
156+
STATICFILES_DIRS = [
157+
BASE_DIR / "static_global",
158+
BASE_DIR / "app1" / "static_app1",
159+
BASE_DIR / "app2" / "static_app2",
160+
]
161+
162+
MEDIA_URL = '/media/'
163+
MEDIA_ROOT = BASE_DIR / 'media'
164+
165+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .base import *
2+
3+
DEBUG = True
4+
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from .base import *
2+
import dj_database_url
3+
4+
DEBUG = False
5+
DATABASES['default'] = dj_database_url.config(default=config('DATABASE_URL'))
6+
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='', cast=lambda v: [s.strip() for s in v.split(',')])
7+
8+
9+
# Modify your secret key for added security:
10+
# SECRET_KEY = 'YOUR_PRODUCTION_SECRET_KEY'
11+
12+
13+
"""
14+
from .base import *
15+
16+
DEBUG = False
17+
ALLOWED_HOSTS = ['yourproductiondomain.com']
18+
19+
DATABASES = {
20+
'default': {
21+
'ENGINE': 'django.db.backends.postgresql',
22+
'NAME': 'prod_db',
23+
'USER': 'prod_user',
24+
'PASSWORD': 'prod_password',
25+
'HOST': 'localhost',
26+
'PORT': '5432',
27+
}
28+
}
29+
30+
# Security settings
31+
SECURE_SSL_REDIRECT = True
32+
SESSION_COOKIE_SECURE = True
33+
CSRF_COOKIE_SECURE = True
34+
35+
# Plus any other production-specific settings
36+
37+
"""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .base import *
2+
3+
DEBUG = True
4+
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
URL configuration for backend project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.0/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
# backend/urls.py
18+
19+
from django.contrib import admin
20+
from django.urls import path, re_path, include
21+
# Adjusted import statement here
22+
from inventory.views import schema_view
23+
from rest_framework_simplejwt.views import (
24+
TokenObtainPairView,
25+
TokenRefreshView,
26+
TokenVerifyView,
27+
)
28+
29+
urlpatterns = [
30+
path("admin/", admin.site.urls),
31+
path('', include("inventory.urls")),
32+
path('', include("users.urls")),
33+
path('api/', include('inventory.api.urls')), # Assuming you have a separate urls.py for API endpoints
34+
# Swagger and Redoc paths as defined
35+
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
36+
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
37+
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
38+
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
39+
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
40+
path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
41+
]
42+
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for backend project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings.base")
15+
16+
application = get_wsgi_application()

wims/backend/inventory/__init__.py

Whitespace-only changes.

wims/backend/inventory/admin.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from django.contrib import admin
2+
from .models import Item
3+
4+
admin.site.register(Item)

wims/backend/inventory/api/__init__.py

Whitespace-only changes.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# inventory/api/serializers.py
2+
3+
from rest_framework import serializers
4+
from inventory.models import Item
5+
6+
7+
class ItemSerializer(serializers.ModelSerializer):
8+
class Meta:
9+
model = Item
10+
fields = '__all__'

0 commit comments

Comments
 (0)