mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 07:19:36 +02:00
feat: Add hotel management functionality with serializer and UI integration
This commit is contained in:
parent
271cba9abc
commit
d1f50dfa17
8 changed files with 425 additions and 541 deletions
|
@ -203,6 +203,17 @@ class TransportationSerializer(CustomModelSerializer):
|
|||
]
|
||||
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']
|
||||
|
||||
class HotelSerializer(CustomModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Hotel
|
||||
fields = [
|
||||
'id', 'user_id', 'name', 'description', 'rating', 'link', 'check_in', 'check_out',
|
||||
'reservation_number', 'price', 'latitude', 'longitude', 'location', 'is_public',
|
||||
'collection', 'created_at', 'updated_at'
|
||||
]
|
||||
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']
|
||||
|
||||
class NoteSerializer(CustomModelSerializer):
|
||||
|
||||
class Meta:
|
||||
|
@ -289,10 +300,11 @@ class CollectionSerializer(CustomModelSerializer):
|
|||
transportations = TransportationSerializer(many=True, read_only=True, source='transportation_set')
|
||||
notes = NoteSerializer(many=True, read_only=True, source='note_set')
|
||||
checklists = ChecklistSerializer(many=True, read_only=True, source='checklist_set')
|
||||
hotels = HotelSerializer(many=True, read_only=True, source='hotel_set')
|
||||
|
||||
class Meta:
|
||||
model = Collection
|
||||
fields = ['id', 'description', 'user_id', 'name', 'is_public', 'adventures', 'created_at', 'start_date', 'end_date', 'transportations', 'notes', 'updated_at', 'checklists', 'is_archived', 'shared_with', 'link']
|
||||
fields = ['id', 'description', 'user_id', 'name', 'is_public', 'adventures', 'created_at', 'start_date', 'end_date', 'transportations', 'notes', 'updated_at', 'checklists', 'is_archived', 'shared_with', 'link', 'hotels']
|
||||
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']
|
||||
|
||||
def to_representation(self, instance):
|
||||
|
@ -302,15 +314,4 @@ class CollectionSerializer(CustomModelSerializer):
|
|||
for user in instance.shared_with.all():
|
||||
shared_uuids.append(str(user.uuid))
|
||||
representation['shared_with'] = shared_uuids
|
||||
return representation
|
||||
|
||||
class HotelSerializer(CustomModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = Hotel
|
||||
fields = [
|
||||
'id', 'user_id', 'name', 'description', 'rating', 'link', 'check_in', 'check_out',
|
||||
'reservation_number', 'price', 'latitude', 'longitude', 'location', 'is_public',
|
||||
'collection', 'created_at', 'updated_at'
|
||||
]
|
||||
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']
|
||||
return representation
|
|
@ -45,8 +45,9 @@ class Command(BaseCommand):
|
|||
force = options['force']
|
||||
batch_size = 100
|
||||
current_version_json = os.path.join(settings.MEDIA_ROOT, 'data_version.json')
|
||||
cdn_version_json = requests.get(f'{ADVENTURELOG_CDN_URL}/data/version.json')
|
||||
if cdn_version_json.status_code == 200:
|
||||
try:
|
||||
cdn_version_json = requests.get(f'{ADVENTURELOG_CDN_URL}/data/version.json')
|
||||
cdn_version_json.raise_for_status()
|
||||
cdn_version = cdn_version_json.json().get('version')
|
||||
if os.path.exists(current_version_json):
|
||||
with open(current_version_json, 'r') as f:
|
||||
|
@ -62,8 +63,8 @@ class Command(BaseCommand):
|
|||
else:
|
||||
self.stdout.write(self.style.SUCCESS('Data is already up-to-date. Run with --force to re-download'))
|
||||
return
|
||||
else:
|
||||
self.stdout.write(self.style.ERROR('Error downloading version.json'))
|
||||
except requests.RequestException as e:
|
||||
self.stdout.write(self.style.ERROR(f'Error fetching version from the CDN: {e}, skipping data import. Try restarting the container once CDN connection has been restored.'))
|
||||
return
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('Fetching latest data from the AdventureLog CDN located at: ' + ADVENTURELOG_CDN_URL))
|
||||
|
@ -90,27 +91,6 @@ class Command(BaseCommand):
|
|||
self.stdout.write(self.style.ERROR('Error downloading countries_states_cities.json'))
|
||||
return
|
||||
|
||||
|
||||
# if not os.path.exists(version_json) or force:
|
||||
# res = requests.get(f'https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/{COUNTRY_REGION_JSON_VERSION}/json/countries%2Bstates%2Bcities.json')
|
||||
# if res.status_code == 200:
|
||||
# with open(countries_json_path, 'w') as f:
|
||||
# f.write(res.text)
|
||||
# self.stdout.write(self.style.SUCCESS('countries+regions+states.json downloaded successfully'))
|
||||
# else:
|
||||
# self.stdout.write(self.style.ERROR('Error downloading countries+regions+states.json'))
|
||||
# return
|
||||
# elif not os.path.isfile(countries_json_path):
|
||||
# self.stdout.write(self.style.ERROR('countries+regions+states.json is not a file'))
|
||||
# return
|
||||
# elif os.path.getsize(countries_json_path) == 0:
|
||||
# self.stdout.write(self.style.ERROR('countries+regions+states.json is empty'))
|
||||
# elif Country.objects.count() == 0 or Region.objects.count() == 0 or City.objects.count() == 0:
|
||||
# self.stdout.write(self.style.WARNING('Some region data is missing. Re-importing all data.'))
|
||||
# else:
|
||||
# self.stdout.write(self.style.SUCCESS('Latest country, region, and state data already downloaded.'))
|
||||
# return
|
||||
|
||||
with open(countries_json_path, 'r') as f:
|
||||
f = open(countries_json_path, 'rb')
|
||||
parser = ijson.items(f, 'item')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue