|
| 1 | +# Python 2 and 3 |
| 2 | +from __future__ import unicode_literals |
| 3 | + |
| 4 | +from future.utils import with_metaclass |
| 5 | + |
| 6 | +from gapipy.models.base import BaseModel |
| 7 | +from gapipy.resources.base import Resource |
| 8 | +from gapipy.utils import get_resource_class_from_resource_name |
| 9 | + |
| 10 | +from .service import Service |
| 11 | + |
| 12 | + |
| 13 | +class LastModified(BaseModel): |
| 14 | + _as_is_fields = [ |
| 15 | + 'name', |
| 16 | + 'user_type', |
| 17 | + ] |
| 18 | + _date_time_fields_utc = ['date'] |
| 19 | + |
| 20 | + |
| 21 | +class ResourceField(BaseModel): |
| 22 | + _as_is_fields = [ |
| 23 | + 'field', |
| 24 | + 'required', |
| 25 | + 'value', |
| 26 | + 'viewable_by', |
| 27 | + ] |
| 28 | + |
| 29 | + @property |
| 30 | + def _resource_fields(self): |
| 31 | + # extract the resource_name from the raw data |
| 32 | + # and use it to return the appropriate resource |
| 33 | + # class |
| 34 | + resource_name = self._raw_data.get('resource', {}).get('resource_name') |
| 35 | + if resource_name: |
| 36 | + try: |
| 37 | + resource_class = get_resource_class_from_resource_name(resource_name) |
| 38 | + return [ |
| 39 | + ('resource', resource_class), |
| 40 | + ] |
| 41 | + except: |
| 42 | + pass |
| 43 | + # fall back |
| 44 | + return [] |
| 45 | + |
| 46 | + |
| 47 | +class Requirement(Resource): |
| 48 | + _resource_name = 'requirements' |
| 49 | + |
| 50 | + _as_is_fields = [ |
| 51 | + 'id', |
| 52 | + 'href', |
| 53 | + 'type', |
| 54 | + 'applied_overrides', |
| 55 | + 'code', |
| 56 | + 'editable_by', |
| 57 | + 'flags', |
| 58 | + 'name', |
| 59 | + 'override_reasons', |
| 60 | + 'status', |
| 61 | + ] |
| 62 | + |
| 63 | + _date_fields = [ |
| 64 | + 'complete_by_date', |
| 65 | + ] |
| 66 | + |
| 67 | + _model_fields = [ |
| 68 | + ('last_modified', LastModified), |
| 69 | + ] |
| 70 | + |
| 71 | + _resource_fields = [ |
| 72 | + ('booking', 'Booking'), |
| 73 | + ('customer', 'Customer'), |
| 74 | + ('requirement_set', 'RequirementSet'), |
| 75 | + ] |
| 76 | + |
| 77 | + _model_collection_fields = [ |
| 78 | + ('services', Service), |
| 79 | + ('resource_fields', ResourceField), |
| 80 | + ] |
| 81 | + |
| 82 | + |
| 83 | +class RequirementSet(Resource): |
| 84 | + _resource_name = 'requirement_sets' |
| 85 | + |
| 86 | + _is_listable = True |
| 87 | + |
| 88 | + _as_is_fields = [ |
| 89 | + 'id', |
| 90 | + 'href', |
| 91 | + 'code', |
| 92 | + 'name', |
| 93 | + ] |
| 94 | + |
| 95 | + _date_fields = [ |
| 96 | + 'complete_by_date', |
| 97 | + ] |
| 98 | + |
| 99 | + _model_collection_fields = [ |
| 100 | + ('requirements', Requirement), |
| 101 | + ] |
| 102 | + |
| 103 | + _resource_fields = [ |
| 104 | + ('booking', 'Booking'), |
| 105 | + ] |
| 106 | + |
0 commit comments