source: subversion/sites/other/tilesAtHome_tahngo/requests/models.py

Last change on this file was 11374, checked in by spaetz, 12 years ago

includ z,x,y in the upload. fire autorequester every 4h

File size: 3.2 KB
Line 
1from datetime import datetime
2from django.db import models
3from django.contrib.auth.models import User
4from tah.tah_intern.models import Layer
5from tah.requests.manager import RequestManager, UploadManager
6#-----------------------------------------------------
7class Request(models.Model):
8  # x,y are the coordinates of the request tileset
9  x = models.PositiveSmallIntegerField()
10  y = models.PositiveSmallIntegerField()
11
12  # render tiles from zoom level min_z through max_z
13  min_z = models.PositiveSmallIntegerField(default=12)
14  max_z = models.PositiveSmallIntegerField(default=17)
15
16  # list of layers we should render
17  layers = models.ManyToManyField(Layer,null=True)
18
19  #status: 0=unhandled, 1=Handed out, 2=Finished
20  status = models.PositiveSmallIntegerField(default=0)
21
22  # priority: 1=urgent 3=slow bulk
23  priority = models.PositiveSmallIntegerField(default=3)
24
25  # ipaddress, request time, and freeform "src" string of the requester
26  ipaddress = models.IPAddressField(blank=True,default="")
27  request_time = models.DateTimeField(blank=True, default=datetime.today)
28  src  = models.CharField(max_length=64, blank=True, default='unknown')
29
30  # renderer/user (=client), client_uuid, and time of last client contact.
31  #clientping contains the last "I am still working on it" when active, on upload it indicates the upload time
32  clientping_time = models.DateTimeField(blank=True,default=datetime.today())
33  client = models.ForeignKey(User,blank=True,null=True)
34  client_uuid = models.PositiveIntegerField(blank=True, default=0)
35  #---- end of model definition ----
36
37  # use RequestManager that allows to e.g. select a request "FOR UPDATE"
38  objects = RequestManager()
39
40  def __str__(self):
41    # take protocol v5
42    return "%s|%s|%s|%s" % (self.x,self.y,self.min_z,self.layers_str)
43    # take protocol v6
44    return "%d|%d|%d|%d|%s" % (self.x,self.y,self.min_z,self.priority,self.layers_str)
45
46  @property
47  def layers_str(self):
48    return  ','.join([a['name'] for a in self.layers.values()])
49
50  @property
51  def status_str(self):
52    return  ['unhandled','active','finished'][self.status]
53
54
55#-----------------------------------------------------
56class Upload(models.Model):
57  file = models.FileField(upload_to='Incoming')
58  layer = models.ForeignKey(Layer,blank=True,null=True)
59  z = models.PositiveSmallIntegerField(blank=True,null=True)
60  x = models.PositiveSmallIntegerField(blank=True,null=True)
61  y = models.PositiveSmallIntegerField(blank=True,null=True)
62  ipaddress = models.IPAddressField(blank=True,default="")
63  user_id = models.ForeignKey(User)
64  client_uuid = models.PositiveSmallIntegerField(blank=True, default=0)
65  #clientping contains the upload it indicates the upload time
66  upload_time = models.DateTimeField(auto_now_add=True)
67  # priority: 1=urgent 3=slow bulk
68  priority = models.PositiveSmallIntegerField(blank=True,default=3)
69  # if we need to do multi-threaded processing this shows locked uploads
70  is_locked = models.BooleanField(blank=True,default=False)
71
72  ########  end of model definition #######
73
74  # use UploadManager that allows to e.g. select a request "FOR UPDATE"
75  objects = UploadManager()
76
77  def __str__(self):
78    return str(self.layer)+","+str(self.file)
79
80  class Meta:
81    ordering = ['upload_time']
Note: See TracBrowser for help on using the repository browser.