14 |
14 |
# You should have received a copy of the GNU Affero General Public License
|
15 |
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.xs
|
16 |
16 |
|
|
17 |
import re
|
17 |
18 |
from urllib.parse import urljoin
|
18 |
19 |
|
19 |
20 |
from django.core.cache import cache
|
... | ... | |
35 |
36 |
|
36 |
37 |
ENVS = (('test', _('Test')), ('prod', _('Production')))
|
37 |
38 |
|
|
39 |
FNI_PLATE_PATTERN = re.compile(r'(\d{2,4})([a-zA-Z]{2,3})(\d{2,3})')
|
|
40 |
|
38 |
41 |
|
39 |
42 |
class Resource(BaseResource):
|
40 |
43 |
consumer_key = models.CharField(_('Consumer key'), max_length=128)
|
... | ... | |
86 |
89 |
def get_infos_by_immat(self, endpoint, immat, codesra=None):
|
87 |
90 |
# remove dashes / spaces in immat to avoid lookup issues
|
88 |
91 |
immat = immat.strip().replace('-', '').replace(' ', '').upper()
|
|
92 |
fin_match = FNI_PLATE_PATTERN.match(immat)
|
|
93 |
if fin_match:
|
|
94 |
immat = f'{fin_match.group(3)}{fin_match.group(2)}{fin_match.group(1).zfill(4)}'
|
89 |
95 |
payload = {'immat': immat}
|
90 |
96 |
if codesra is not None:
|
91 |
97 |
payload['codesra'] = codesra
|
... | ... | |
111 |
117 |
@endpoint(
|
112 |
118 |
perm='can_access',
|
113 |
119 |
description=_('Get vehicle details by registration plate'),
|
114 |
|
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '01XT0747'}},
|
|
120 |
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '747XT01'}},
|
115 |
121 |
)
|
116 |
122 |
def consultervehiculeparimmat(self, request, immat, codesra=None):
|
117 |
123 |
return self.get_infos_by_immat('consultervehiculeparimmat', immat, codesra)
|
... | ... | |
119 |
125 |
@endpoint(
|
120 |
126 |
perm='can_access',
|
121 |
127 |
description=_('Get vehicle "finition" by registration plate'),
|
122 |
|
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '01XT0747'}},
|
|
128 |
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '747XT01'}},
|
123 |
129 |
)
|
124 |
130 |
def consulterfinitionparimmat(self, request, immat, codesra=None):
|
125 |
131 |
result = self.get_infos_by_immat('consulterfinitionparimmat', immat, codesra)
|
... | ... | |
128 |
134 |
@endpoint(
|
129 |
135 |
perm='can_access',
|
130 |
136 |
description=_('Get vehicle "finition" by registration plate, ordered by rangs'),
|
131 |
|
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '01XT0747'}},
|
|
137 |
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '747XT01'}},
|
132 |
138 |
)
|
133 |
139 |
def consulterfinitionscoresparimmat(self, request, immat, codesra=None):
|
134 |
140 |
return self.get_infos_by_immat('consulterfinitionscoresparimmat', immat, codesra)
|
... | ... | |
136 |
142 |
@endpoint(
|
137 |
143 |
perm='can_access',
|
138 |
144 |
description=_('Get vehicle theorical "finition" by registration plate'),
|
139 |
|
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '01XT0747'}},
|
|
145 |
parameters={'immat': {'description': _('Registration plate number'), 'example_value': '747XT01'}},
|
140 |
146 |
)
|
141 |
147 |
def consulterfinitiontheoriqueparimmat(self, request, immat, codesra=None):
|
142 |
148 |
return self.get_infos_by_immat('consulterfinitiontheoriqueparimmat', immat, codesra)
|