Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit 5d8b41f

Browse files
committed
Merge pull request #390 from gandalfar/api-improvements
truncate event description in API, make more link in marker a button
2 parents 153a0d4 + 9850350 commit 5d8b41f

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

api/serializers.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
from django.utils.text import Truncator
12
from rest_framework import serializers
23

34
from api.models.events import Event
45

56
class EventListSerializers(serializers.ModelSerializer):
7+
description_short = serializers.CharField(source='description')
8+
69
class Meta:
710
model = Event
8-
fields = ('geoposition', 'title', 'id' , 'slug', 'description', 'picture')
11+
fields = ('geoposition', 'title', 'id' , 'slug', 'description_short', 'picture')
12+
13+
def transform_description_short(self, obj, value):
14+
return Truncator(value).chars(160)

static/js/index.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,16 @@ var Codeweek = window.Codeweek || {};
4343

4444
var infoWindowContent = '',
4545
buble_content = '',
46-
image = '',
47-
description = '';
46+
image = '';
4847

4948
if (marker.image !== "") {
5049
image += '<img src="' + Codeweek.Index.media_url + marker.image + '" class="img-polaroid marker-buble-img">';
5150
}
5251

53-
if (marker.description.length > 150) {
54-
description = marker.description.substring(0, 150) + '... ';
55-
} else {
56-
description = marker.description;
57-
}
58-
5952
buble_content = '<div><h4><a href="' + marker.url + '" class="map-marker">' + marker.title + '</a></h4><div>' +
6053
image +
61-
'<p style="overflow:hidden;">' + description +
62-
'&nbsp;<a href="' + marker.url + '" class="map-marker"><span>More...</span></a></p>';
54+
'<p style="overflow:hidden;">' + marker.description +
55+
'&nbsp;<a class="btn btn-sm" href="' + marker.url + '" class="map-marker"><span>More...</span></a></p>';
6356

6457
placeinfowindow.setContent(buble_content);
6558
placeinfowindow.open(map, marker);
@@ -75,7 +68,7 @@ var Codeweek = window.Codeweek || {};
7568
map_event_id = events[i].id,
7669
map_event_slug = events[i].slug,
7770
markUrl = "/view/" + map_event_id + "/" + map_event_slug,
78-
markDesc = events[i].description,
71+
markDesc = events[i].description_short,
7972
markImg = events[i].picture;
8073

8174
markers[map_event_id] = createMarker(markTitle, markLat, markLng, markUrl, markDesc, markImg);

0 commit comments

Comments
 (0)