diff --git a/migrations/0001_initial.py b/migrations/0001_initial.py new file mode 100644 index 0000000..b98e2e0 --- /dev/null +++ b/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-06-09 01:52 +from __future__ import unicode_literals + +from django.db import migrations, models +import lasana.models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Meal', + fields=[ + ('id', models.CharField(db_index=True, max_length=4, primary_key=True, serialize=False)), + ('file', models.FileField(storage=lasana.models.MealStorage(), upload_to='/tmp/', verbose_name='File')), + ('expiration_time', models.DateTimeField(db_index=True, verbose_name='Expiration time')), + ], + options={ + 'ordering': ['expiration_time'], + 'verbose_name': 'Meal', + }, + ), + ] diff --git a/migrations/__init__.py b/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/models.py b/models.py index f42b0f5..a94eb74 100644 --- a/models.py +++ b/models.py @@ -11,16 +11,19 @@ import string import random + class MealStorage(FileSystemStorage): def url(self, name): return Meal.objects.get(file=name).get_absolute_url() -MEAL_ALPHABET = list(set(string.ascii_uppercase + string.digits) - {'I','1','O','0'}) +MEAL_ALPHABET = list(set(string.ascii_uppercase + string.digits) - {'I', '1', 'O', '0'}) safe_random = random.SystemRandom() -def get_random_string(length): - return ''.join(safe_random.choice(MEAL_ALPHABET) for x in range(4)) + +def get_random_string(length=4): + return ''.join(safe_random.choice(MEAL_ALPHABET) for x in range(length)) + class Meal(Model): id_length = 4 diff --git a/sendfile.py b/sendfile.py index b033aaf..3d6eef2 100644 --- a/sendfile.py +++ b/sendfile.py @@ -1,3 +1,4 @@ +import django from django.http import HttpResponse, Http404 from django.utils.http import urlquote import os @@ -7,7 +8,10 @@ from . settings import LASANA_USE_X_SENDFILE, LASANA_NGINX_ACCEL_REDIRECT_BASE_URL #For no-XSendfile approach -from django.core.servers.basehttp import FileWrapper +if django.VERSION >= (1, 9): + from wsgiref.util import FileWrapper +else: + from django.core.servers.basehttp import FileWrapper CONTENT_RANGE_REGEXP = re.compile(r"bytes=(\d+)?-(\d+)?") diff --git a/views.py b/views.py index 925b023..7b8011c 100644 --- a/views.py +++ b/views.py @@ -7,7 +7,7 @@ from . sendfile import send from . import styles from . settings import LASANA_ALLOW_CHANGE_STYLE, LASANA_BLOCK_CRAWLERS -import idn +from . import idn from django.shortcuts import render from django.http import HttpResponse, HttpResponseRedirect, \