coding utf-8 Author Alexey Kuzmin quzmich gmail com import logging fro

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
# Author: Alexey Kuzmin <quzmich@gmail.com>
import logging
from wapy.cache import cache
from wapy.rest import RestView
from wapy.entity.sqla import SQLAEntityStore, row2dict
from wapy.entity.schema import Entity, EntityNode, String, Integer, Float
from uris import models
from uris import classifiers as cls
from uris.views.rest import RestHandlerView
from pyramid.response import Response
log = logging.getLogger('uris')
repair_info_store = SQLAEntityStore()
repair_info_store.model = models.ObjectInfo
def to_int(s):
if isinstance(s, basestring):
s = s.strip()
s = '' if s is None else s
return int(s) if s else 0
class RepairInfoEntity(Entity):
# Шифр объекта
object_cipher = EntityNode(String())
# Воинские части_ID
military_units_id = EntityNode(Integer())
# Гарнизон
garrison = EntityNode(String())
# КЭЧ района (объединение) (Воинские части_ID)
cou = EntityNode(Integer())
# Номер военного городка
cantonment_number = EntityNode(String())
# Наименование работ
work_name = EntityNode(String())
# Наименование объекта по титулу
object_name = EntityNode(String())
repair_info_struct = RepairInfoEntity()
class RepairInfo(RestHandlerView):
store = repair_info_store
def collection_get(self):
entities = repair_info_store.find(self.request.filters, **self.request.terms)
rows = [row2dict(row) for row in entities]
for row in rows:
mil_unit = cls.military_unit_by_id(row['military_unit_id'])
row['military_unit_name'] = mil_unit.get('number', '')
return rows
def collection_post(self):
cstruct = self.request.json_body
rid = repair_info_store.insert(cstruct)
return {"id": rid}
def get(self):
row = repair_info_store[self.request.id]
row = row2dict(row)
return row
def put(self):
cstruct = self.request.json_body
repair_info_store.update({'id': self.request.id}, cstruct)
return {"id": self.request.id}