def serialize_order(order): details = {} if isinstance(order, Order): customer = order.customer product = order.coffee created_at = order.date details['type'] = 'COFFEE' details['brew_method'] = order.brew.name details['packaging_method'] = order.package order.details.pop('shipped_to', None) # don't show details['remarks'] = order.details if order.voucher and order.voucher.name in settings.GIFT_VOUCHERS: details['gift'] = order.voucher.name elif isinstance(order, GearOrder): customer = order.customer product = order.gear created_at = order.date details['type'] = 'GEAR' details['brew_method'] = '-' details['packaging_method'] = '-' order.details.pop('shipped_to', None) # don't show details['remarks'] = { k: v if v not in ('true', 'false') else v.capitalize() for k, v in order.details.items() } if order.voucher and order.voucher.name in settings.GIFT_VOUCHERS: details['gift'] = order.voucher.name elif isinstance(order, RedemItem): customer = order.user.customer product = order.item created_at = order.added details['type'] = 'REDEM' details['brew_method'] = '-' details['packaging_method'] = '-' details['remarks'] = order.points shipping_at = order.shipping_date details['id'] = order.id details['customer_id'] = customer.id details['name'] = customer.get_full_name() details['email'] = customer.get_email() details['coffee'] = product.name details['created_date'] = int(dt_format(created_at, 'U')) details['shipping_date'] = int(dt_format(shipping_at, 'U')) details['status'] = order.status # order.get_status_display() return details
def serialize_date(some_date): """ Returns the string representation of a date """ return dt_format( datetime.datetime.combine(some_date, datetime.datetime.min.time()), settings.DATE_FORMAT)
def get_last_order_date(self): try: last_order_date = self.orders.latest('date').date except ObjectDoesNotExist: last_order_date = None return int(dt_format(last_order_date, 'U')) if last_order_date else None
def to_unix_timestamp_ms(date): """Convert datetime to unix timestamp in microseconds. Alternative: - date.strftime('%Y-%m-%dT%H:%M:%S%fZ') """ date_utc = date.replace(tzinfo=timezone.utc) return int(dt_format(date_utc, 'Uu'))
def _get_order_data(order_id): order = Order.objects.select_related('customer', 'coffee', 'brew', 'voucher').get(id=order_id) data = { 'order': { 'value': order.id, 'url': 'https://hookcoffee.com.sg/admin/customers/order/%d/' % order.id, }, 'coffee': { 'value': order.coffee.name, 'url': 'https://hookcoffee.com.sg/admin/coffees/coffeetype/%d/' % order.coffee.id }, 'created_date': int(dt_format(order.date, 'U')), 'shipping_date': int(dt_format(order.shipping_date, 'U')), 'shipping_address': '[%s] %s %s %s' % ( order.shipping_address['name'], order.shipping_address['line1'], order.shipping_address['line2'], order.shipping_address['postcode'], ), 'price': { 'currency': 'SGD', 'amount': round(order.amount * 100, 2), }, 'details': str(order.details) if order.details else None, 'voucher': order.voucher.name if order.voucher else None, 'is-shotpods': True if order.brew.name == 'Nespresso' else False, 'stripe_customer': order.customer.stripe_id or None, } return data
def _get_typeform_responses(survey, seconds=(120 * 60)): """Get responses submited on the surveys from TypeForm.""" since = timezone.now() - timedelta(seconds=seconds) api_url = ('https://api.typeform.com/v1/form/%(survey)s?key=%(key)s' '&completed=true&since=%(since)d' '&order_by[]=date_submit,desc') % { 'key': settings.TYPEFORM_API_KEY, 'survey': survey, 'since': int(dt_format(since, 'U')) } resp = urllib2.urlopen(api_url) resp = json.loads(resp.read()) return resp.get('responses', [])
def serialize_time(some_time): """ Returns the string representation of a time """ return dt_format(some_time, settings.TIME_FORMAT)
def get_last_login(self): return int(dt_format(self.user.last_login, 'U')) if self.user.last_login else None
def get_signed_up(self): return int(dt_format(self.user.created_at, 'U'))