Various improvements to the schedule view
Still clearly not yet complete though.
This commit is contained in:
parent
1017823b06
commit
890392ab92
|
@ -8,6 +8,8 @@
|
|||
|
||||
$(function() {
|
||||
|
||||
$('.timesheet-header select').selectmenu();
|
||||
|
||||
$('.week-picker #date').datepicker({
|
||||
dateFormat: 'yy-mm-dd',
|
||||
changeYear: true,
|
||||
|
@ -43,11 +45,29 @@
|
|||
## </div>
|
||||
## </div>
|
||||
|
||||
<div class="field-wrapper week">
|
||||
<label>Week of</label>
|
||||
<div class="field">
|
||||
${week_of}
|
||||
<div class="fieldset">
|
||||
|
||||
<div class="field-wrapper week">
|
||||
<label>Store</label>
|
||||
<div class="field">
|
||||
${form.select('store', store_options, selected_value=store.uuid if store else None)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-wrapper week">
|
||||
<label>Department</label>
|
||||
<div class="field">
|
||||
${form.select('department', department_options, selected_value=department.uuid if department else None)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field-wrapper week">
|
||||
<label>Week of</label>
|
||||
<div class="field">
|
||||
${week_of}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="week-picker">
|
||||
|
|
|
@ -3,4 +3,9 @@
|
|||
|
||||
<%def name="title()">Schedule: ${sunday}</%def>
|
||||
|
||||
<ul id="context-menu">
|
||||
<li>${h.link_to("Print this Schedule", '#')}</li>
|
||||
<li>${h.link_to("Edit this Schedule", '#')}</li>
|
||||
</ul>
|
||||
|
||||
${self.timesheet(employees)}
|
||||
|
|
|
@ -28,31 +28,94 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
import datetime
|
||||
|
||||
from rattail.db import model
|
||||
from rattail import enum
|
||||
from rattail.db import model, api
|
||||
from rattail.time import localtime, get_sunday
|
||||
|
||||
import formencode as fe
|
||||
from pyramid_simpleform import Form
|
||||
|
||||
from tailbone import forms
|
||||
from tailbone.db import Session
|
||||
from tailbone.views import View
|
||||
|
||||
|
||||
class ShiftFilter(fe.Schema):
|
||||
allow_extra_fields = True
|
||||
filter_extra_fields = True
|
||||
store = forms.validators.ValidStore()
|
||||
department = forms.validators.ValidDepartment()
|
||||
|
||||
|
||||
class TimeSheetView(View):
|
||||
"""
|
||||
Base view for time sheets.
|
||||
"""
|
||||
model_class = None
|
||||
|
||||
# Set this to False to avoid the default behavior of auto-filtering by
|
||||
# current store.
|
||||
default_filter_store = True
|
||||
|
||||
def __call__(self):
|
||||
date = self.get_date()
|
||||
store = None
|
||||
department = None
|
||||
employees = Session.query(model.Employee)\
|
||||
.filter(model.Employee.status == enum.EMPLOYEE_STATUS_CURRENT)
|
||||
|
||||
form = Form(self.request, schema=ShiftFilter)
|
||||
if form.validate():
|
||||
store = form.data['store']
|
||||
department = form.data['department']
|
||||
|
||||
elif self.request.method != 'POST' and self.default_filter_store:
|
||||
store = self.rattail_config.get('rattail', 'store')
|
||||
if store:
|
||||
store = api.get_store(Session(), store)
|
||||
|
||||
# TODO:
|
||||
# store = Session.query(model.Store).filter_by(id='003').one()
|
||||
# department = Session.query(model.Department).filter_by(number=6).one()
|
||||
|
||||
if store:
|
||||
employees = employees.join(model.EmployeeStore)\
|
||||
.filter(model.EmployeeStore.store == store)
|
||||
|
||||
if department:
|
||||
employees = employees.join(model.EmployeeDepartment)\
|
||||
.filter(model.EmployeeDepartment.department == department)
|
||||
|
||||
return self.render(date, employees.all(), store=store, department=department, form=form)
|
||||
|
||||
def get_date(self):
|
||||
date = None
|
||||
if 'date' in self.request.GET:
|
||||
if 'date' in self.request.params:
|
||||
try:
|
||||
date = datetime.datetime.strptime(self.request.GET['date'], '%Y-%m-%d').date()
|
||||
date = datetime.datetime.strptime(self.request.params['date'], '%Y-%m-%d').date()
|
||||
except ValueError:
|
||||
self.request.session.flash("The specified date is not valid: {}".format(self.request.GET['date']), 'error')
|
||||
self.request.session.flash("The specified date is not valid: {}".format(self.request.params['date']), 'error')
|
||||
if not date:
|
||||
date = localtime(self.rattail_config).date()
|
||||
return date
|
||||
|
||||
def render(self, date, employees):
|
||||
def get_stores(self):
|
||||
return Session.query(model.Store).order_by(model.Store.id).all()
|
||||
|
||||
def get_store_options(self, stores):
|
||||
options = [(s.uuid, "{} - {}".format(s.id, s.name)) for s in stores]
|
||||
options.insert(0, (None, "(all)"))
|
||||
return options
|
||||
|
||||
def get_departments(self):
|
||||
return Session.query(model.Department).order_by(model.Department.name).all()
|
||||
|
||||
def get_department_options(self, departments):
|
||||
options = [(d.uuid, d.name) for d in departments]
|
||||
options.insert(0, (None, "(all)"))
|
||||
return options
|
||||
|
||||
def render(self, date, employees, store=None, department=None, form=None):
|
||||
"""
|
||||
Render a time sheet for one or more employees, for the week which
|
||||
includes the specified date.
|
||||
|
@ -69,8 +132,22 @@ class TimeSheetView(View):
|
|||
week_of = '{} - {}'.format(sunday.strftime('%a %b %d, Y'), saturday.strftime('%a %b %d, %Y'))
|
||||
|
||||
self.modify_employees(employees, weekdays)
|
||||
|
||||
stores = self.get_stores()
|
||||
store_options = self.get_store_options(stores)
|
||||
|
||||
departments = self.get_departments()
|
||||
department_options = self.get_department_options(departments)
|
||||
|
||||
return {
|
||||
'form': forms.FormRenderer(form) if form else None,
|
||||
'employees': employees,
|
||||
'stores': stores,
|
||||
'store_options': store_options,
|
||||
'store': store,
|
||||
'departments': departments,
|
||||
'department_options': department_options,
|
||||
'department': department,
|
||||
'week_of': week_of,
|
||||
'sunday': sunday,
|
||||
'prev_sunday': sunday - datetime.timedelta(days=7),
|
||||
|
|
|
@ -39,24 +39,6 @@ class ScheduleView(TimeSheetView):
|
|||
"""
|
||||
model_class = model.ScheduledShift
|
||||
|
||||
def __call__(self):
|
||||
date = self.get_date()
|
||||
employees = Session.query(model.Employee)\
|
||||
.filter(model.Employee.status == enum.EMPLOYEE_STATUS_CURRENT)
|
||||
|
||||
# TODO:
|
||||
# store = Session.query(model.Store).filter_by(id='003').one()
|
||||
# department = Session.query(model.Department).filter_by(number=6).one()
|
||||
|
||||
# if store:
|
||||
# employees = employees.join(model.EmployeeStore)\
|
||||
# .filter(model.EmployeeStore.store == store)
|
||||
# if department:
|
||||
# employees = employees.join(model.EmployeeDepartment)\
|
||||
# .filter(model.EmployeeDepartment.department == department)
|
||||
|
||||
return self.render(date, employees.all())
|
||||
|
||||
|
||||
def includeme(config):
|
||||
|
||||
|
|
Loading…
Reference in a new issue