witten
/
luminotes
Archived
1
0
Fork 0

Added a new group_storage_bytes member to model.User and some SQL to calculate it.

This commit is contained in:
Dan Helfman 2008-06-04 19:46:08 -07:00
parent 08dc744403
commit f8efc2f178
3 changed files with 48 additions and 2 deletions

5
NEWS
View File

@ -1,9 +1,12 @@
1.4.0: ??
* Implemented some basic user administration features.
* Implemented some basic user administration features, allowing you to create
Luminotes users yourself.
* Added new rate plans with support for user administration.
* Wrote a tool for manually updating a user's rate plan: tools/set_plan.py
* Refactored some of the client-side form-handling code to cut down on
special-case hacks.
* NOTE: After upgrading to this release, you must restart memcached to clear
the cache. Failing to do so will cause errors with the User object.
1.3.40: May 27, 2008
* Added some minor product page tweaks like meta description tags.

View File

@ -41,6 +41,7 @@ class User( Persistent ):
self.__password_hash = password_hash
self.__email_address = email_address
self.__storage_bytes = storage_bytes or 0
self.__group_storage_bytes = 0
self.__rate_plan = rate_plan or 0
@staticmethod
@ -323,11 +324,37 @@ class User( Persistent ):
) as file_storage;
""" % ( quote( self.object_id ), quote( self.object_id ) )
def sql_calculate_group_storage( self ):
"""
Return a SQL string to calculate the total bytes of storage usage for all groups that this user
is a member of. This includes the cumulative storage of all users in these groups.
"""
return \
"""
select
coalesce( sum( storage_bytes ), 0 )
from
user_group, luminotes_user_current
where
group_id in (
select
group_id
from
user_group
where
user_id = %s
) and
user_id = luminotes_user_current.id
group by
user_id, storage_bytes;
""" % quote( self.object_id )
def to_dict( self ):
d = Persistent.to_dict( self )
d.update( dict(
username = self.username,
storage_bytes = self.__storage_bytes,
group_storage_bytes = self.__group_storage_bytes,
rate_plan = self.__rate_plan,
) )
@ -346,6 +373,11 @@ class User( Persistent ):
self.update_revision()
self.__storage_bytes = storage_bytes
def __set_group_storage_bytes( self, group_storage_bytes ):
# The group_storage_bytes member isn't actually saved to the database, so setting it doesn't
# need to call update_revision().
self.__group_storage_bytes = group_storage_bytes
def __set_rate_plan( self, rate_plan ):
self.update_revision()
self.__rate_plan = rate_plan
@ -353,5 +385,6 @@ class User( Persistent ):
username = property( lambda self: self.__username )
email_address = property( lambda self: self.__email_address, __set_email_address )
password = property( None, __set_password )
storage_bytes = property( lambda self: self.__storage_bytes, __set_storage_bytes )
storage_bytes = property( lambda self: self.__group_storage_bytes or self.__storage_bytes, __set_storage_bytes )
group_storage_bytes = property( lambda self: self.__group_storage_bytes, __set_group_storage_bytes )
rate_plan = property( lambda self: self.__rate_plan, __set_rate_plan )

View File

@ -19,6 +19,7 @@ class Test_user( object ):
assert self.user.username == self.username
assert self.user.email_address == self.email_address
assert self.user.storage_bytes == 0
assert self.user.group_storage_bytes == 0
assert self.user.rate_plan == 0
def test_check_correct_password( self ):
@ -78,6 +79,14 @@ class Test_user( object ):
assert self.user.storage_bytes == storage_bytes
assert self.user.revision > previous_revision
def test_set_storage_bytes( self ):
original_revision = self.user.revision
group_storage_bytes = 44
self.user.group_storage_bytes = group_storage_bytes
assert self.user.group_storage_bytes == group_storage_bytes
assert self.user.revision == original_revision
def test_set_rate_plan( self ):
previous_revision = self.user.revision
rate_plan = 2
@ -91,4 +100,5 @@ class Test_user( object ):
assert d.get( "username" ) == self.username
assert d.get( "storage_bytes" ) == self.user.storage_bytes
assert d.get( "group_storage_bytes" ) == self.user.group_storage_bytes
assert d.get( "rate_plan" ) == self.user.rate_plan