Skip to content

Commit 9289dde

Browse files
committed
bumped Django version to 3.2, fixed line filtering, fixed issue with text formatting. Had to remove footnotes
1 parent 0c07beb commit 9289dde

File tree

7 files changed

+83
-27
lines changed

7 files changed

+83
-27
lines changed

memorymap_toolkit/settings/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149

150150
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
151151

152+
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
152153

153154
### App-Specific Settings ###
154155

@@ -168,7 +169,7 @@
168169
['Image', 'Table', 'HorizontalRule', 'SpecialChar', 'Iframe'],
169170
['RemoveFormat', 'Source']
170171
]
171-
},
172+
}
172173
}
173174

174175
# Easy Thumbnails

mmt_api/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class DocumentSerializer(serializers.ModelSerializer):
4444
attachment_type = serializers.CharField(source='get_type', read_only=True)
4545
class Meta:
4646
model = Document
47-
fields = ('attachment_type', 'title', 'body_processed', 'order', 'slug')
47+
fields = ('attachment_type', 'title', 'body_processed', 'order', 'slug', 'body')
4848

4949
class ImageSerializer(serializers.ModelSerializer):
5050
attachment_type = serializers.CharField(source='get_type', read_only=True)

mmt_map/models.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@ class Document(AbstractAttachment):
191191
def save(self, *args, **kwargs):
192192
"""Sanitize html input from users and add footnotes"""
193193
# Clean the html
194-
self.body = bleach.clean(self.body, tags=['p', 'b', 'strong', 'em', 'img', 'a', 'blockquote', 'i', 'li', 'ul', 'ol', 'h2', 'h3', 'h4', 'br', 'hr', 'iframe'], attributes={'img': ['alt', 'src', 'style'], 'a': ['href', 'target'], 'iframe': ['width', 'height', 'src', 'allow', 'frameborder']}, styles=['width', 'height'])
195-
# Convert HTML to Markdown so you can run the footnote filter on it, then save as self.body_processed, which is what gets displayed on the site
196-
h = html2text.HTML2Text()
197-
h.ignore_images = False
198-
h.unicode_snob = True
199-
body_markdown = h.handle(self.body)
200-
self.body_processed = markdown.markdown(body_markdown, extensions=['markdown.extensions.footnotes'])
194+
self.body = bleach.clean(self.body, tags=['p', 'b', 'strong', 'em', 'img', 'a', 'blockquote', 'i', 'li', 'ul', 'ol', 'h2', 'h3', 'h4', 'br', 'hr', 'iframe', 'u'], attributes={'img': ['alt', 'src', 'style'], 'a': ['href', 'target'], 'iframe': ['width', 'height', 'src', 'allow', 'frameborder']}, styles=['width', 'height'])
195+
196+
## Todo: Footnotes filter -- disabled to enable bold and italics and underlines. Needs to be re-written and reactivated.
197+
198+
# Convert HTML to Markdown so you can run the footnote filter on it, then save as self.body_processed, which is what gets displayed on the site.
199+
#h = html2text.HTML2Text()
200+
#h.ignore_images = False
201+
#h.unicode_snob = True
202+
# body_markdown = h.handle(self.body)
203+
# self.body_processed = markdown.markdown(body_markdown, extensions=['markdown.extensions.footnotes'])
201204
super(Document, self).save(*args, **kwargs)
202205

203206

project_static/js/filters.js

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ $('.theme').click(function(e) {
1010
map.setFilter('points', ['==', ['get', 'theme_id'], key]);
1111
map.setFilter('points_labels', ['==', ['get', 'theme_id'], key]);
1212
map.setFilter('polygon_labels', ['==', ['get', 'theme_id'], key]);
13+
map.setFilter('lines', ['==', ['get', 'theme_id'], key]);
14+
map.setFilter('line_labels', ['==', ['get', 'theme_id'], key]);
1315

1416
$('.theme').each(function() {
1517
var color = $(this).data('color');
@@ -27,6 +29,8 @@ $('.theme').click(function(e) {
2729
map.setFilter('points');
2830
map.setFilter('points_labels');
2931
map.setFilter('polygon_labels');
32+
map.setFilter('lines');
33+
map.setFilter('line_labels');
3034
$('.theme').each(function() {
3135
let color = $(this).data('color');
3236
$(this).css('background-color', 'transparent');
@@ -46,11 +50,15 @@ $('.tag').click(function(e) {
4650
map.setFilter('points', ['in', tag, ['get', 'tag_str']]);
4751
map.setFilter('points_labels', tag, ['in', ['get', 'tag_str']]);
4852
map.setFilter('polygon_labels', ['in', tag, ['get', 'tag_str']]);
53+
map.setFilter('line_labels', ['in', tag, ['get', 'tag_str']]);
54+
map.setFilter('lines', ['in', tag, ['get', 'tag_str']]);
4955
} else {
5056
map.setFilter('polygons');
5157
map.setFilter('polygon_outlines');
5258
map.setFilter('points');
5359
map.setFilter('points_labels');
5460
map.setFilter('polygon_labels');
61+
map.setFilter('lines');
62+
map.setFilter('line_labels');
5563
}
5664
})

project_static/js/interactionHandler.js

+28-11
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ MmtMap.clickInteractions = {
5656
className: 'detail_popup'
5757
}),
5858

59-
pageHeaderHtmlTemplate: '<div class="feature_detail shadow col-12"><br /><button type="button" class="close close_feature" aria-label="Close"><span aria-hidden="true">&times;</span></button><div class="row"><div class="col-xs-12 col-sm-8 col-lg-6" style="margin: auto"><br /><img src="<%= banner %>" alt="Photo of <%= feature_name %>" class="feature_banner img-fluid" /><p class="small"><em><%= banner_copyright %></em></p><h2><%= feature_name %></h2><br /><article>',
59+
pageHeaderHtmlTemplate: '<div class="feature_detail shadow col-12"><br /><button type="button" class="close close_feature" aria-label="Close"><span aria-hidden="true">&times;</span></button><div class="row"><div class="col-xs-12 col-sm-8 col-lg-6" style="margin: auto"><br />',
60+
61+
headerTitleHmtlTemplate: '<article><h2><%= feature_name %></h2><br />',
62+
63+
headerImageHtmlTemplate: '<img src="<%= banner %>" alt="Photo of <%= feature_name %>" class="feature_banner img-fluid" /><p class="small"><em><%= banner_copyright %></em></p>',
6064

6165
documentHtmlTemplate: '<%= document_body %><hr /><br />',
6266

@@ -77,7 +81,7 @@ MmtMap.clickInteractions = {
7781
}
7882
};
7983

80-
let url = '/api/1.0/features/' + sourceLayer + '/' + id + '/attachments/';
84+
const url = '/api/1.0/features/' + sourceLayer + '/' + id + '/attachments/';
8185

8286
// Then get the data for the page and display it as an overlay to the map
8387
$.get(url, function(data) {
@@ -88,13 +92,28 @@ MmtMap.clickInteractions = {
8892

8993
// Once you have the data, compile the HTML fragments
9094

91-
var pageHeader = _.template(MmtMap.clickInteractions.pageHeaderHtmlTemplate);
95+
const pageHeader = _.template(MmtMap.clickInteractions.pageHeaderHtmlTemplate);
96+
const pageTitle = _.template(MmtMap.clickInteractions.headerTitleHmtlTemplate);
9297

93-
page = pageHeader({
94-
banner: data.properties.banner_image,
95-
feature_name: data.properties.name,
96-
banner_copyright: data.properties.banner_image_copyright
97-
});
98+
let page = pageHeader();
99+
100+
if (data.properties.banner_image) {
101+
102+
const headerImgTemplate = _.template(MmtMap.clickInteractions.headerImageHtmlTemplate);
103+
const headerImg = headerImgTemplate({
104+
banner: data.properties.banner_image,
105+
banner_copyright: data.properties.banner_image_copyright,
106+
feature_name: data.properties.name
107+
})
108+
109+
page = page + headerImg;
110+
}
111+
112+
let title = pageTitle({
113+
feature_name: data.properties.name
114+
});
115+
116+
page = page + title;
98117

99118
if (data.properties.popup_audio_file != null) {
100119
var popupAudio = _.template(MmtMap.clickInteractions.audioFileHtmlTemplate);
@@ -115,7 +134,7 @@ MmtMap.clickInteractions = {
115134
case 'document':
116135
var doc = _.template(MmtMap.clickInteractions.documentHtmlTemplate);
117136
doc = doc({
118-
document_body: attachment.body_processed
137+
document_body: attachment.body
119138
});
120139
page = page + doc;
121140
break;
@@ -222,8 +241,6 @@ MmtMap.clickInteractions = {
222241
clickFeature: function(source, sourceLayer, feature, id, coords) {
223242
// Loads the feature from the server and adds a large click popup with an audio player (if there is an audio file related to it)
224243

225-
226-
227244
$.get('api/1.0/features/' + sourceLayer + '/' + id, function(data) {
228245
// Construct the HTML for the popup and add it to the map
229246
let popupPlayerId = undefined;

requirements.txt

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
asgiref==3.2.10
1+
asgiref==3.6.0
22
bleach==3.3.0
33
certifi==2022.12.7
44
chardet==3.0.4
55
charset-normalizer==2.1.1
66
coreapi==2.3.3
77
coreschema==0.0.4
88
coverage==5.1
9-
Django==3.1.13
9+
cssselect2==0.7.0
10+
Django==3.2.18
1011
django-analytical==2.6.0
11-
django-ckeditor==5.9.0
12+
django-ckeditor==6.5.1
1213
django-colorful==1.3
13-
django-constance==2.6.0
14+
django-constance==2.9.0
1415
django-debug-toolbar==2.2.1
15-
django-filer==2.0.2
16+
django-filer==2.1
1617
django-filter==2.2.0
17-
django-js-asset==1.2.2
18+
django-js-asset==2.0.0
1819
django-mptt==0.11.0
1920
django-picklefield==3.0.1
2021
django-polymorphic==3.0.0
2122
django-taggit==1.3.0
2223
djangorestframework==3.11.2
2324
djangorestframework-gis==0.15
24-
easy-thumbnails==2.7
25+
easy-thumbnails==2.8.5
2526
html2text==2020.1.16
2627
idna==2.9
2728
itypes==1.2.0
2829
Jinja2==2.11.3
30+
lxml==4.9.2
2931
Markdown==3.2.2
3032
MarkupSafe==1.1.1
3133
packaging==20.4
@@ -34,9 +36,12 @@ psycopg2==2.8.5
3436
pyparsing==2.4.7
3537
python-memcached==1.59
3638
pytz==2020.1
39+
reportlab==3.6.12
3740
requests==2.28.1
3841
six==1.15.0
3942
sqlparse==0.3.1
43+
svglib==1.5.1
44+
tinycss2==1.2.1
4045
Unidecode==1.1.1
4146
Unipath==1.1
4247
uritemplate==3.0.1

templates/mmt_map/forms/widgets/mapboxgl_widget.html

+22
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@
160160
},
161161
'filter': ['!=', ['get', 'name'], name]
162162
});
163+
164+
map.addLayer({
165+
'id': 'lines',
166+
'source': 'interactive',
167+
'source-layer': 'lines',
168+
'type': 'line',
169+
'paint': {
170+
'line-color': '#c1c1c1',
171+
'line-width': ["interpolate", ["linear"], ["zoom"],
172+
14, 1,
173+
19, 4
174+
],
175+
'line-opacity': ["interpolate", ["linear"], ["zoom"],
176+
14, 0.3,
177+
19, 1
178+
]
179+
},
180+
'layout': {
181+
'line-cap': 'round'
182+
},
183+
'filter': ['!=', ['get', 'name'], name]
184+
});
163185

164186
});
165187

0 commit comments

Comments
 (0)