Fixed sorting for latest pastes
This commit is contained in:
parent
21aaad38cd
commit
4d80983eea
|
@ -12,14 +12,14 @@ from django.db import models
|
||||||
vertex_pattern = re.compile(r'vertex\s+([0-9.e+-]+)\s+([0-9.e+-]+)\s+([0-9.e+-]+)')
|
vertex_pattern = re.compile(r'vertex\s+([0-9.e+-]+)\s+([0-9.e+-]+)\s+([0-9.e+-]+)')
|
||||||
|
|
||||||
def safe_upload_path(base_dir):
|
def safe_upload_path(base_dir):
|
||||||
|
|
||||||
def generate_path(instance, filename):
|
def generate_path(instance, filename):
|
||||||
|
|
||||||
ext = os.path.splitext(filename)[1]
|
ext = os.path.splitext(filename)[1]
|
||||||
|
|
||||||
md5sum = md5()
|
md5sum = md5()
|
||||||
md5sum.update(instance.name
|
md5sum.update(instance.name
|
||||||
+ str(datetime.now())
|
+ str(datetime.now())
|
||||||
+ filename)
|
+ filename)
|
||||||
randomname = md5sum.hexdigest()
|
randomname = md5sum.hexdigest()
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ class Geometry(models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_latest(cls):
|
def get_latest(cls):
|
||||||
return cls.objects.all().filter(public = True).order_by('date')[:10]
|
return cls.objects.all().filter(public = True).order_by('-date')[:10]
|
||||||
|
|
||||||
def get_expiration_date(self):
|
def get_expiration_date(self):
|
||||||
for expiration in [self.HOUR, self.DAY, self.WEEK, self.MONTH]:
|
for expiration in [self.HOUR, self.DAY, self.WEEK, self.MONTH]:
|
||||||
|
@ -83,13 +83,13 @@ class Geometry(models.Model):
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
min_coord = [None,None,None]
|
min_coord = [None,None,None]
|
||||||
max_coord = [None,None,None]
|
max_coord = [None,None,None]
|
||||||
|
|
||||||
if self.file.read(5) != "solid":
|
if self.file.read(5) != "solid":
|
||||||
print "binary"
|
print "binary"
|
||||||
#Skip header
|
#Skip header
|
||||||
self.file.seek(80)
|
self.file.seek(80)
|
||||||
count = struct.unpack("i",self.file.read(4))[0]
|
count = struct.unpack("i",self.file.read(4))[0]
|
||||||
|
|
||||||
done = False
|
done = False
|
||||||
for pos in range(0,count):
|
for pos in range(0,count):
|
||||||
|
@ -97,24 +97,24 @@ class Geometry(models.Model):
|
||||||
self.file.seek(self.file.tell()+3*4)
|
self.file.seek(self.file.tell()+3*4)
|
||||||
#Loop over each coordinate
|
#Loop over each coordinate
|
||||||
for vert in range(0,3):
|
for vert in range(0,3):
|
||||||
# Loop over each coordinate
|
# Loop over each coordinate
|
||||||
for i in range(0,3):
|
for i in range(0,3):
|
||||||
x = struct.unpack("<f",self.file.read(4))[0]
|
x = struct.unpack("<f",self.file.read(4))[0]
|
||||||
|
|
||||||
if min_coord[i] != None :
|
if min_coord[i] != None :
|
||||||
min_coord[i] = min(min_coord[i], x)
|
min_coord[i] = min(min_coord[i], x)
|
||||||
else:
|
else:
|
||||||
min_coord[i] = x
|
min_coord[i] = x
|
||||||
|
|
||||||
if max_coord[i] != None :
|
if max_coord[i] != None :
|
||||||
max_coord[i] = max(max_coord[i], x)
|
max_coord[i] = max(max_coord[i], x)
|
||||||
else:
|
else:
|
||||||
max_coord[i] = x
|
max_coord[i] = x
|
||||||
#Skip attributes (16bit)
|
#Skip attributes (16bit)
|
||||||
self.file.seek(self.file.tell()+2)
|
self.file.seek(self.file.tell()+2)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print "ascii"
|
print "ascii"
|
||||||
|
|
||||||
line = self.file.readline()
|
line = self.file.readline()
|
||||||
while line != "":
|
while line != "":
|
||||||
|
@ -124,25 +124,25 @@ class Geometry(models.Model):
|
||||||
if line.startswith("vertex"):
|
if line.startswith("vertex"):
|
||||||
coords = vertex_pattern.match(line).groups();
|
coords = vertex_pattern.match(line).groups();
|
||||||
for i in range(0,3):
|
for i in range(0,3):
|
||||||
x = float(coords[i])
|
x = float(coords[i])
|
||||||
|
|
||||||
if min_coord[i] != None :
|
if min_coord[i] != None :
|
||||||
min_coord[i] = min(min_coord[i], x)
|
min_coord[i] = min(min_coord[i], x)
|
||||||
else:
|
else:
|
||||||
min_coord[i] = x
|
min_coord[i] = x
|
||||||
|
|
||||||
if max_coord[i] != None :
|
if max_coord[i] != None :
|
||||||
max_coord[i] = max(max_coord[i], x)
|
max_coord[i] = max(max_coord[i], x)
|
||||||
else:
|
else:
|
||||||
max_coord[i] = x
|
max_coord[i] = x
|
||||||
|
|
||||||
line = self.file.readline()
|
line = self.file.readline()
|
||||||
|
|
||||||
self.file.close()
|
self.file.close()
|
||||||
|
|
||||||
self.width = max_coord[0] - min_coord[0]
|
self.width = max_coord[0] - min_coord[0]
|
||||||
self.depth = max_coord[1] - min_coord[1]
|
self.depth = max_coord[1] - min_coord[1]
|
||||||
self.height = max_coord[2] - min_coord[2]
|
self.height = max_coord[2] - min_coord[2]
|
||||||
self.polycount = count
|
self.polycount = count
|
||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -166,5 +166,3 @@ class Geometry(models.Model):
|
||||||
if self.polycount == 0:
|
if self.polycount == 0:
|
||||||
self._generate_meta_infos()
|
self._generate_meta_infos()
|
||||||
return self.height
|
return self.height
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue