Guest User

Untitled

a guest
Oct 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.40 KB | None | 0 0
  1. class CommissionImportCommissionJunction(models.Model):
  2.  
  3. class Meta(object):
  4. db_table = u'commission_import_commission_junction'
  5.  
  6. objects = CommissionImportCommissionJunctionManager()
  7.  
  8. commission_import_commission_junction_id = models.AutoField(primary_key=True)
  9. action_status = models.CharField(max_length=50)
  10. action_type = models.CharField(max_length=50)
  11. ad_id = models.BigIntegerField(null=True, blank=True)
  12. commission_id = models.BigIntegerField()
  13. country = models.CharField(max_length=255, null=True, blank=True)
  14. event_date = models.DateTimeField()
  15. locking_date = models.DateTimeField(null=True, blank=True)
  16. order_id = models.CharField(max_length=50)
  17. original = models.NullBooleanField(null=True, blank=True)
  18. original_action_id = models.BigIntegerField()
  19. posting_date = models.DateTimeField()
  20. website_id = models.BigIntegerField()
  21. advertiser_name = models.CharField(max_length=500, null=True, blank=True)
  22. commission_amount = models.DecimalField(max_digits=19, decimal_places=2)
  23. sale_amount = models.DecimalField(max_digits=19, decimal_places=2)
  24. aggregator_affiliate_id = models.IntegerField()
  25. is_processed = models.BooleanField(db_index=True)
  26. created_date = models.DateTimeField(auto_now_add=True)
  27. member_transaction = models.ForeignKey(transactionsmodels.MemberTransaction, null=True, blank=True)
  28. commission_import_build = models.ForeignKey(CommissionImportBuild)
  29. sid = models.CharField(max_length=255, null=True, blank=True)
  30. error_description = models.TextField(null=True, blank=True)
  31. error_type = models.ForeignKey(ImportErrorType, db_column='error_type', to_field='error_type_code', null=True, blank=True)
  32.  
  33. class Affiliate(models.Model):
  34. ''' Affiliate.
  35.  
  36. Fields maintained EXPLICITLY by CSV imports:
  37. - aggregator/aggregator_affiliate_id (PK)
  38. - aggregator_affiliate_name
  39. - name
  40. - website_name
  41. - offer (JSON) :: AffiliateCommissionBracket, NonCommissionableGood, CommissionableGood, select_goods_only, has_non_commissionable_goods
  42. - notes
  43. - green
  44. - categories (CSV) :: AffiliateCategory
  45. - description
  46. - rollover
  47. - days_to_return
  48. - active
  49. - impression_pixel
  50. - aggregator_affiliate_name
  51. - Optionally:
  52. - link
  53. - link_expiration_date
  54. - image_src
  55. - impression_pixel
  56.  
  57. Fields implicitly maintained by CSV imports:
  58. - auto_activate
  59. - updated -- if image_src and link are supplied, updated gets set to True
  60.  
  61. Fields implicitly maintained by the old Affiliate Admin system:
  62. - updated
  63.  
  64. Share-A-Sale updates take up too many API credits. Updating the links
  65. and images needs to be done manually after the first time they are updated.
  66.  
  67. '''
  68.  
  69. affiliate_id = models.AutoField(primary_key=True)
  70. aggregator = models.ForeignKey(aggregatorsmodels.Aggregator)
  71. #: This is the ID of the affiliate given by an Aggregator
  72. aggregator_affiliate_id = models.IntegerField()
  73. #: This is the name of the affiliate given by an Aggregator
  74. aggregator_affiliate_name = models.CharField(max_length=255, null=True, blank=True)
  75. #: This is the name of the affiliate given by Employee Rewards
  76. name = models.CharField(max_length=255, null=True, blank=True)
  77. #: This is a description of the affiliate. It is displayed over the affiliate website name
  78. description = models.TextField(max_length=1000, null=True, blank=True)
  79. #: This is a secondary description of the affiliate. It is displayed over the affiliate image
  80. rollover = models.TextField(max_length=1000, null=True, blank=True)
  81. #: This is the link to follow to reach this affiliate's website and be tracked through the aggregator
  82. link = models.CharField(max_length=1024, null=True, blank=True)
  83. #: This is the day the link expires
  84. link_expiration_date = models.DateTimeField(null=True, blank=True)
  85. #: The URL of this affiliate's image
  86. image_src = models.CharField(max_length=1024, null=True, blank=True)
  87. #: The local filepath of this affiliate's image
  88. image_filepath = models.CharField(max_length=1000, null=True, blank=True)
  89. #: Whether or not this affiliate is active on the aggreagtor system.
  90. active = models.BooleanField(db_index=True, default=False)
  91. #: The name of the affiliate's website i.e. walmart.com or bestbuy.com
  92. website_name = models.CharField(max_length=150, null=True, blank=True)
  93. #: Admin notes about this affiliate
  94. notes = models.TextField(max_length=1000, null=True, blank=True)
  95. #: A URL of a pixel used to track how many times an affiliate's information has been shown to customers
  96. impression_pixel = models.CharField(max_length=1000, null=True, blank=True)
  97. #: Whether or not this affiliate is explicitly earth-friendly
  98. green = models.NullBooleanField(null=True, blank=True)
  99. #: Number of days an affiliate takes before issuing commission for purchases
  100. days_to_return = models.IntegerField(null=True, blank=True)
  101. auto_activate = models.BooleanField(default=False)
  102. ''' If an affiliate is uploaded for the first time, it is not active, but
  103. will be automatically activated when the next affiliates update occurs and
  104. the affiliate is ready to be seen by the public'''
  105. #: Whether this affiliate has commission only on select goods.
  106. is_select_goods_only = models.BooleanField(default=False)
  107. has_non_commissionable_goods = models.BooleanField(default=False)
  108. ''' Whether or not this affiliate has goods that do not have a commission reward.
  109. Helpful when a list of those goods is not available. '''
  110. #: Whether or not this Affiliate has been published, and should be shown to the customer
  111. published = models.BooleanField(default=False)
  112.  
  113. #: Specify the through-table for our M2M relationship with categories
  114. categories = models.ManyToManyField(categorymodels.Category, through='AffiliateCategory')
  115.  
  116. class Meta(object):
  117. db_table = u'affiliates'
  118. unique_together = ("aggregator", "aggregator_affiliate_id")
  119. ordering = ['name']
  120.  
  121. def __unicode__(self):
  122. return self.name
  123.  
  124. def get_external_properties(self):
  125. return self.aggregator.proxy.affiliate_properties(self.aggregator_affiliate_id)
  126.  
  127. class MemberHash(models.Model):
  128. member_hash_id = models.AutoField(primary_key=True)
  129. member = models.ForeignKey('Member')
  130. site = models.ForeignKey(legacymodels.Site)
  131. hash = models.CharField(unique=True, max_length=24)
  132. class Meta(object):
  133. db_table = u'member_hashes'
  134.  
  135. class CommissionImportBuild(models.Model):
  136. commission_import_build_id = models.AutoField(primary_key=True)
  137. build_date = models.DateTimeField(unique=True)
  138. class Meta(object):
  139. db_table = u'commission_import_builds'
  140.  
  141. def __unicode__(self):
  142. return self.build_date.strftime('%B %m, %Y, %I:%M %p')
  143.  
  144. # Create your models here.
  145. class Aggregator(models.Model):
  146. aggregator_id = models.AutoField(primary_key=True)
  147. system_name = models.CharField(max_length=255, null=False, blank=False, unique=True)
  148. name = models.CharField(max_length=255, null=True, blank=True)
  149. active = models.BooleanField(default=False, db_index=True)
  150. #: The user name to log into the aggregator's management system/API
  151. account_username = models.CharField(max_length=255, null=True, blank=True)
  152. #: The password to log into the aggregator's management system/API
  153. account_password = models.CharField(max_length=255, null=True, blank=True)
  154.  
  155. objects = AggregatorManager()
  156. linkshare_objects = LinkshareManager()
  157. commission_junction_objects = CommissionJunctionManager()
  158. shareasale_objects = ShareASaleManager()
  159.  
  160. class Meta(object):
  161. db_table = u'aggregators'
  162.  
  163. @property
  164. def proxy(self):
  165. return self._get_proxy()
  166.  
  167. def _get_proxy(self):
  168. ''' Return the Proxy instance for this Aggregator. '''
  169. if self.name == 'Linkshare':
  170. return Linkshare.objects.get_instance()
  171. elif self.name == 'Commission Junction':
  172. return CommissionJunction.objects.get_instance()
  173. elif self.name == 'Share-A-Sale':
  174. return ShareASale.objects.get_instance()
  175. else:
  176. raise Exception('Invalid aggregator name "%s". Excpected Linkshare, Commission Junction, or Share-A-Sale.' % self.name)
  177.  
  178. def __unicode__(self):
  179. return self.name
Add Comment
Please, Sign In to add comment