Skip to content

Commit

Permalink
Merge 9cd4249 into dd656a0
Browse files Browse the repository at this point in the history
  • Loading branch information
FatemehMoghadam committed Jun 26, 2018
2 parents dd656a0 + 9cd4249 commit 817d3fb
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 44 deletions.
4 changes: 3 additions & 1 deletion parkstay/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ def available_campsite_classes(self, request, format='json', pk=None):
s = CampsiteClassSerializer(CampsiteClass.objects.get(id=k),context={'request':request},method='get').data
s['campsites'] = [c.id for c in v]
available_serializers.append(s)
available_serializers.sort(key=lambda x: x['name'])
data = available_serializers

return Response(data,status=http_status)
Expand Down Expand Up @@ -1640,7 +1641,8 @@ def list(self, request, *args, **kwargs):
for item in first_campsite_list:
campground_site_type.append ({
"name": '{}'.format(item.name if item else ""),
"type": '{}'.format(item.type if item.type else "")
"type": '{}'.format(item.type if item.type else ""),
"campground_type": item.campground.site_type,
})
bk['campground_site_type'] = campground_site_type
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
</div>
<div class="row">
<div class="col-sm-12">
<div v-show="booking.campsite_classes.length > 1">
<div v-show="booking.campsite_classes.length > 0">
<div class="column table-scroll">
<table class="hover table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%" name="campsite-type" v-model="selected_campsite_class">
<thead>
Expand Down
65 changes: 37 additions & 28 deletions parkstay/frontend/parkstay/src/components/booking/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,34 +219,36 @@ export default {
{
data: "campground_site_type",
mRender: function(data, type, full) {
if (data.length == 1) {
var typeCondensed = {};
var resultList = [];
for (var i = 0; i < data.length; i++) {
if (data[i].campground_type === 0) {
resultList.push(data[i].name);
continue;
}
if (typeCondensed[data[i].type] == undefined) {
typeCondensed[data[i].type] = 0;
}
typeCondensed[data[i].type] += 1;
}
for (var index in typeCondensed) {
var count = typeCondensed[index];
var site_type = index.split(':', 1)[0];
resultList.push(`${count}x ${site_type}`);
}
if (resultList.length == 1) {
var max_length = 15;
var name = (data[0].type.length > max_length) ? data[0].type.substring(0,max_length-1)+'...' : data[0].type;
var name = (resultList[0] > max_length) ? resultList[0].substring(0,max_length-1): resultList[0];
var column = '<td> <div class="name_popover" tabindex="0" data-toggle="popover" data-placement="top" data-content="__NAME__" >'+ name +'</div></td>';
return column.replace('__NAME__', data[0].type);
} else if (data.length > 1) {
var results = {};
for (var i = 0; i < data.length; i++) {
if (results[data[i].name] == undefined) {
results[data[i].name] = 0;
}
results[data[i].name] += 1;
}
var resultList = [];
for (var index in results) {
resultList.push(`${index}`);
}
return column.replace('__NAME__', resultList[0]);
}
else if (data.length > 1) {
var resultString = resultList.join(", ");
var max_length = 15;
var name = "Multiple";
var column =
'<td><span style="padding: 0;" class="name_popover" tabindex="0" data-toggle="popover" data-placement="top" data-content="__NAME__" >' +
name +
"</span></td>";
var column ='<td><span class="name_popover" tabindex="0" data-toggle="popover" data-placement="top" data-content="__NAME__" >' +name +"</span></td>";
return column.replace("__NAME__", resultString);
}
return "<td></td>";
},
orderable: false,
Expand Down Expand Up @@ -676,16 +678,23 @@ export default {
bk[field] = booking.id;
break;
case 7:
var results = {};
var typeCondensed = {};
var resultList = [];
for (var i = 0; i < booking.campground_site_type.length; i++) {
if (results[booking.campground_site_type[i].name] == undefined) {
results[booking.campground_site_type[i].name] = 0;
if (booking.campground_site_type[i].campground_type === 0) {
resultList.push(booking.campground_site_type[i].name);
continue;
}
results[booking.campground_site_type[i].name] += 1;
if (typeCondensed[booking.campground_site_type[i].type] == undefined) {
typeCondensed[booking.campground_site_type[i].type] = 0;
}
typeCondensed[booking.campground_site_type[i].type] += 1;
}
var resultList = [];
for (var index in results) {
resultList.push(`${index}`);
for (var index in typeCondensed) {
var count = typeCondensed[index];
var site_type = index.split(':', 1)[0];
resultList.push(`${count}x ${site_type}`);
}
var resultString = resultList.join(", ");
bk[field] = resultString;
Expand Down
20 changes: 13 additions & 7 deletions parkstay/frontend/parkstay/src/components/booking/history.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,22 @@ export default {
},
computed: {
CampSiteType: function(){
var results = {};
var typeCondensed = {};
var resultList = [];
for (var i = 0; i < this.booking.campground_site_type.length; i++) {
if (results[this.booking.campground_site_type[i].name] == undefined) {
results[this.booking.campground_site_type[i].name] = 0;
if (this.booking.campground_site_type[i].campground_type === 0) {
resultList.push(this.booking.campground_site_type[i].name);
continue;
}
results[this.booking.campground_site_type[i].name] += 1;
if (typeCondensed[this.booking.campground_site_type[i].type] == undefined) {
typeCondensed[this.booking.campground_site_type[i].type] = 0;
}
typeCondensed[this.booking.campground_site_type[i].type] += 1;
}
var resultList = [];
for (var index in results) {
resultList.push(`${index}`);
for (var index in typeCondensed) {
var count = typeCondensed[index];
var site_type = index.split(':', 1)[0];
resultList.push(`${count}x ${site_type}`);
}
var resultString = resultList.join(", ");
return resultString;
Expand Down
17 changes: 13 additions & 4 deletions parkstay/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,20 @@ def create_confirmation(confirmation_buffer, booking):
table_data.append([Paragraph('Campground', styles['BoldLeft']), Paragraph('{}, {}'.format(booking.campground.name, booking.campground.park.name), styles['BoldLeft'])])

if booking.first_campsite_list:
campsite = ""
for item in booking.first_campsite_list:
campsite += ' {},'.format(item.name if item else "")
campsites = []
if booking.campground.site_type == 0:
for item in booking.first_campsite_list:
campsites.append(item.name if item else "" )
elif booking.campground.site_type == 1 or 2:
for item in booking.first_campsite_list:
campsites.append(item.type.split(':',1)[0] if item else "")
campsite = ', '.join(campsites)
result = {x:campsites.count(x) for x in campsites}
for key, value in result.items():
campsite = ', '.join(['%sx %s' % (value, key) for (key, value) in result.items()])



#campsite = u'{}'.format(booking.first_campsite_list) if booking.campground.site_type == 2 else u'{} ({})'.format(booking.first_campsite.name, booking.first_campsite.type)
table_data.append([Paragraph('Camp Site', styles['BoldLeft']), Paragraph(campsite, styles['Left'])])

table_data.append([Paragraph('Dates', styles['BoldLeft']), Paragraph(booking.stay_dates, styles['Left'])])
Expand Down
2 changes: 1 addition & 1 deletion parkstay/static/parkstay/js/parkstay.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions parkstay/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_available_campsitetypes(campground_id,start_date,end_date,_list=True):
available_campsiteclasses = []
else:
available_campsiteclasses = {}

for _class in cg.campsite_classes:
sites_qs = Campsite.objects.filter(
campground=campground_id,
Expand Down Expand Up @@ -402,7 +402,7 @@ def get_available_campsites_list(campsite_qs,request, start_date, end_date):
if ('booked' not in av):
if ('closed' not in av):
available.append(CampsiteSerialiser(Campsite.objects.filter(id = camp),many=True,context={'request':request}).data[0])

available.sort(key=lambda x: x['name'])
return available

def get_available_campsites_list_booking(campsite_qs,request, start_date, end_date,booking):
Expand Down

0 comments on commit 817d3fb

Please sign in to comment.