Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for EmpManagement 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', 'EmpManagement.settings')

application = get_asgi_application()
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = 'django-insecure-j*z@8-osfqlljsr1sr0)-v2si+ng$j%v=igu5vz6x5*3(8sl4k'

DEBUG = True

ALLOWED_HOSTS = ['*']

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'employees.apps.EmployeesConfig',
]

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 = 'EmpManagement.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 = 'EmpManagement.wsgi.application'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'employee_db',
'USER': 'postgres',
'PASSWORD': '123456',
'HOST': 'psql-db4',
'PORT': 5432,
}
}




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',
},
]


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

STATIC_URL = 'static/'

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('employees/', include('employees.urls')),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for EmpManagement 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', 'EmpManagement.settings')

application = get_wsgi_application()
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"
services:
web_service:
build:
context: ./
dockerfile: ./dockerfiles/Dockerfile
image: workshop1_web
container_name: workshop_web_container3
stdin_open: true
tty: true
ports:
- "8000:8000"
volumes:
- .:/root/workspace/site

psql-db:
image: 'postgres:14'
container_name: psql-db4
environment:
- PGPASSWORD=123456
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=123456
ports:
- '5446:5432'
volumes:
- db:/var/lib/postgresql/data
volumes:
db:
driver: local
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.10.2-alpine3.15

RUN apk update && \
apk --no-cache add --virtual build-deps-alpine build-base && \
apk --no-cache add --virtual postgresql-deps libpq-dev

RUN pip install --upgrade pip
RUN pip install Django psycopg2==2.9.3

RUN mkdir -p /root/workspace/src
COPY ./ /root/workspace/site

WORKDIR /root/workspace/site
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin
from .models import Employee

class DjEmployeeAdmin(admin.ModelAdmin):
list_display = ("first_name", "last_name", "emp_id", "address", "mobile", "dept","salary",)
list_filter = ("dept",)


admin.site.register(Employee, DjEmployeeAdmin)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig

class EmployeesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'employees'
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2 on 2023-05-05 13:44

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Employee',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(default=None, max_length=200)),
('last_name', models.CharField(default=None, max_length=200)),
('address', models.CharField(default=None, max_length=200)),
('emp_id', models.IntegerField(default=None)),
('mobile', models.CharField(default=None, max_length=10)),
('salary', models.IntegerField(default=None)),
('dept', models.CharField(choices=[('HR', 'HR'), ('Engineering', 'Engineering'), ('Marketing', 'Marketing'), ('Planning', 'Planning'), ('Sales', 'Sales'), ('Finance', 'Finance'), ('Operations', 'Operations')], default=None, max_length=100)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2 on 2023-05-06 04:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('employees', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='employee',
name='dept',
field=models.CharField(choices=[('HR', 'HR'), ('Engineering', 'Engineering'), ('Marketing', 'Marketing'), ('Planning', 'Planning'), ('Sales', 'Sales'), ('Finance', 'Finance'), ('Operations', 'Operations')], max_length=100),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2 on 2023-05-09 01:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('employees', '0002_alter_employee_dept'),
]

operations = [
migrations.AlterField(
model_name='employee',
name='address',
field=models.CharField(max_length=200),
),
migrations.AlterField(
model_name='employee',
name='emp_id',
field=models.IntegerField(),
),
migrations.AlterField(
model_name='employee',
name='first_name',
field=models.CharField(max_length=200),
),
migrations.AlterField(
model_name='employee',
name='last_name',
field=models.CharField(max_length=200),
),
migrations.AlterField(
model_name='employee',
name='mobile',
field=models.CharField(max_length=10),
),
migrations.AlterField(
model_name='employee',
name='salary',
field=models.IntegerField(),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2 on 2023-05-09 12:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('employees', '0003_alter_employee_address_alter_employee_emp_id_and_more'),
]

operations = [
migrations.RemoveField(
model_name='employee',
name='id',
),
migrations.AlterField(
model_name='employee',
name='emp_id',
field=models.BigAutoField(primary_key=True, serialize=False),
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.db import models

DEPARTMENT_CHOICES = (
("HR", "HR"),
("Engineering", "Engineering"),
("Marketing", "Marketing"),
("Planning", "Planning"),
("Sales","Sales"),
("Finance","Finance"),
("Operations","Operations"),
)




class Employee(models.Model):
first_name = models.CharField(max_length=200)
last_name = models.CharField(max_length=200)
address = models.CharField(max_length=200)
emp_id = models.BigAutoField(primary_key=True)
mobile = models.CharField(max_length=10)
dept =models.CharField(max_length=100, choices=DEPARTMENT_CHOICES)
salary = models.IntegerField()

def __str__(self):
return self.first_name + " " + self.last_name




Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sample</title>
</head>
<body>

<h1>Hello World!</h1>
<p>Welcome to my first Django project!</p>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from . import views

urlpatterns = [
path('employee/<int:emp_id>', views.EmployeeView.as_view()),
path('employee/', views.EmployeeView.as_view()),
path('employee/<str:dept>', views.EmployeeView.as_view()),
]
Loading