...
 
Commits (9)
......@@ -98,6 +98,7 @@ urlpatterns = [
path('about', views.section_home, {'slug': 'about'}, name='about'),
path('community', views.section_home, {'slug': 'community'}, name='community_home'),
path('resources', views.section_home, {'slug': 'resources'}, name='resources_home'),
path('resources/', views.section_home, {'slug': 'resources'}, name='resources_home'),
path('news_events', views.news_and_events, name='news_and_events'),
path('page/<slug:slug>', views.page, name='page'),
......
......@@ -54,8 +54,12 @@ def video(request, id):
info = get_object_or_404(Video, pk=id)
editlink = ""+str(id) + "/change/"
editlink = reverse("core:admin_video", args=[id])
download = False
download_videos = [34,35,37,38,39,40,41,42,43]
if id in download_videos:
download = True
context = { "section": "resources", "page": "video", "info": info, "editlink": editlink }
context = { "section": "resources", "page": "video", "info": info, "editlink": editlink, "download": download }
return render(request, "core/video.html", context)
def search(request):
......
......@@ -522,7 +522,11 @@ def download_csv(request, city, id):
contents = open(file_path, 'r')
date = str(file.created_at.year) + '-' + str(file.created_at.month) + '-' + str(file.created_at.day)
response = HttpResponse(contents, content_type="text/csv")
response['Content-Disposition'] = 'attachment; filename="'+file.dataset.name+'-'+date+'.csv"'
if file.dataset:
name = file.dataset.name
else:
name = 'download'
response['Content-Disposition'] = 'attachment; filename="'+name+'-'+date+'.csv"'
return response
@login_required
......@@ -780,7 +784,7 @@ def upload_flow_review(request, city, type, id, update=None):
if len(row) != column_count and len(row) > 0:
error = "File format invalid. The number of columns in the files is not correct. We expect " + str(column_count) + " columns but the file had " + str(len(row))
elif not error and len(row) > 0:
if row[0].strip() != "Timeframe" and row[0] and row[0].strip() != "Timeframe name" and row[0].strip() != "Date" :
if row[0].strip().lower() != "timeframe" and row[0] and row[0].strip().lower() != "timeframe name" and row[0].strip().lower() != "date" :
if dataset.name == "Population":
material = "People"
......@@ -848,9 +852,9 @@ def upload_flow_review(request, city, type, id, update=None):
elif destination == info.name:
destination_info = info
else:
destination_info = ReferenceSpace.objects.filter(active=True, city=info,name=destination)
destination_info = ReferenceSpace.objects.filter(active=True, city=info,name__iexact=destination)
if not destination_info:
destination_info = ReferenceSpace.objects.filter(active=True, name=destination)
destination_info = ReferenceSpace.objects.filter(active=True, name__iexact=destination)
if destination_info:
# We only want a single result, so slice this
destination_info = destination_info[0]
......@@ -870,9 +874,9 @@ def upload_flow_review(request, city, type, id, update=None):
elif origin == info.name:
origin_info = info
else:
origin_info = ReferenceSpace.objects.filter(active=True, city=info,name=origin)
origin_info = ReferenceSpace.objects.filter(active=True, city=info,name__iexact=origin)
if not origin_info:
origin_info = ReferenceSpace.objects.filter(active=True, name=origin)
origin_info = ReferenceSpace.objects.filter(active=True, name__iexact=origin)
if origin_info:
origin_info = origin_info[0]
else:
......@@ -1105,7 +1109,7 @@ def upload_flow_meta(request, city, type, id):
with open(path) as f:
reader = csv.reader(f)
for row in reader:
if len(row) > 0 and row[0].strip() != "Timeframe" and row[0] and row[0].strip() != "Timeframe name" and row[0].strip() != "Date":
if len(row) > 0 and row[0].strip().lower() != "timeframe" and row[0] and row[0].strip().lower() != "timeframe name" and row[0].strip().lower() != "date":
if dataset.name == "Population":
material = "People"
......@@ -1209,7 +1213,7 @@ def upload_flow_meta(request, city, type, id):
if destination in referencespacelist:
destination_info = referencespacelist[destination]
else:
destination_info = ReferenceSpace.objects.filter(active=True, name=destination)
destination_info = ReferenceSpace.objects.filter(active=True, name__iexact=destination)
if destination_info:
# We only want a single result, so slice this
destination_info = destination_info[0]
......@@ -1236,7 +1240,7 @@ def upload_flow_meta(request, city, type, id):
if origin in referencespacelist:
origin_info = referencespacelist[origin]
else:
origin_info = ReferenceSpace.objects.filter(active=True, name=origin)
origin_info = ReferenceSpace.objects.filter(active=True, name__iexact=origin)
if origin_info:
origin_info = origin_info[0]
else:
......@@ -1391,7 +1395,7 @@ def upload_mtu_review(request, city, filename):
log = UserLog.objects.create(user=request.user, action=import_data, space=info, points=10, model="MTU geojson", description="File: " + filename)
type = ReferenceSpaceType.objects.filter(name=request.POST['mtu_name'])
type = ReferenceSpaceType.objects.filter(name__iexact=request.POST['mtu_name'])
if type:
type = type[0]
else:
......@@ -1399,9 +1403,9 @@ def upload_mtu_review(request, city, filename):
if type:
type = type[0]
else:
type = ReferenceSpaceType.objects.create(name=request.POST['mtu_name'], slug=slugify(request.POST['mtu_name']), type='SOC', marker_color=None, user_accessible=False)
type = ReferenceSpaceType.objects.create(name__iexact=request.POST['mtu_name'], slug=slugify(request.POST['mtu_name']), type='SOC', marker_color=None, user_accessible=False)
mtu = MTU.objects.create(type=type, space=info, timeframe=request.POST['timeframe'], source=request.POST['source'], file=filename, description=request.POST['details'])
mtu = MTU.objects.create(type=type, space=info, timeframe=request.POST['start'], source=request.POST['source'], file=filename, description=request.POST['details'])
for record in data['features']:
properties = record['properties']
......@@ -1414,7 +1418,15 @@ def upload_mtu_review(request, city, filename):
area = float(properties[request.POST['area']])/float(request.POST['unit'])
space = ReferenceSpace.objects.create(name=name, type=type, city=info, country=info.country, slug=slugify(name), mtu=mtu)
location = ReferenceSpaceLocation.objects.create(space=space, area=area, timeframe=request.POST['timeframe'], source=request.POST['source'], geojson=geometry)
if 'start' in request.POST and request.POST['start']:
start = request.POST['start']
else:
start = None
if 'end' in request.POST and request.POST['end']:
end = request.POST['end']
else:
end = None
location = ReferenceSpaceLocation.objects.create(space=space, area=area, start=start, end=end, source=request.POST['source'], geojson=geometry)
space.location = location
space.save()
......
......@@ -27,6 +27,11 @@
{% endif %}
{{ info.description|safe }}
{% if download %}
<p class="pad-top">
<a href="/media/videos/{{ info.id }}.mp4" target="_blank" class="btn btn-success">Download this video</a>
</p>
{% endif %}
<p class="pad-top">
{% if info.primary_space %}
<a href="{% url 'multiplicity:space' info.primary_space.city.slug info.primary_space.type.slug info.primary_space.slug %}" class="btn btn-info">Related: {{ info.primary_space.name }}</a>
......
......@@ -112,7 +112,10 @@
{% for details in csv %}
<tr>
<td data-sort="{{ details.created_at|date:"Y-m-d H:i" }}">{{ details.created_at }}</td>
<td><a href="{% url 'multiplicity:upload_flow_review' info.slug details.datasettype.id details.id %}">{{ details.original_name }}</a></td>
<td>
<a href="{% url 'multiplicity:download_csv' info.slug details.id %}"><i class="fa fa-download"></i></a>
<a href="{% url 'multiplicity:upload_flow_review' info.slug details.datasettype.id details.id %}">{{ details.original_name }}</a>
</td>
<td><a href="{% url 'core:userdetails' details.user.id %}">{{ details.user.first_name }} {{ details.user.last_name }}</a></td>
<td>
{% if details.dataset %}
......
......@@ -122,9 +122,16 @@
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Timeframe</label>
<label class="col-sm-2 control-label">Start date</label>
<div class="col-sm-10">
<input class="form-control" type="text" required name="timeframe" placeholder="Since when are these boundaries in place? E.g. 2008-present." />
<input class="form-control" type="date" name="start" placeholder="Since when are these boundaries in place?" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">End date</label>
<div class="col-sm-10">
<input class="form-control" type="date" name="end" placeholder="What was the end date of these boundaries? Leave blank if still active." />
</div>
</div>
......