예제 #1
0
    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
예제 #2
0
파일: runner.py 프로젝트: pld/flows
    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
예제 #3
0
def second(ctx, datetime):
    """
    Returns only the second of a datetime (0 to 59)
    """
    return conversions.to_datetime(datetime, ctx).second
예제 #4
0
def minute(ctx, datetime):
    """
    Returns only the minute of a datetime (0 to 59)
    """
    return conversions.to_datetime(datetime, ctx).minute
예제 #5
0
def hour(ctx, datetime):
    """
    Returns only the hour of a datetime (0 to 23)
    """
    return conversions.to_datetime(datetime, ctx).hour
예제 #6
0
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))
예제 #7
0
def second(ctx, datetime):
    """
    Returns only the second of a datetime (0 to 59)
    """
    return conversions.to_datetime(datetime, ctx).second
예제 #8
0
def minute(ctx, datetime):
    """
    Returns only the minute of a datetime (0 to 59)
    """
    return conversions.to_datetime(datetime, ctx).minute
예제 #9
0
def hour(ctx, datetime):
    """
    Returns only the hour of a datetime (0 to 23)
    """
    return conversions.to_datetime(datetime, ctx).hour
예제 #10
0
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)