Package expedient :: Package clearinghouse :: Package resources :: Module models
[hide private]
[frames] | no frames]

Source Code for Module expedient.clearinghouse.resources.models

 1  ''' 
 2  @author: jnaous 
 3  ''' 
 4  from django.db import models 
 5  from expedient.clearinghouse.aggregate.models import Aggregate 
 6  from expedient.common.extendable.models import Extendable 
 7  from expedient.clearinghouse.slice.models import Slice 
 8  from datetime import datetime 
 9   
10 -class Resource(Extendable):
11 ''' 12 Generic model of a resource. 13 14 @ivar name: A human-readable name for the resource 15 @type name: L{str} 16 @ivar available: Is the resources available? 17 @type available: C{bool} 18 @ivar status_change_timestamp: The time when C{available} changed. 19 @type status_change_timestamp: L{datetime.datetime} 20 @ivar aggregate: The L{Aggregate} that controls/owns this resource 21 @type aggregate: L{models.ForeignKey} to L{Aggregate} 22 @ivar slice_set: The set of slices this resource is in 23 @type slice_set: a L{models.ManyToManyField} to L{Slice}. 24 ''' 25 26 name = models.CharField(max_length=200) 27 available = models.BooleanField("Available", default=True, editable=False) 28 status_change_timestamp = models.DateTimeField( 29 editable=False, auto_now_add=True) 30 aggregate = models.ForeignKey( 31 Aggregate, verbose_name="Aggregate the resource belongs to") 32 slice_set = models.ManyToManyField( 33 Slice, through="Sliver", verbose_name="Slices this resource is used in") 34
35 - def update_timestamp(self):
36 """Set the resource's status change timestamp to now. 37 38 This method does not save the object, so the object still 39 needs to be manually saved. 40 """ 41 self.status_change_timestamp = datetime.now()
42
43 - def __unicode__(self):
44 return u"Resource %s belonging to aggregate %s." % ( 45 self.name, self.aggregate.name)
46
47 -class Sliver(Extendable):
48 ''' 49 Information on the reservation of a particular resource for a slice. 50 51 @ivar resource: The resource the sliver is part of. 52 @type resource: L{Resource} 53 @ivar slice: The slice the slice is part of. 54 @type slice: L{Slice} 55 ''' 56 57 resource = models.ForeignKey( 58 Resource, verbose_name="Resource this sliver is part of") 59 slice = models.ForeignKey( 60 Slice, verbose_name="Slice this sliver is part of")
61