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