Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django>=1.7 #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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',
},
),
]
Empty file added migrations/__init__.py
Empty file.
9 changes: 6 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion sendfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
from django.http import HttpResponse, Http404
from django.utils.http import urlquote
import os
Expand All @@ -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+)?")

Expand Down
2 changes: 1 addition & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down