newmediamonitoring/polls/views/download.py

30 lines
968 B
Python
Raw Normal View History

2020-10-27 10:24:47 +00:00
import os
from django.conf import settings
from django.http import Http404, HttpResponse, JsonResponse
from django.shortcuts import render
from polls.models import AppVersion
def app_intro(request):
return render(request, 'polls/app.html')
def download(request):
2020-10-27 13:02:08 +00:00
app = AppVersion.objects.first()
2020-10-27 10:24:47 +00:00
filename = 'app-%s.apk' % (app.version,)
file_path = os.path.join(settings.MEDIA_ROOT, filename)
if os.path.exists(file_path):
with open(file_path, 'rb') as fh:
response = HttpResponse(
fh.read(), content_type="application/vnd.android.package-archive")
response['Content-Disposition'] = 'inline; filename=' + \
os.path.basename(file_path)
return response
raise Http404
def has_update(request):
version = request.GET.get('version', '1')
2020-10-27 13:02:08 +00:00
last = AppVersion.objects.first()
2020-10-27 13:34:46 +00:00
return JsonResponse({'status': 'success', 'message': str(last.version) != version})