diff --git a/homework2/EmpManagement/EmpManagement/__init__.py b/homework2/EmpManagement/EmpManagement/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/homework2/EmpManagement/EmpManagement/__pycache__/__init__.cpython-310.pyc b/homework2/EmpManagement/EmpManagement/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000..9962d666 Binary files /dev/null and b/homework2/EmpManagement/EmpManagement/__pycache__/__init__.cpython-310.pyc differ diff --git a/homework2/EmpManagement/EmpManagement/__pycache__/settings.cpython-310.pyc b/homework2/EmpManagement/EmpManagement/__pycache__/settings.cpython-310.pyc new file mode 100644 index 00000000..a98ce566 Binary files /dev/null and b/homework2/EmpManagement/EmpManagement/__pycache__/settings.cpython-310.pyc differ diff --git a/homework2/EmpManagement/EmpManagement/__pycache__/urls.cpython-310.pyc b/homework2/EmpManagement/EmpManagement/__pycache__/urls.cpython-310.pyc new file mode 100644 index 00000000..c0a79f4d Binary files /dev/null and b/homework2/EmpManagement/EmpManagement/__pycache__/urls.cpython-310.pyc differ diff --git a/homework2/EmpManagement/EmpManagement/__pycache__/wsgi.cpython-310.pyc b/homework2/EmpManagement/EmpManagement/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 00000000..7d199608 Binary files /dev/null and b/homework2/EmpManagement/EmpManagement/__pycache__/wsgi.cpython-310.pyc differ diff --git a/homework2/EmpManagement/EmpManagement/asgi.py b/homework2/EmpManagement/EmpManagement/asgi.py new file mode 100644 index 00000000..e4d9ee14 --- /dev/null +++ b/homework2/EmpManagement/EmpManagement/asgi.py @@ -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() diff --git a/homework2/EmpManagement/EmpManagement/settings.py b/homework2/EmpManagement/EmpManagement/settings.py new file mode 100644 index 00000000..b4582934 --- /dev/null +++ b/homework2/EmpManagement/EmpManagement/settings.py @@ -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' diff --git a/homework2/EmpManagement/EmpManagement/urls.py b/homework2/EmpManagement/EmpManagement/urls.py new file mode 100644 index 00000000..b4a63e9d --- /dev/null +++ b/homework2/EmpManagement/EmpManagement/urls.py @@ -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')), +] diff --git a/homework2/EmpManagement/EmpManagement/wsgi.py b/homework2/EmpManagement/EmpManagement/wsgi.py new file mode 100644 index 00000000..05f44b3a --- /dev/null +++ b/homework2/EmpManagement/EmpManagement/wsgi.py @@ -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() diff --git a/homework2/EmpManagement/__pycache__/unittest_api.cpython-310.pyc b/homework2/EmpManagement/__pycache__/unittest_api.cpython-310.pyc new file mode 100644 index 00000000..d2bcab8c Binary files /dev/null and b/homework2/EmpManagement/__pycache__/unittest_api.cpython-310.pyc differ diff --git a/homework2/EmpManagement/docker-compose.yml b/homework2/EmpManagement/docker-compose.yml new file mode 100644 index 00000000..67c61704 --- /dev/null +++ b/homework2/EmpManagement/docker-compose.yml @@ -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 diff --git a/homework2/EmpManagement/dockerfiles/Dockerfile b/homework2/EmpManagement/dockerfiles/Dockerfile new file mode 100644 index 00000000..d34dc3af --- /dev/null +++ b/homework2/EmpManagement/dockerfiles/Dockerfile @@ -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 diff --git a/homework2/EmpManagement/employees/__init__.py b/homework2/EmpManagement/employees/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/homework2/EmpManagement/employees/__pycache__/__init__.cpython-310.pyc b/homework2/EmpManagement/employees/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000..60f99c10 Binary files /dev/null and b/homework2/EmpManagement/employees/__pycache__/__init__.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/__pycache__/admin.cpython-310.pyc b/homework2/EmpManagement/employees/__pycache__/admin.cpython-310.pyc new file mode 100644 index 00000000..998d151a Binary files /dev/null and b/homework2/EmpManagement/employees/__pycache__/admin.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/__pycache__/apps.cpython-310.pyc b/homework2/EmpManagement/employees/__pycache__/apps.cpython-310.pyc new file mode 100644 index 00000000..d1dafac5 Binary files /dev/null and b/homework2/EmpManagement/employees/__pycache__/apps.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/__pycache__/models.cpython-310.pyc b/homework2/EmpManagement/employees/__pycache__/models.cpython-310.pyc new file mode 100644 index 00000000..a01c4f7d Binary files /dev/null and b/homework2/EmpManagement/employees/__pycache__/models.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/__pycache__/urls.cpython-310.pyc b/homework2/EmpManagement/employees/__pycache__/urls.cpython-310.pyc new file mode 100644 index 00000000..95b73b35 Binary files /dev/null and b/homework2/EmpManagement/employees/__pycache__/urls.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/__pycache__/views.cpython-310.pyc b/homework2/EmpManagement/employees/__pycache__/views.cpython-310.pyc new file mode 100644 index 00000000..2cd95a36 Binary files /dev/null and b/homework2/EmpManagement/employees/__pycache__/views.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/admin.py b/homework2/EmpManagement/employees/admin.py new file mode 100644 index 00000000..a9706f5e --- /dev/null +++ b/homework2/EmpManagement/employees/admin.py @@ -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) diff --git a/homework2/EmpManagement/employees/apps.py b/homework2/EmpManagement/employees/apps.py new file mode 100644 index 00000000..e1187f4f --- /dev/null +++ b/homework2/EmpManagement/employees/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + +class EmployeesConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'employees' diff --git a/homework2/EmpManagement/employees/migrations/0001_initial.py b/homework2/EmpManagement/employees/migrations/0001_initial.py new file mode 100644 index 00000000..69d2392f --- /dev/null +++ b/homework2/EmpManagement/employees/migrations/0001_initial.py @@ -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)), + ], + ), + ] diff --git a/homework2/EmpManagement/employees/migrations/0002_alter_employee_dept.py b/homework2/EmpManagement/employees/migrations/0002_alter_employee_dept.py new file mode 100644 index 00000000..f4ce64cd --- /dev/null +++ b/homework2/EmpManagement/employees/migrations/0002_alter_employee_dept.py @@ -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), + ), + ] diff --git a/homework2/EmpManagement/employees/migrations/0003_alter_employee_address_alter_employee_emp_id_and_more.py b/homework2/EmpManagement/employees/migrations/0003_alter_employee_address_alter_employee_emp_id_and_more.py new file mode 100644 index 00000000..c408efb8 --- /dev/null +++ b/homework2/EmpManagement/employees/migrations/0003_alter_employee_address_alter_employee_emp_id_and_more.py @@ -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(), + ), + ] diff --git a/homework2/EmpManagement/employees/migrations/0004_remove_employee_id_alter_employee_emp_id.py b/homework2/EmpManagement/employees/migrations/0004_remove_employee_id_alter_employee_emp_id.py new file mode 100644 index 00000000..f5110e25 --- /dev/null +++ b/homework2/EmpManagement/employees/migrations/0004_remove_employee_id_alter_employee_emp_id.py @@ -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), + ), + ] diff --git a/homework2/EmpManagement/employees/migrations/__init__.py b/homework2/EmpManagement/employees/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/homework2/EmpManagement/employees/migrations/__pycache__/0001_initial.cpython-310.pyc b/homework2/EmpManagement/employees/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 00000000..34655743 Binary files /dev/null and b/homework2/EmpManagement/employees/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/migrations/__pycache__/0002_alter_employee_dept.cpython-310.pyc b/homework2/EmpManagement/employees/migrations/__pycache__/0002_alter_employee_dept.cpython-310.pyc new file mode 100644 index 00000000..08e1cda9 Binary files /dev/null and b/homework2/EmpManagement/employees/migrations/__pycache__/0002_alter_employee_dept.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/migrations/__pycache__/0002_remove_employee_role.cpython-310.pyc b/homework2/EmpManagement/employees/migrations/__pycache__/0002_remove_employee_role.cpython-310.pyc new file mode 100644 index 00000000..5dfeeb20 Binary files /dev/null and b/homework2/EmpManagement/employees/migrations/__pycache__/0002_remove_employee_role.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/migrations/__pycache__/0003_alter_employee_address_alter_employee_emp_id_and_more.cpython-310.pyc b/homework2/EmpManagement/employees/migrations/__pycache__/0003_alter_employee_address_alter_employee_emp_id_and_more.cpython-310.pyc new file mode 100644 index 00000000..eb3cd332 Binary files /dev/null and b/homework2/EmpManagement/employees/migrations/__pycache__/0003_alter_employee_address_alter_employee_emp_id_and_more.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/migrations/__pycache__/0003_delete_role_alter_employee_address_and_more.cpython-310.pyc b/homework2/EmpManagement/employees/migrations/__pycache__/0003_delete_role_alter_employee_address_and_more.cpython-310.pyc new file mode 100644 index 00000000..0d6e570e Binary files /dev/null and b/homework2/EmpManagement/employees/migrations/__pycache__/0003_delete_role_alter_employee_address_and_more.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/migrations/__pycache__/0004_remove_employee_id_alter_employee_emp_id.cpython-310.pyc b/homework2/EmpManagement/employees/migrations/__pycache__/0004_remove_employee_id_alter_employee_emp_id.cpython-310.pyc new file mode 100644 index 00000000..27ea9ed9 Binary files /dev/null and b/homework2/EmpManagement/employees/migrations/__pycache__/0004_remove_employee_id_alter_employee_emp_id.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/migrations/__pycache__/__init__.cpython-310.pyc b/homework2/EmpManagement/employees/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000..70c9fb90 Binary files /dev/null and b/homework2/EmpManagement/employees/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/homework2/EmpManagement/employees/models.py b/homework2/EmpManagement/employees/models.py new file mode 100644 index 00000000..bc73fd88 --- /dev/null +++ b/homework2/EmpManagement/employees/models.py @@ -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 + + + + diff --git a/homework2/EmpManagement/employees/templates/index.html b/homework2/EmpManagement/employees/templates/index.html new file mode 100644 index 00000000..de26a070 --- /dev/null +++ b/homework2/EmpManagement/employees/templates/index.html @@ -0,0 +1,13 @@ + + +
+ +Welcome to my first Django project!
+ + + diff --git a/homework2/EmpManagement/employees/tests.py b/homework2/EmpManagement/employees/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/homework2/EmpManagement/employees/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/homework2/EmpManagement/employees/urls.py b/homework2/EmpManagement/employees/urls.py new file mode 100644 index 00000000..41c6a7c2 --- /dev/null +++ b/homework2/EmpManagement/employees/urls.py @@ -0,0 +1,8 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('employee/