Personal wiki notebook (not under development)

Download_access.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from Persistent import Persistent, quote
  2. class Download_access( Persistent ):
  3. """
  4. Access for a particular user to a downloadable product. This object is used to create unique
  5. per-customer product download links without requiring the user to have a Luminotes account.
  6. """
  7. def __init__( self, object_id, revision = None, item_number = None, transaction_id = None ):
  8. """
  9. Create a download access record with the given id.
  10. @type object_id: unicode
  11. @param object_id: id of the download access
  12. @type revision: datetime or NoneType
  13. @param revision: revision timestamp of the object (optional, defaults to now)
  14. @type item_number: unicode or NoneType
  15. @param item_number: number of the item to which download access is granted (optional)
  16. @type transaction_id: unicode or NoneType
  17. @param transaction_id: payment processor id for the transaction used to pay for this download
  18. (optional)
  19. @rtype: Download_access
  20. @return: newly constructed download access object
  21. """
  22. Persistent.__init__( self, object_id, revision )
  23. self.__item_number = item_number
  24. self.__transaction_id = transaction_id
  25. @staticmethod
  26. def create( object_id, item_number = None, transaction_id = None ):
  27. """
  28. Convenience constructor for creating a new download access object.
  29. @type item_number: unicode or NoneType
  30. @param item_number: number of the item to which download access is granted (optional)
  31. @type transaction_id: unicode or NoneType
  32. @param transaction_id: payment processor id for the transaction used to pay for this download
  33. (optional)
  34. @rtype: Download_access
  35. @return: newly constructed download access object
  36. """
  37. return Download_access( object_id, item_number = item_number, transaction_id = transaction_id )
  38. @staticmethod
  39. def sql_load( object_id, revision = None ):
  40. # download access objects don't store old revisions
  41. if revision:
  42. raise NotImplementedError()
  43. return "select id, revision, item_number, transaction_id from download_access where id = %s;" % quote( object_id )
  44. @staticmethod
  45. def sql_load_by_transaction_id( transaction_id ):
  46. return "select id, revision, item_number, transaction_id from download_access where transaction_id = %s;" % quote( transaction_id )
  47. @staticmethod
  48. def sql_id_exists( object_id, revision = None ):
  49. if revision:
  50. raise NotImplementedError()
  51. return "select id from download_access where id = %s;" % quote( object_id )
  52. def sql_exists( self ):
  53. return Download_access.sql_id_exists( self.object_id )
  54. def sql_create( self ):
  55. return "insert into download_access ( id, revision, item_number, transaction_id ) values ( %s, %s, %s, %s );" % \
  56. ( quote( self.object_id ), quote( self.revision ), quote( self.__item_number ), quote( self.__transaction_id ) )
  57. def sql_update( self ):
  58. return "update download_access set revision = %s, item_number = %s, transaction_id = %s where id = %s;" % \
  59. ( quote( self.revision ), quote( self.__item_number ), quote( self.__transaction_id ), quote( self.object_id ) )
  60. item_number = property( lambda self: self.__item_number )
  61. transaction_id = property( lambda self: self.__transaction_id )