Skip to content

Commit b81bc1a

Browse files
committed
职位增删改查
1 parent c7be67e commit b81bc1a

11 files changed

Lines changed: 140 additions & 18 deletions

File tree

36-job-and-resume-management/jobplus/jobplus/forms.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from flask_wtf import FlaskForm
2-
from wtforms import StringField, PasswordField, SubmitField, BooleanField, ValidationError, IntegerField, TextAreaField
2+
from wtforms import StringField, PasswordField, SubmitField, BooleanField, ValidationError, IntegerField, TextAreaField, SelectField
33
from wtforms.validators import Length, Email, EqualTo, Required
4-
from jobplus.models import db, User, CompanyDetail
4+
from jobplus.models import db, User, CompanyDetail, Job
55

66

77
class LoginForm(FlaskForm):
@@ -144,3 +144,49 @@ def update(self, company):
144144
db.session.add(company)
145145
db.session.add(detail)
146146
db.session.commit()
147+
148+
149+
class JobForm(FlaskForm):
150+
name = StringField('职位名称')
151+
salary_low = IntegerField('最低薪酬')
152+
salary_high = IntegerField('最高薪酬')
153+
location = StringField('工作地点')
154+
tags = StringField('职位标签(多个用,隔开)')
155+
experience_requirement = SelectField(
156+
'经验要求(年)',
157+
choices=[
158+
('不限', '不限'),
159+
('1', '1'),
160+
('2', '2'),
161+
('3', '3'),
162+
('1-3', '1-3'),
163+
('3-5', '3-5'),
164+
('5+', '5+')
165+
]
166+
)
167+
degree_requirement = SelectField(
168+
'学历要求',
169+
choices=[
170+
('不限', '不限'),
171+
('专科', '专科'),
172+
('本科', '本科'),
173+
('硕士', '硕士'),
174+
('博士', '博士')
175+
]
176+
)
177+
description = TextAreaField('职位描述', validators=[Length(0, 1500)])
178+
submit = SubmitField('发布')
179+
180+
def create_job(self, company):
181+
job = Job()
182+
self.populate_obj(job)
183+
job.company_id = company.id
184+
db.session.add(job)
185+
db.session.commit()
186+
return job
187+
188+
def update_job(self, job):
189+
self.populate_obj(job)
190+
db.session.add(job)
191+
db.session.commit()
192+
return job

36-job-and-resume-management/jobplus/jobplus/handlers/company.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from flask import Blueprint, render_template, flash, redirect, url_for, request, abort, current_app
22
from flask_login import login_required, current_user
3-
from jobplus.forms import CompanyProfileForm
3+
from jobplus.forms import CompanyProfileForm, JobForm
44
from jobplus.models import User, Job, Delivery, db
55

66
company = Blueprint('company', __name__, url_prefix='/company')
@@ -99,7 +99,7 @@ def admin_apply_reject(company_id, delivery_id):
9999
return redirect(url_for('company.admin_apply', company_id=company_id))
100100

101101

102-
@company.route('/<int:company_id>/admin/apply/<int:delivery_id>/accept')
102+
@company.route('/<int:company_id>/admin/apply/<int:delivery_id>/accept/')
103103
@login_required
104104
def admin_apply_accept(company_id, delivery_id):
105105
d = Delivery.query.get_or_404(delivery_id)
@@ -109,3 +109,46 @@ def admin_apply_accept(company_id, delivery_id):
109109
db.session.add(d)
110110
db.session.commit()
111111
return redirect(url_for('company.admin_apply', company_id=company_id))
112+
113+
114+
@company.route('/<int:company_id>/admin/publish_job/', methods=['GET', 'POST'])
115+
@login_required
116+
def admin_publish_job(company_id):
117+
if current_user.id != company_id:
118+
abort(404)
119+
form = JobForm()
120+
if form.validate_on_submit():
121+
form.create_job(current_user)
122+
flash('职位创建成功', 'success')
123+
return redirect(url_for('company.admin_index', company_id=current_user.id))
124+
return render_template('company/publish_job.html', form=form, company_id=company_id)
125+
126+
127+
@company.route('/<int:company_id>/admin/edit_job/<int:job_id>/', methods=['GET', 'POST'])
128+
@login_required
129+
def admin_edit_job(company_id, job_id):
130+
if current_user.id != company_id:
131+
abort(404)
132+
job = Job.query.get_or_404(job_id)
133+
if job.company_id != current_user.id:
134+
abort(404)
135+
form = JobForm(obj=job)
136+
if form.validate_on_submit():
137+
form.update_job(job)
138+
flash('职位更新成功', 'success')
139+
return redirect(url_for('company.admin_index', company_id=current_user.id))
140+
return render_template('company/edit_job.html', form=form, company_id=company_id, job=job)
141+
142+
143+
@company.route('/<int:company_id>/admin/jobs/<int:job_id>/delete')
144+
@login_required
145+
def admin_delete_job(company_id, job_id):
146+
if current_user.id != company_id:
147+
abort(404)
148+
job = Job.query.get_or_404(job_id)
149+
if job.company_id != current_user.id:
150+
abort(404)
151+
db.session.delete(job)
152+
db.session.commit()
153+
flash('职位更新成功', 'success')
154+
return redirect(url_for('company.admin_index', company_id=current_user.id))

36-job-and-resume-management/jobplus/jobplus/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ class User(Base, UserMixin):
5555
def __repr__(self):
5656
return '<User:{}>'.format(self.name)
5757

58+
@property
59+
def enable_jobs(self):
60+
if not self.is_company:
61+
raise AttributeError('User has no attribute enable_jobs')
62+
return self.jobs.filter(Job.is_disable.is_(False))
63+
5864
@property
5965
def password(self):
6066
return self._password

36-job-and-resume-management/jobplus/jobplus/static/main.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,13 @@ a.dilivery-btn {
9595
color: #5cb85c;
9696
background-color: #eee;
9797
}
98+
99+
.btn-admin {
100+
width: 100%;
101+
background-color: #ffffff;
102+
margin-bottom: 5px;
103+
}
104+
105+
a.btn-admin {
106+
color: #5cb85c;
107+
}

36-job-and-resume-management/jobplus/jobplus/templates/company/admin_apply.html

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
{% extends "company/admin_base.html" %}
22

33
{% block operation %}
4-
<a href="{{ url_for('company.admin_apply', company_id=company_id, status=1) }}" type="button" class="btn btn-primary">
5-
未处理
6-
</a>
7-
8-
<a href="{{ url_for('company.admin_apply', company_id=company_id, status=2) }}" type="button" class="btn btn-primary">
9-
面试
10-
</a>
11-
12-
<a href="{{ url_for('company.admin_apply', company_id=company_id, status=3) }}" type="button" class="btn btn-primary">
13-
不适合
14-
</a>
4+
<a href="{{ url_for('company.admin_apply', company_id=company_id, status=1) }}" type="button" class="btn btn-success btn-admin">未处理</a>
5+
<a href="{{ url_for('company.admin_apply', company_id=company_id, status=2) }}" type="button" class="btn btn-success btn-admin">面试</a>
6+
<a href="{{ url_for('company.admin_apply', company_id=company_id, status=3) }}" type="button" class="btn btn-success btn-admin">不适合</a>
157
{% endblock %}
168

179
{% block admin %}

36-job-and-resume-management/jobplus/jobplus/templates/company/admin_base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
{% block body %}
88
<div class="row">
99
<div class="col-md-3">
10+
<h4>公司管理</h4>
1011
<div class="list-group">
1112
<a href="{{ url_for('company.admin_index', company_id=company_id) }}" class="list-group-item">职位管理</a>
1213
<a href="{{ url_for('company.admin_apply', company_id=company_id) }}" class="list-group-item">投递管理</a>

36-job-and-resume-management/jobplus/jobplus/templates/company/admin_index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{% extends "company/admin_base.html" %}
22

3+
{% block operation %}
4+
<a href="{{ url_for('company.admin_publish_job', company_id=company_id) }}" type="button" class="btn btn-success btn-admin">发布职位</a>
5+
{% endblock %}
6+
37
{% block admin %}
48
<table class="table">
59
<thead>
@@ -28,6 +32,12 @@
2832
上线
2933
</a>
3034
{% endif %}
35+
<a href="{{ url_for('company.admin_edit_job', company_id=company_id, job_id=job.id) }}" type="button" class="btn btn-default">
36+
编辑
37+
</a>
38+
<a href="{{ url_for('company.admin_delete_job', company_id=company_id, job_id=job.id) }}" type="button" class="btn btn-default">
39+
删除
40+
</a>
3141
</div>
3242
</td>
3343
</tr>

36-job-and-resume-management/jobplus/jobplus/templates/company/detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ <h2>{{ company.name }}</h2>
2525
<div class="col-md-8">
2626
<ul class="nav nav-tabs">
2727
<li role="presentation" class="{% if panel == 'about' %}active{% endif %}"><a href="{{ url_for('company.detail', company_id=company.id) }}">公司介绍</a></li>
28-
<li role="presentation" class="{% if panel == 'job' %}active{% endif %}"><a href="{{ url_for('company.company_jobs', company_id=company.id) }}">在招职位({{ company.jobs.count() }})</a></li>
28+
<li role="presentation" class="{% if panel == 'job' %}active{% endif %}"><a href="{{ url_for('company.company_jobs', company_id=company.id) }}">在招职位({{ company.enable_jobs.count() }})</a></li>
2929
</ul>
3030
<div class="company-detail">
3131
{% if panel == 'about' %}
3232
{{ company.detail.about }}
3333
{% else %}
34-
{% for job in company.jobs %}
34+
{% for job in company.enable_jobs %}
3535
<div class="job-item">
3636
<a href="{{ url_for('job.detail', job_id=job.id) }}">
3737
<h4>{{ job.name }}</h4>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "company/admin_base.html" %}
2+
{% from "macros.html" import render_form %}
3+
4+
{% block admin %}
5+
<h4>编辑职位</h4>
6+
{{ render_form(form, url_for('company.admin_edit_job', company_id=company_id, job_id=job.id)) }}
7+
{% endblock %}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% extends "company/admin_base.html" %}
2+
{% from "macros.html" import render_form %}
3+
4+
{% block admin %}
5+
<h4>发布职位</h4>
6+
{{ render_form(form, url_for('company.admin_publish_job', company_id=company_id)) }}
7+
{% endblock %}

0 commit comments

Comments
 (0)