Example #1
0
 def representation(self):
     if self.promo:
         return self.promo.representation(user=self.user)
     
     liked = False
     disliked = False
     
     votes = self.coupon.votes.filter(user=self.user)
     if votes:
         vote = votes[0]
         if vote.liked:
             liked = True
         else:
             disliked = True
     
     result = {
         "type": "local",
         "id": self.pk,
         "parent": self.coupon.representation(),
         "redeemed": format_datetime(self.redeemed),
         "added": format_datetime(self.added_at),
         "liked": liked,
         "disliked": disliked
     }
     
     now = datetime.datetime.now()
     if self.redeemed:
         remaining = ((self.redeemed + datetime.timedelta(seconds=COUPON_REDEEM_LIFESPAN)) - now).seconds
         
         if remaining < 0:
             remaining = 0
         
         result["remaining"] = remaining
     
     return result
Example #2
0
 def representation(self):
     result = {
         "type": "local",
         "id": self.pk,
         "parent": self.ad.representation(),
         'address': self.address,
         'email': self.email,
         'phone': self.phone,
         "added": format_datetime(self.added_at),
     }
     
     return result
Example #3
0
 def representation(self):
     return {
         "coupon_id":self.id,
         "title": self.title,
         "image": self.image.name,
         "description": self.description,
         "expires": format_datetime(self.valid_to),
         "redeemed": self.issued_redeemed,
         "redeem_limit":int(self.redeem_limit),
         "remaining": (self.redeem_limit - self.issued_redeemed) if self.redeem_limit else None,
         "geo": True if self.geography else False,
         "vendor": self.vendor.representation() if self.vendor else None
     }
Example #4
0
 def representation(self, user=None):
     return {
         "type": "remote",
         "expires": format_datetime(self.valid_to),
         "vendor": self.vendor.representation(promo=self, user=user)
     }