diff --git a/polls/models.py b/polls/models.py index ee242eb..6cac1ef 100644 --- a/polls/models.py +++ b/polls/models.py @@ -45,7 +45,8 @@ class Notice(models.Model): type = models.IntegerField( 'category', choices=NOTICE_TYPE_CHOICES, default=0) content = models.CharField('内容', max_length=256, null=False) - group_id = models.CharField('group_id', max_length=256, null=True, blank=True) + group_id = models.CharField( + 'group_id', max_length=256, null=True, blank=True) app = models.CharField('app', max_length=256, null=True, blank=True) model = models.CharField('model', max_length=256, null=True, blank=True) field = models.CharField('field', max_length=256, null=True, blank=True) @@ -112,7 +113,6 @@ class Task(models.Model): Message.objects.create( type=1, send_from_id=user_id, send_to_id=group.id, task=self, page_title=title, page_description=description, page_image=image, url=url) - class Meta: ordering = ["-added"] @@ -206,3 +206,10 @@ class GroupRecord(models.Model): leave_at = models.DateTimeField(auto_now=True) added = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) + + +class AppVersion(models.Model): + id = models.UUIDField('id', primary_key=True, default=uuid.uuid4) + version = models.IntegerField('version', default=1) + added = models.DateTimeField(auto_now_add=True) + updated = models.DateTimeField(auto_now=True) \ No newline at end of file diff --git a/polls/views/__init__.py b/polls/views/__init__.py index fe7304a..6879918 100644 --- a/polls/views/__init__.py +++ b/polls/views/__init__.py @@ -8,4 +8,4 @@ from .group import groups, room, is_level1_or_leve2, group_member, group_manager from .compartment import compartments from .organizations import organizations, organization_level from .message import last_messages, send_text_message, is_read_message, read_message -from .download import download, app_intro +from .app import download, app_intro diff --git a/polls/views/app.py b/polls/views/app.py new file mode 100644 index 0000000..ee58de1 --- /dev/null +++ b/polls/views/app.py @@ -0,0 +1,29 @@ +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.last('version') + 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.last('version') + return JsonResponse({'status': 'success', 'message': last != version}) diff --git a/polls/views/download.py b/polls/views/download.py deleted file mode 100644 index 0ccf0b3..0000000 --- a/polls/views/download.py +++ /dev/null @@ -1,17 +0,0 @@ -import os -from django.conf import settings -from django.http import HttpResponse, Http404 -from django.shortcuts import render - -def app_intro(request): - return render(request, 'polls/app.html') - - -def download(request): - file_path = os.path.join(settings.MEDIA_ROOT, 'pom.apk') - 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 \ No newline at end of file