Skip to content

Commit e56e53d

Browse files
committed
init commit
0 parents  commit e56e53d

18 files changed

+435
-0
lines changed

djangocrud/__init__.py

Whitespace-only changes.

djangocrud/settings.py

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
Django settings for djangocrud project.
3+
4+
Generated by 'django-admin startproject' using Django 2.2.2.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.2/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '=j-&9)(b@x7947yccbyqj&(1=%fnkvvjz1knz%wi7g#*9pz_lr'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'employee'
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'djangocrud.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [],
59+
'APP_DIRS': True,
60+
'OPTIONS': {
61+
'context_processors': [
62+
'django.template.context_processors.debug',
63+
'django.template.context_processors.request',
64+
'django.contrib.auth.context_processors.auth',
65+
'django.contrib.messages.context_processors.messages',
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = 'djangocrud.wsgi.application'
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
76+
77+
DATABASES = {
78+
'default': {
79+
'ENGINE': 'django.db.backends.mysql',
80+
'NAME': 'djangodb',
81+
'USER': 'root',
82+
'PASSWORD': '1234',
83+
'HOST': 'localhost',
84+
'PORT': '3306'
85+
}
86+
}
87+
88+
89+
# Password validation
90+
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
91+
92+
AUTH_PASSWORD_VALIDATORS = [
93+
{
94+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
95+
},
96+
{
97+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
98+
},
99+
{
100+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
101+
},
102+
{
103+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
104+
},
105+
]
106+
107+
108+
# Internationalization
109+
# https://docs.djangoproject.com/en/2.2/topics/i18n/
110+
111+
LANGUAGE_CODE = 'en-us'
112+
113+
TIME_ZONE = 'UTC'
114+
115+
USE_I18N = True
116+
117+
USE_L10N = True
118+
119+
USE_TZ = True
120+
121+
122+
# Static files (CSS, JavaScript, Images)
123+
# https://docs.djangoproject.com/en/2.2/howto/static-files/
124+
125+
STATIC_URL = '/static/'

djangocrud/urls.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""djangocrud URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.2/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: path('', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path
18+
from employee import views
19+
20+
urlpatterns = [
21+
path('admin/', admin.site.urls),
22+
path('emp', views.emp),
23+
path('show', views.show),
24+
path('edit/<int:id>', views.edit),
25+
path('update/<int:id>', views.update),
26+
path('delete/<int:id>', views.destroy),
27+
]

djangocrud/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for djangocrud 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/2.2/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', 'djangocrud.settings')
15+
16+
application = get_wsgi_application()

employee/__init__.py

Whitespace-only changes.

employee/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

employee/apps.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class EmployeeConfig(AppConfig):
5+
name = 'employee'

employee/forms.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django import forms
2+
from employee.models import Employee
3+
4+
5+
class EmployeeForm(forms.ModelForm):
6+
class Meta:
7+
model = Employee
8+
fields = "__all__"

employee/migrations/0001_initial.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 2.2.2 on 2019-06-19 05:27
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Employee',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('eid', models.CharField(max_length=20)),
19+
('ename', models.CharField(max_length=100)),
20+
('eemail', models.EmailField(max_length=254)),
21+
('econtact', models.CharField(max_length=20)),
22+
],
23+
options={
24+
'db_table': 'employee',
25+
},
26+
),
27+
]

employee/migrations/__init__.py

Whitespace-only changes.

employee/models.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.db import models
2+
3+
4+
class Employee(models.Model):
5+
eid = models.CharField(max_length=20)
6+
ename = models.CharField(max_length=100)
7+
eemail = models.EmailField()
8+
econtact = models.CharField(max_length=20)
9+
10+
class Meta:
11+
db_table = "employee"
12+

employee/static/css/style.css

Whitespace-only changes.

employee/templates/edit.html

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Index</title>
6+
{% load staticfiles %}
7+
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
8+
</head>
9+
<body>
10+
<form method="POST" class="post-form" action="/update/{{employee.id}}">
11+
{% csrf_token %}
12+
<div class="container">
13+
<br>
14+
<div class="form-group row">
15+
<label class="col-sm-1 col-form-label"></label>
16+
<div class="col-sm-4">
17+
<h3>Update Details</h3>
18+
</div>
19+
</div>
20+
<div class="form-group row">
21+
<label class="col-sm-2 col-form-label">Employee Id:</label>
22+
<div class="col-sm-4">
23+
<input type="text" name="eid" id="id_eid" required maxlength="20" value="{{ employee.eid }}"/>
24+
</div>
25+
</div>
26+
<div class="form-group row">
27+
<label class="col-sm-2 col-form-label">Employee Name:</label>
28+
<div class="col-sm-4">
29+
<input type="text" name="ename" id="id_ename" required maxlength="100" value="{{ employee.ename }}" />
30+
</div>
31+
</div>
32+
<div class="form-group row">
33+
<label class="col-sm-2 col-form-label">Employee Email:</label>
34+
<div class="col-sm-4">
35+
<input type="email" name="eemail" id="id_eemail" required maxlength="254" value="{{ employee.eemail }}" />
36+
</div>
37+
</div>
38+
<div class="form-group row">
39+
<label class="col-sm-2 col-form-label">Employee Contact:</label>
40+
<div class="col-sm-4">
41+
<input type="text" name="econtact" id="id_econtact" required maxlength="15" value="{{ employee.econtact }}" />
42+
</div>
43+
</div>
44+
<div class="form-group row">
45+
<label class="col-sm-1 col-form-label"></label>
46+
<div class="col-sm-4">
47+
<button type="submit" class="btn btn-success">Update</button>
48+
</div>
49+
</div>
50+
</div>
51+
</form>
52+
</body>
53+
</html>

employee/templates/index.html

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Index</title>
6+
{% load staticfiles %}
7+
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
8+
</head>
9+
<body>
10+
<form method="POST" class="post-form" action="/emp">
11+
{% csrf_token %}
12+
<div class="container">
13+
<br>
14+
<div class="form-group row">
15+
<label class="col-sm-1 col-form-label"></label>
16+
<div class="col-sm-4">
17+
<h3>Enter Details</h3>
18+
</div>
19+
</div>
20+
<div class="form-group row">
21+
<label class="col-sm-2 col-form-label">Employee Id:</label>
22+
<div class="col-sm-4">
23+
{{ form.eid }}
24+
</div>
25+
</div>
26+
<div class="form-group row">
27+
<label class="col-sm-2 col-form-label">Employee Name:</label>
28+
<div class="col-sm-4">
29+
{{ form.ename }}
30+
</div>
31+
</div>
32+
<div class="form-group row">
33+
<label class="col-sm-2 col-form-label">Employee Email:</label>
34+
<div class="col-sm-4">
35+
{{ form.eemail }}
36+
</div>
37+
</div>
38+
<div class="form-group row">
39+
<label class="col-sm-2 col-form-label">Employee Contact:</label>
40+
<div class="col-sm-4">
41+
{{ form.econtact }}
42+
</div>
43+
</div>
44+
<div class="form-group row">
45+
<label class="col-sm-1 col-form-label"></label>
46+
<div class="col-sm-4">
47+
<button type="submit" class="btn btn-primary">Submit</button>
48+
</div>
49+
</div>
50+
</div>
51+
</form>
52+
</body>
53+
</html>

employee/templates/show.html

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Employee Records</title>
6+
{% load staticfiles %}
7+
<link rel="stylesheet" href="{% static 'css/style.css' %}"/>
8+
</head>
9+
<body>
10+
<table class="table table-striped table-bordered table-sm">
11+
<thead class="thead-dark">
12+
<tr>
13+
<th>Employee ID</th>
14+
<th>Employee Name</th>
15+
<th>Employee Email</th>
16+
<th>Employee Contact</th>
17+
<th>Actions</th>
18+
</tr>
19+
</thead>
20+
<tbody>
21+
{% for employee in employees %}
22+
<tr>
23+
<td>{{ employee.eid }}</td>
24+
<td>{{ employee.ename }}</td>
25+
<td>{{ employee.eemail }}</td>
26+
<td>{{ employee.econtact }}</td>
27+
<td>
28+
<a href="/edit/{{ employee.id }}"><span class="glyphicon glyphicon-pencil" >Edit</span></a>
29+
<a href="/delete/{{ employee.id }}">Delete</a>
30+
</td>
31+
</tr>
32+
{% endfor %}
33+
</tbody>
34+
</table>
35+
<br>
36+
<br>
37+
<center><a href="/emp" class="btn btn-primary">Add New Record</a></center>
38+
</body>
39+
</html>

employee/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

0 commit comments

Comments
 (0)