diff --git a/Day31-Day35/car/car/__init__.py b/Day31-Day35/car/car/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..aa60bed871c7d5c87f5a243972afeacad22709d2 --- /dev/null +++ b/Day31-Day35/car/car/__init__.py @@ -0,0 +1,3 @@ +import pymysql + +pymysql.install_as_MySQLdb() \ No newline at end of file diff --git a/Day31-Day35/car/car/settings.py b/Day31-Day35/car/car/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..71837f81b53a5ec326c1ee52f7ac04b9ff1fed7d --- /dev/null +++ b/Day31-Day35/car/car/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for car project. + +Generated by 'django-admin startproject' using Django 2.0.5. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'ol6dmf6im(w!l*z4w+_whm&)8@(c7%4&tlhd%uh6$lfx=pi*5e' + +# 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', + 'search', +] + +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 = 'car.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'templates')] + , + '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 = 'car.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'car', + 'HOST': 'localhost', + 'PORT': 3306, + 'USER': 'root', + 'PASSWORD': '123456', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.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/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ +STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')] + +STATIC_URL = '/static/' diff --git a/Day31-Day35/car/car/urls.py b/Day31-Day35/car/car/urls.py new file mode 100644 index 0000000000000000000000000000000000000000..11e97ebabeabfe64cdea5d74353c0a94b7a0e16f --- /dev/null +++ b/Day31-Day35/car/car/urls.py @@ -0,0 +1,26 @@ +"""car URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.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.contrib import admin +from django.conf.urls import url + +from search import views + +urlpatterns = [ + url(r'^search$', views.search), + url(r'^search2$', views.ajax_search), + url(r'^add', views.add), + url(r'^admin/', admin.site.urls), +] diff --git a/Day31-Day35/car/car/wsgi.py b/Day31-Day35/car/car/wsgi.py new file mode 100644 index 0000000000000000000000000000000000000000..150b999f0cf70f5506bcffc198168b3d3176ff64 --- /dev/null +++ b/Day31-Day35/car/car/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for car 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/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car.settings") + +application = get_wsgi_application() diff --git a/Day31-Day35/car/manage.py b/Day31-Day35/car/manage.py new file mode 100644 index 0000000000000000000000000000000000000000..5478c46944009af40bf01c2dca44f6ae4926cfe0 --- /dev/null +++ b/Day31-Day35/car/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/Day31-Day35/car/search/__init__.py b/Day31-Day35/car/search/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Day31-Day35/car/search/admin.py b/Day31-Day35/car/search/admin.py new file mode 100644 index 0000000000000000000000000000000000000000..1c98cb7e3643b0f0b608b0aedfc801406bf9846d --- /dev/null +++ b/Day31-Day35/car/search/admin.py @@ -0,0 +1,12 @@ +from django.contrib import admin + +from search.models import CarRecord + + +class CarRecordAdmin(admin.ModelAdmin): + + list_display = ('carno', 'reason', 'date', 'punish', 'isdone') + search_fields = ('carno', ) + + +admin.site.register(CarRecord, CarRecordAdmin) diff --git a/Day31-Day35/car/search/apps.py b/Day31-Day35/car/search/apps.py new file mode 100644 index 0000000000000000000000000000000000000000..5726231f79784f2514cc9a84bc4bfc557a7c21fc --- /dev/null +++ b/Day31-Day35/car/search/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class SearchConfig(AppConfig): + name = 'search' diff --git a/Day31-Day35/car/search/migrations/0001_initial.py b/Day31-Day35/car/search/migrations/0001_initial.py new file mode 100644 index 0000000000000000000000000000000000000000..ceed8857adc47af2efdc576a619b314df2d7d1b8 --- /dev/null +++ b/Day31-Day35/car/search/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-24 01:16 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='CarRecord', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('carno', models.CharField(max_length=7)), + ('reason', models.CharField(max_length=50)), + ('date', models.DateTimeField(db_column='happen_date')), + ('punlish', models.CharField(max_length=50)), + ('isdone', models.BooleanField(default=False)), + ], + options={ + 'db_table': 'tb_car_record', + }, + ), + ] diff --git a/Day31-Day35/car/search/migrations/0002_auto_20180524_1420.py b/Day31-Day35/car/search/migrations/0002_auto_20180524_1420.py new file mode 100644 index 0000000000000000000000000000000000000000..bd2aa56fdd29ab2aed8856c00798a1f63d141cc8 --- /dev/null +++ b/Day31-Day35/car/search/migrations/0002_auto_20180524_1420.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-24 06:20 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('search', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='carrecord', + options={'ordering': ('-date',)}, + ), + migrations.RenameField( + model_name='carrecord', + old_name='punlish', + new_name='punish', + ), + ] diff --git a/Day31-Day35/car/search/migrations/__init__.py b/Day31-Day35/car/search/migrations/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Day31-Day35/car/search/models.py b/Day31-Day35/car/search/models.py new file mode 100644 index 0000000000000000000000000000000000000000..eeaf4eb11037817ab0483343d57c3d14dc2ab151 --- /dev/null +++ b/Day31-Day35/car/search/models.py @@ -0,0 +1,22 @@ +from django.db import models + + +class CarRecord(models.Model): + carno = models.CharField(max_length=7) + reason = models.CharField(max_length=50) + date = models.DateTimeField(db_column='happen_date', auto_now_add=True) + punish = models.CharField(max_length=50) + isdone = models.BooleanField(default=False) + + @property + def happen_date(self): + return self.date.strftime('%Y-%m-%d %H:%M:%S') + """ + return '%d年%02d月%02d日 %02d:%02d:%02d' % \ + (self.date.year, self.date.month, self.date.day, + self.date.hour, self.date.minute, self.date.second) + """ + + class Meta: + db_table = 'tb_car_record' + ordering = ('-date', ) diff --git a/Day31-Day35/car/search/tests.py b/Day31-Day35/car/search/tests.py new file mode 100644 index 0000000000000000000000000000000000000000..7ce503c2dd97ba78597f6ff6e4393132753573f6 --- /dev/null +++ b/Day31-Day35/car/search/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Day31-Day35/car/search/views.py b/Day31-Day35/car/search/views.py new file mode 100644 index 0000000000000000000000000000000000000000..a0d01a6fab69ca5c6ae779ce4398dd7699281af1 --- /dev/null +++ b/Day31-Day35/car/search/views.py @@ -0,0 +1,78 @@ +from json import JSONEncoder + +from django import forms +from django.http import JsonResponse +from django.shortcuts import render + +from search.models import CarRecord + +# 序列化/串行化/腌咸菜 - 把对象按照某种方式处理成字节或者字符的序列 +# 反序列化/反串行化 - 把字符或者字节的序列重新还原成对象 +# Python实现序列化和反序列化的工具模块 - json / pickle / shelve +# return HttpResponse(json.dumps(obj), content_type='application/json') +# return JsonResponse(obj, encoder=, safe=False) +# from django.core.serializers import serialize +# return HttpResponse(serialize('json', obj), content_type='application/json; charset=utf-8') + + +class CarRecordEncoder(JSONEncoder): + + def default(self, o): + del o.__dict__['_state'] + o.__dict__['date'] = o.happen_date + return o.__dict__ + + +def ajax_search(request): + if request.method == 'GET': + return render(request, 'search2.html') + else: + carno = request.POST['carno'] + record_list = list(CarRecord.objects.filter(carno__icontains=carno)) + # 第一个参数是要转换成JSON格式(序列化)的对象 + # encoder参数要指定完成自定义对象序列化的编码器(JSONEncoder的子类型) + # safe参数的值如果为True那么传入的第一个参数只能是字典 + # return HttpResponse(json.dumps(record_list), content_type='application/json; charset=utf-8') + return JsonResponse(record_list, encoder=CarRecordEncoder, + safe=False) + + +def search(request): + # 请求行中的请求命令 + # print(request.method) + # 请求行中的路径 + # print(request.path) + # 请求头(以HTTP_打头的键是HTTP请求的请求头) + # print(request.META) + # 查询参数: http://host/path/resource?a=b&c=d + # print(request.GET) + # 表单参数 + # print(request.POST) + if request.method == 'GET': + ctx = {'show_result': False} + else: + carno = request.POST['carno'] + ctx = { + 'show_result': True, + 'record_list': list(CarRecord.objects.filter(carno__contains=carno))} + return render(request, 'search.html', ctx) + + +class CarRecordForm(forms.Form): + carno = forms.CharField(min_length=7, max_length=7, label='车牌号', error_messages={'carno': '请输入有效的车牌号'}) + reason = forms.CharField(max_length=50, label='违章原因') + punish = forms.CharField(max_length=50, required=False, label='处罚方式') + + +def add(request): + errors = [] + if request.method == 'GET': + f = CarRecordForm() + else: + f = CarRecordForm(request.POST) + if f.is_valid(): + CarRecord(**f.cleaned_data).save() + f = CarRecordForm() + else: + errors = f.errors.values() + return render(request, 'add.html', {'f': f, 'errors': errors}) diff --git a/Day31-Day35/car/static/images/icon-no.svg b/Day31-Day35/car/static/images/icon-no.svg new file mode 100644 index 0000000000000000000000000000000000000000..2e0d3832c9299c3994f627cd64ed0341a5da7b14 --- /dev/null +++ b/Day31-Day35/car/static/images/icon-no.svg @@ -0,0 +1,3 @@ + + + diff --git a/Day31-Day35/car/static/images/icon-yes.svg b/Day31-Day35/car/static/images/icon-yes.svg new file mode 100644 index 0000000000000000000000000000000000000000..5883d877e89b89d42fa121725ae7b726dbfa5f50 --- /dev/null +++ b/Day31-Day35/car/static/images/icon-yes.svg @@ -0,0 +1,3 @@ + + + diff --git a/Day31-Day35/car/templates/add.html b/Day31-Day35/car/templates/add.html new file mode 100644 index 0000000000000000000000000000000000000000..67ac313eb083d1e414ce50aaf4cd6895bff27673 --- /dev/null +++ b/Day31-Day35/car/templates/add.html @@ -0,0 +1,23 @@ + + + + + 添加 + + +

添加违章记录

+
+

+ {% for err in errors %} +

{{ err }}
+ {% endfor %} +

+
+ + {{ f.as_table }} +
+ {% csrf_token %} + +
+ + \ No newline at end of file diff --git a/Day31-Day35/car/templates/search.html b/Day31-Day35/car/templates/search.html new file mode 100644 index 0000000000000000000000000000000000000000..6183d50b97e892002504ad48b542dc6a0adc502e --- /dev/null +++ b/Day31-Day35/car/templates/search.html @@ -0,0 +1,90 @@ + +{% load staticfiles %} + + + + 车辆违章查询 + + + +
+
+ + + + + {% csrf_token %} + + +
+
+ {% if show_result %} + + + + + + + + + {% for record in record_list %} + + + + + + + + {% endfor %} +
车牌号违章原因违章时间处罚方式是否受理
{{ record.carno }}{{ record.reason }}{{ record.happen_date }}{{ record.punish }} + {% if record.isdone %} + + {% else %} + + {% endif %} +
+ {% endif %} +
+ + \ No newline at end of file diff --git a/Day31-Day35/car/templates/search2.html b/Day31-Day35/car/templates/search2.html new file mode 100644 index 0000000000000000000000000000000000000000..3827332b438bc80be4fb37a9d48b1d354a71cde1 --- /dev/null +++ b/Day31-Day35/car/templates/search2.html @@ -0,0 +1,110 @@ + + + + + 车辆违章查询 + + + +
+ +
+ + + + + + + + + + + + + +
车牌号违章原因违章时间处罚方式是否受理
+
+ + + + \ No newline at end of file diff --git a/Day31-Day35/oa/hrs/migrations/0001_initial.py b/Day31-Day35/oa/hrs/migrations/0001_initial.py new file mode 100644 index 0000000000000000000000000000000000000000..b42df39037ffffb5d74b2a038ef481eba464a6e0 --- /dev/null +++ b/Day31-Day35/oa/hrs/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# Generated by Django 2.0.5 on 2018-05-22 03:07 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Dept', + fields=[ + ('no', models.IntegerField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=20)), + ('location', models.CharField(max_length=10)), + ], + options={ + 'db_table': 'tb_dept', + }, + ), + migrations.CreateModel( + name='Emp', + fields=[ + ('no', models.IntegerField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=20)), + ('job', models.CharField(max_length=10)), + ('mgr', models.IntegerField(null=True)), + ('sal', models.DecimalField(decimal_places=2, max_digits=7)), + ('comm', models.DecimalField(decimal_places=2, max_digits=7, null=True)), + ('dept', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='hrs.Dept')), + ], + options={ + 'db_table': 'tb_emp', + }, + ), + ] diff --git a/Day31-Day35/oa/hrs/migrations/0002_auto_20180523_0923.py b/Day31-Day35/oa/hrs/migrations/0002_auto_20180523_0923.py new file mode 100644 index 0000000000000000000000000000000000000000..8b9b835a5b6e204d799a71659938b8b97db8597e --- /dev/null +++ b/Day31-Day35/oa/hrs/migrations/0002_auto_20180523_0923.py @@ -0,0 +1,43 @@ +# Generated by Django 2.0.5 on 2018-05-23 01:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hrs', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='dept', + name='excellent', + field=models.BooleanField(default=0, verbose_name='是否优秀'), + ), + migrations.AlterField( + model_name='dept', + name='location', + field=models.CharField(max_length=10, verbose_name='部门所在地'), + ), + migrations.AlterField( + model_name='dept', + name='name', + field=models.CharField(max_length=20, verbose_name='部门名称'), + ), + migrations.AlterField( + model_name='dept', + name='no', + field=models.IntegerField(primary_key=True, serialize=False, verbose_name='部门编号'), + ), + migrations.AlterField( + model_name='emp', + name='comm', + field=models.DecimalField(blank=True, decimal_places=2, max_digits=7, null=True), + ), + migrations.AlterField( + model_name='emp', + name='mgr', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/Day31-Day35/oa/hrs/migrations/0003_auto_20180524_1646.py b/Day31-Day35/oa/hrs/migrations/0003_auto_20180524_1646.py new file mode 100644 index 0000000000000000000000000000000000000000..c4054fcc198d52aa73abecc0e228e5f88fe7c13b --- /dev/null +++ b/Day31-Day35/oa/hrs/migrations/0003_auto_20180524_1646.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.5 on 2018-05-24 08:46 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('hrs', '0002_auto_20180523_0923'), + ] + + operations = [ + migrations.AlterField( + model_name='emp', + name='mgr', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='hrs.Emp'), + ), + ] diff --git a/Day31-Day35/oa/hrs/models.py b/Day31-Day35/oa/hrs/models.py index 84fd032bb9441169a9ae1c0804d3a226afe0cba9..b3ab6c0b9da7387bd54dfee8be6bf24e71454364 100644 --- a/Day31-Day35/oa/hrs/models.py +++ b/Day31-Day35/oa/hrs/models.py @@ -24,7 +24,8 @@ class Emp(models.Model): no = models.IntegerField(primary_key=True) name = models.CharField(max_length=20) job = models.CharField(max_length=10) - mgr = models.IntegerField(null=True, blank=True) + mgr = models.ForeignKey('self', null=True, blank=True, on_delete=models.SET_NULL) + # mgr = models.IntegerField(null=True, blank=True) sal = models.DecimalField(max_digits=7, decimal_places=2) comm = models.DecimalField(max_digits=7, decimal_places=2, null=True, blank=True) dept = models.ForeignKey(Dept, on_delete=models.PROTECT) diff --git a/Day31-Day35/oa/hrs/urls.py b/Day31-Day35/oa/hrs/urls.py index 675e9928ee2fc1a0ec27bf677f31ed2f82699817..91a2660c9e882fbcb2e04a52f8f12a0aa96fb08e 100644 --- a/Day31-Day35/oa/hrs/urls.py +++ b/Day31-Day35/oa/hrs/urls.py @@ -4,6 +4,7 @@ from hrs import views urlpatterns = [ path('depts', views.depts, name='depts'), - path('depts/emps', views.emps, name='empsindept'), - path('deldepts', views.del_dept, name='ddel') + # url('depts/emps/(?P[0-9]+)', views.emps, name='empsindept'), + path('depts/emps/', views.emps, name='empsindept'), + path('deldept/', views.del_dept, name='ddel') ] diff --git a/Day31-Day35/oa/hrs/views.py b/Day31-Day35/oa/hrs/views.py index dd70dc89f25c087e055c83a75f601c2444c5763f..269c8197948f567ac7cc8a9c0382d3577e882ff5 100644 --- a/Day31-Day35/oa/hrs/views.py +++ b/Day31-Day35/oa/hrs/views.py @@ -1,5 +1,8 @@ +from django.http import HttpResponse from django.shortcuts import render, redirect -from django.urls import reverse +from django.db.models import ObjectDoesNotExist + +from json import dumps from hrs.models import Dept, Emp @@ -11,13 +14,21 @@ def index(request): return render(request, 'index.html', context=ctx) -def del_dept(request): - # 重定向 - 重新请求一个指定的页面 - return redirect(reverse('depts')) +def del_dept(request, no='0'): + try: + Dept.objects.get(pk=no).delete() + ctx = {'code': 200} + except (ObjectDoesNotExist, ValueError): + ctx = {'code': 404} + return HttpResponse( + dumps(ctx), content_type='application/json; charset=utf-8') + # 重定向 - 给浏览器一个URL, 让浏览器重新请求指定的页面 + # return redirect(reverse('depts')) + # return depts(request) -def emps(request): - no = request.GET['no'] +def emps(request, no='0'): + # no = request.GET['no'] # dept = Dept.objects.get(no=no) # ForeignKey(Dept, on_delete=models.PROTECT, related_name='emps') # dept.emps.all() diff --git a/Day31-Day35/oa/templates/dept.html b/Day31-Day35/oa/templates/dept.html index f7f186088846e2cb6f419faecfc8fa9e6c5b029c..9be8030e9aa20b5d042924cfa69e575bc930fb8b 100644 --- a/Day31-Day35/oa/templates/dept.html +++ b/Day31-Day35/oa/templates/dept.html @@ -5,6 +5,11 @@ 部门 +
@@ -14,6 +19,7 @@
+
@@ -32,7 +38,7 @@ {% endfor %} @@ -60,6 +66,18 @@ $(function() { $('#dept tbody tr:even').addClass('info'); $('#dept tbody tr:odd').addClass('warning'); + $('#dept a[id]').on('click', function(evt) { + var a = $(evt.target); + if (confirm('确定要删除吗?')) { + $.getJSON('/hrs/deldept/' + a.attr('id'), function(json) { + if (json.code == 200) { + a.parent().parent().remove(); + $('#dept tbody tr:even').addClass('info'); + $('#dept tbody tr:odd').addClass('warning'); + } + }); + } + }); });
{{ dept.no }} - {{ dept.name }} + {{ dept.name }} {{ dept.location }} @@ -43,7 +49,7 @@ {% endif %} - 删除 + 删除