def build_context(self, run, container): """ Builds the evaluation context for this contact :param run: the current run state :param container: the containing evaluation context :return: the context """ context = { '*': self.get_display(run.org, False), 'name': self.name, 'first_name': self.get_first_name(run.org), 'tel_e164': self.get_urn_display(run.org, ContactUrn.Scheme.TEL, True), 'groups': ",".join(self.groups), 'uuid': self.uuid, 'language': self.language } # add all URNs for scheme in ContactUrn.Scheme.__members__.values(): context[unicode(scheme.name).lower()] = self.get_urn_display(run.org, scheme, False) # add all fields for key, raw_value in self.fields.iteritems(): field = run.get_or_create_field(key) if field and field.value_type == Field.ValueType.DATETIME: as_datetime = conversions.to_datetime(raw_value, container) value = conversions.to_string(as_datetime, container) else: value = raw_value context[key] = value return context
def second(ctx, datetime): """ Returns only the second of a datetime (0 to 59) """ return conversions.to_datetime(datetime, ctx).second
def minute(ctx, datetime): """ Returns only the minute of a datetime (0 to 59) """ return conversions.to_datetime(datetime, ctx).minute
def hour(ctx, datetime): """ Returns only the hour of a datetime (0 to 23) """ return conversions.to_datetime(datetime, ctx).hour
def format_date(ctx, text): """ Takes a single parameter (date as string) and returns it in the format defined by the org """ dt = conversions.to_datetime(text, ctx) return dt.astimezone(ctx.timezone).strftime(ctx.get_date_format(True))
def epoch(ctx, datetime): """ Converts the given date to the number of seconds since January 1st, 1970 UTC """ return conversions.to_decimal( str(conversions.to_datetime(datetime, ctx).timestamp()), ctx)