def show_permit(request, pk): id = pk if request.method == 'POST': form = PermitForm(request.POST) permit = PermitGateway.find_by_id(_id=pk) if form.is_valid(): permit.update_info(form) permit.save() perm = Permit.objects.get(id=id) permit_form = PermitForm(instance=perm) context = { 'permit': permit, 'form': permit_form, 'error': 0, 'method': 'post', 'id': id } else: context = {'error': 1} return context else: permit = PermitGateway.find_by_id(_id=pk) permit_form = PermitForm(instance=Permit.objects.get(id=id)) context = { 'reqobject': permit, 'form': permit_form, 'error': 0, 'method': 'get', 'id': id } return context
def print(request, pk): permit = PermitGateway.find_by_id(_id=pk) permit.status = u'PRI' permit.save() context = { 'permit': permit, } return context
def print_permit(pk): permit = PermitGateway.find_by_id(_id=pk) pos = PositionGateway.find_by_id(_id=permit.position_id) dep = DepartGateway.find_by_id(_id=permit.department_id) if pos != None: permit.position = pos.name if dep != None: permit.department = dep.full_name() permit.id = pk context = { 'permit': permit, } return context
def permits(request): permits = PermitGateway.all() for permit in permits: pos = PositionGateway.find_by_id(_id=permit.position_id) dep = DepartGateway.find_by_id(_id=permit.department_id) if pos != None: permit.position = pos.name if dep != None: permit.department = dep.full_name() context = { 'permits': permits, } return context
def show_permit(request, pk): id = pk if request.method == 'POST': form = PermitForm(request.POST) permit = PermitGateway.find_by_id(_id=pk) if form.is_valid(): permit.update_info(form) permit.save() perm = Permit.objects.get(id=id) permit_form = PermitForm(instance=perm) context = { 'permit': permit, 'form': permit_form, 'error': 0, 'method': 'post', 'id': id } else: context = { 'error': 1 } return context else: permit = PermitGateway.find_by_id(_id=pk) permit_form = PermitForm(instance=Permit.objects.get(id=id)) context = { 'reqobject': permit, 'form': permit_form, 'error': 0, 'method': 'get', 'id': id } return context
def deletion(pk): requests = RequestGateway.find_by_fields(department_id=pk) permits = PermitGateway.find_by_fields(department_id=pk) persons = PersonGateway.find_by_fields(department_id=pk) for per in permits: per.department_id = None for req in requests: req.department_id = None for per in persons: per.department_id = None MyRequestt.find_by_id(_id=pk)\ .delete() return 1
def delete(pk): position_id = pk position = PositionGateway.find_by_id(_id=position_id) position.delete() requests = RequestGateway.find_by_fields(position_id=position_id) permits = PermitGateway.find_by_fields(position_id=position_id) persons = PersonGateway.find_by_fields(position_id=position_id) for per in permits: per.department_id = None for req in requests: req.department_id = None for per in persons: per.department_id = None return 1
def permits_of_person(pk): person = PersonGateway.find_by_id(_id=pk) person.department = DepartGateway.find_by_id( _id=person.department_id).full_name() person.position = PositionGateway.find_by_id( _id=person.position_id).name permits = PermitGateway.find_by_fields(person=person) for permit in permits: pos = PositionGateway.find_by_id(_id=permit.position_id) dep = DepartGateway.find_by_id(_id=permit.department_id) if pos != None: permit.position = pos.name if dep != None: permit.department = dep.full_name() context = {'permits': permits, 'person': person} return context
def delete(pk): position_id = pk position = PositionGateway.find_by_id(_id = position_id) position.delete() requests = RequestGateway.find_by_fields(position_id=position_id) permits = PermitGateway.find_by_fields(position_id=position_id) persons = PersonGateway.find_by_fields(position_id=position_id) for per in permits: per.department_id = None for req in requests: req.department_id = None for per in persons: per.department_id = None return 1
def permits_of_person(pk): person = PersonGateway.find_by_id(_id = pk) person.department = DepartGateway.find_by_id(_id= person.department_id).full_name() person.position = PositionGateway.find_by_id(_id = person.position_id).name permits = PermitGateway.find_by_fields(person = person) for permit in permits: pos = PositionGateway.find_by_id(_id=permit.position_id) dep = DepartGateway.find_by_id(_id=permit.department_id) if pos != None: permit.position = pos.name if dep != None: permit.department = dep.full_name() context = { 'permits': permits, 'person': person } return context