parent
9f7cd2b75f
commit
11f82fae11
|
@ -32,7 +32,7 @@ ALLOWED_HOSTS = []
|
|||
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
||||
# although not all choices may be available on all operating systems.
|
||||
# In a Windows environment this must be set to your system time zone.
|
||||
TIME_ZONE = 'America/Chicago'
|
||||
TIME_ZONE = 'Europe/Berlin'
|
||||
|
||||
# Language code for this installation. All choices can be found here:
|
||||
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||
|
|
|
@ -6,4 +6,4 @@ from models import Geometry
|
|||
class GeometryForm(ModelForm):
|
||||
class Meta:
|
||||
model = Geometry
|
||||
fields = ['name', 'description', 'file', 'sourcefile']
|
||||
fields = ['name', 'description', 'public', 'expiration', 'file', 'sourcefile']
|
|
@ -0,0 +1,22 @@
|
|||
from datetime import datetime
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils.timezone import utc
|
||||
|
||||
from pastebin.models import Geometry
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
args = ''
|
||||
help = 'Remove expired pastes and their files.'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
for expiration in [Geometry.HOUR, Geometry.DAY, Geometry.WEEK, Geometry.MONTH]:
|
||||
expiration_time = datetime.utcnow().replace(tzinfo=utc) - Geometry.DELTAS[expiration]
|
||||
for geometry in Geometry.objects.all().filter(expiration = expiration, date__lte = expiration_time):
|
||||
self.stdout.write("Expiring geometry: %s" % geometry.name)
|
||||
geometry.file.delete()
|
||||
if geometry.sourcefile :
|
||||
geometry.sourcefile.delete()
|
||||
geometry.delete()
|
||||
self.stdout.write("done")
|
|
@ -3,7 +3,7 @@ import struct
|
|||
import re
|
||||
|
||||
from hashlib import md5
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
@ -29,10 +29,30 @@ def safe_upload_path(base_dir):
|
|||
|
||||
|
||||
class Geometry(models.Model):
|
||||
|
||||
HOUR = 0
|
||||
DAY = 1
|
||||
WEEK = 2
|
||||
MONTH = 3
|
||||
FORERVER = 4
|
||||
|
||||
EXPIRATION_CHOICES = ((HOUR, 'one hour'),
|
||||
(DAY, 'one day'),
|
||||
(WEEK, 'one week'),
|
||||
(MONTH, 'one month'),
|
||||
(FORERVER, 'forever'))
|
||||
|
||||
DELTAS = { HOUR : timedelta(hours = 1),
|
||||
DAY : timedelta(days = 1),
|
||||
WEEK : timedelta(weeks = 1),
|
||||
MONTH : timedelta(weeks = 4)}
|
||||
|
||||
name = models.CharField(max_length = 128)
|
||||
description = models.TextField(blank=True)
|
||||
user = models.ForeignKey(User, blank=True, null=True)
|
||||
date = models.DateTimeField(auto_now_add=True)
|
||||
expiration = models.IntegerField(default = 0, choices = EXPIRATION_CHOICES)
|
||||
public = models.BooleanField(default=True)
|
||||
polycount = models.IntegerField(blank=True, default=0)
|
||||
width = models.FloatField(blank=True, default=0)
|
||||
depth = models.FloatField(blank=True, default=0)
|
||||
|
@ -40,6 +60,14 @@ class Geometry(models.Model):
|
|||
file = models.FileField(upload_to=safe_upload_path('models'))
|
||||
sourcefile = models.FileField(upload_to=safe_upload_path('sources'), blank=True)
|
||||
|
||||
def get_expiration_date(self):
|
||||
for expiration in [self.HOUR, self.DAY, self.WEEK, self.MONTH]:
|
||||
if self.expiration == expiration:
|
||||
return self.date + self.DELTAS[expiration]
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def _generate_meta_infos(self):
|
||||
print "Generating metainfos %s" % self.name
|
||||
|
||||
|
@ -109,6 +137,8 @@ class Geometry(models.Model):
|
|||
self.height = max_coord[2] - min_coord[2]
|
||||
self.polycount = count
|
||||
|
||||
self.save()
|
||||
|
||||
def get_polycount(self):
|
||||
if self.polycount == 0:
|
||||
self._generate_meta_infos()
|
||||
|
|
|
@ -105,6 +105,16 @@
|
|||
{{ geometry.date}}<br/>
|
||||
</div>
|
||||
</div>
|
||||
{% if geometry.get_expiration_date %}
|
||||
<div class="pure-g-r">
|
||||
<div class="pure-u-1-3">
|
||||
<i class="icon-trash"></i> <b>expires:</b>
|
||||
</div>
|
||||
<div class="pure-u-2-3">
|
||||
{{ geometry.get_expiration_date|timeuntil}}<br/>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="pure-g-r">
|
||||
<div class="pure-u-1-3">
|
||||
<i class="icon-user"> </i><b>by:</b>
|
||||
|
|
|
@ -19,7 +19,6 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$(".browsebutton").click(function() {
|
||||
console.log("foo");
|
||||
$(this).prev().prev().click();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue