newmediamonitoring1/polls/views/download.py

30 lines
968 B
Python

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):
app = AppVersion.objects.first()
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')
last = AppVersion.objects.first()
return JsonResponse({'status': 'success', 'message': str(last.version) != version})