Exemplo n.º 1
0
 def process_raw_data(self, raw_data, pad=None):
     rv = {}
     for field in itervalues(self.field_map):
         value = raw_data.get(field.name)
         rv[field.name] = field.deserialize_value(value, pad=pad)
     rv["_flowblock"] = self.id
     return rv
Exemplo n.º 2
0
 def process_raw_data(self, raw_data, pad=None):
     rv = {}
     for field in itervalues(self.field_map):
         value = raw_data.get(field.name)
         rv[field.name] = field.deserialize_value(value, pad=pad)
     rv['_flowblock'] = self.id
     return rv
Exemplo n.º 3
0
def get_record_info():
    pad = g.admin_context.pad
    request_path = request.args['path']
    tree_item = g.admin_context.tree.get(request_path)
    children = []
    attachments = []
    alts = []

    for child in tree_item.iter_children():
        if child.is_attachment:
            attachments.append(child)
        else:
            children.append(child)

    primary_alt = pad.db.config.primary_alternative
    if primary_alt is not None:
        for alt in itervalues(tree_item.alts):
            alt_cfg = pad.db.config.get_alternative(alt.id)
            alts.append({
                'alt': alt.id,
                'is_primary': alt.id == PRIMARY_ALT,
                'primary_overlay': alt.id == primary_alt,
                'name_i18n': alt_cfg['name'],
                'exists': alt.exists,
            })

    child_order_by = pad.query(request_path).get_order_by() or []

    return jsonify(
        id=tree_item.id,
        path=tree_item.path,
        label_i18n=tree_item.label_i18n,
        exists=tree_item.exists,
        is_attachment=tree_item.is_attachment,
        attachments=[{
            'id': x.id,
            'path': x.path,
            'type': x.attachment_type,
        } for x in attachments],
        children=[{
            'id': x.id,
            'path': x.path,
            'label': x.id,
            'label_i18n': x.label_i18n,
            'visible': x.is_visible,
        } for x in sorted(
            children,
            key=lambda c: pad.get(c.path).get_sort_key(child_order_by))
        ],
        alts=alts,
        can_have_children=tree_item.can_have_children,
        can_have_attachments=tree_item.can_have_attachments,
        can_be_deleted=tree_item.can_be_deleted,
    )
Exemplo n.º 4
0
def get_record_info():
    pad = g.admin_context.pad
    request_path = request.args["path"]
    tree_item = g.admin_context.tree.get(request_path)
    children = []
    attachments = []
    alts = []

    for child in tree_item.iter_children():
        if child.is_attachment:
            attachments.append(child)
        else:
            children.append(child)

    primary_alt = pad.db.config.primary_alternative
    if primary_alt is not None:
        for alt in itervalues(tree_item.alts):
            alt_cfg = pad.db.config.get_alternative(alt.id)
            alts.append({
                "alt": alt.id,
                "is_primary": alt.id == PRIMARY_ALT,
                "primary_overlay": alt.id == primary_alt,
                "name_i18n": alt_cfg["name"],
                "exists": alt.exists,
            })

    child_order_by = pad.query(request_path).get_order_by() or []

    return jsonify(
        id=tree_item.id,
        path=tree_item.path,
        label_i18n=tree_item.label_i18n,
        exists=tree_item.exists,
        is_attachment=tree_item.is_attachment,
        attachments=[{
            "id": x.id,
            "path": x.path,
            "type": x.attachment_type,
        } for x in attachments],
        children=[{
            "id": x.id,
            "path": x.path,
            "label": x.id,
            "label_i18n": x.label_i18n,
            "visible": x.is_visible,
        } for x in sorted(
            children,
            key=lambda c: pad.get(c.path).get_sort_key(child_order_by))],
        alts=alts,
        can_have_children=tree_item.can_have_children,
        can_have_attachments=tree_item.can_have_attachments,
        can_be_deleted=tree_item.can_be_deleted,
    )
Exemplo n.º 5
0
def test_datetime_timezone_location(env, pad):
    field = make_field(env, 'datetime')
    with Context(pad=pad):
        # Known location name, Asia/Seoul
        rv = field.deserialize_value('2016-04-30 01:02:03 Asia/Seoul', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        tzinfos = get_timezone('Asia/Seoul')._tzinfos  # pylint: disable=no-member
        assert rv.tzinfo in itervalues(tzinfos)
Exemplo n.º 6
0
def test_datetime_timezone_location(env, pad):
    field = make_field(env, 'datetime')
    with Context(pad=pad):
        # Known location name, Asia/Seoul
        rv = field.deserialize_value('2016-04-30 01:02:03 Asia/Seoul', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        tzinfos = get_timezone('Asia/Seoul')._tzinfos  # pylint: disable=no-member
        assert rv.tzinfo in itervalues(tzinfos)
Exemplo n.º 7
0
Arquivo: api.py Projeto: jab/lektor-1
def get_record_info():
    db = g.admin_context.pad.db
    tree_item = g.admin_context.tree.get(request.args['path'])
    children = []
    attachments = []
    alts = []

    for child in tree_item.iter_children():
        if child.is_attachment:
            attachments.append(child)
        else:
            children.append(child)

    primary_alt = db.config.primary_alternative
    if primary_alt is not None:
        for alt in itervalues(tree_item.alts):
            alt_cfg = db.config.get_alternative(alt.id)
            alts.append({
                'alt': alt.id,
                'is_primary': alt.id == PRIMARY_ALT,
                'primary_overlay': alt.id == primary_alt,
                'name_i18n': alt_cfg['name'],
                'exists': alt.exists,
            })

    return jsonify(
        id=tree_item.id,
        path=tree_item.path,
        label_i18n=tree_item.label_i18n,
        exists=tree_item.exists,
        is_attachment=tree_item.is_attachment,
        attachments=[{
            'id': x.id,
            'path': x.path,
            'type': x.attachment_type,
        } for x in attachments],
        children=[{
            'id': x.id,
            'path': x.path,
            'label': x.id,
            'label_i18n': x.label_i18n,
            'visible': x.is_visible,
        } for x in children],
        alts=alts,
        can_have_children=tree_item.can_have_children,
        can_have_attachments=tree_item.can_have_attachments,
        can_be_deleted=tree_item.can_be_deleted,
    )
Exemplo n.º 8
0
 def iter_plugins(self):
     # XXX: sort?
     return itervalues(self.env.plugins)
Exemplo n.º 9
0
def test_datetime(env, pad):
    field = make_field(env, 'datetime')

    with Context(pad=pad):
        # default
        rv = field.deserialize_value('2016-04-30 01:02:03', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo is None

        # It is not datetime, it is None
        rv = field.deserialize_value(None, pad=pad)
        assert isinstance(rv, Undefined)

        # It is not datetime, it is empty string
        rv = field.deserialize_value('', pad=pad)
        assert isinstance(rv, BadValue)

        # It is not datetime, it is date
        rv = field.deserialize_value('2016-04-30', pad=pad)
        assert isinstance(rv, BadValue)

        # Known timezone name, UTC
        rv = field.deserialize_value('2016-04-30 01:02:03 UTC', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo is get_timezone('UTC')

        # Known timezone name, EST
        rv = field.deserialize_value('2016-04-30 01:02:03 EST', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo is get_timezone('EST')

        # Known location name, Asia/Seoul
        rv = field.deserialize_value('2016-04-30 01:02:03 Asia/Seoul', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo in itervalues(get_timezone('Asia/Seoul')._tzinfos)

        # KST - http://www.timeanddate.com/time/zones/kst
        rv = field.deserialize_value('2016-04-30 01:02:03 +0900', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, 9 * 60 * 60)

        # ACST - http://www.timeanddate.com/time/zones/acst
        rv = field.deserialize_value('2016-04-30 01:02:03 +0930', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, (9 * 60 + 30) * 60)

        # MST - http://www.timeanddate.com/time/zones/mst
        rv = field.deserialize_value('2016-04-30 01:02:03 -0700', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, -7 * 60 * 60)

        # MART - http://www.timeanddate.com/time/zones/mart
        rv = field.deserialize_value('2016-04-30 01:02:03 -0930', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, -(9 * 60 + 30) * 60)

        # with timezone name (case 1)
        rv = field.deserialize_value('2016-04-30 01:02:03 KST +0900', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, 9 * 60 * 60)

        # with timezone name (case 2)
        rv = field.deserialize_value('2016-04-30 01:02:03 KST+0900', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, 9 * 60 * 60)
Exemplo n.º 10
0
 def iter_plugins(self):
     # XXX: sort?
     return itervalues(self.env.plugins)
Exemplo n.º 11
0
def test_datetime(env, pad):
    field = make_field(env, 'datetime')

    with Context(pad=pad):
        # default
        rv = field.deserialize_value('2016-04-30 01:02:03', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo is None

        # It is not datetime, it is None
        rv = field.deserialize_value(None, pad=pad)
        assert isinstance(rv, Undefined)

        # It is not datetime, it is empty string
        rv = field.deserialize_value('', pad=pad)
        assert isinstance(rv, BadValue)

        # It is not datetime, it is date
        rv = field.deserialize_value('2016-04-30', pad=pad)
        assert isinstance(rv, BadValue)

        # Known timezone name, UTC
        rv = field.deserialize_value('2016-04-30 01:02:03 UTC', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo is get_timezone('UTC')

        # Known timezone name, EST
        rv = field.deserialize_value('2016-04-30 01:02:03 EST', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo is get_timezone('EST')

        # Known location name, Asia/Seoul
        rv = field.deserialize_value('2016-04-30 01:02:03 Asia/Seoul', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo in itervalues(get_timezone('Asia/Seoul')._tzinfos)

        # KST - http://www.timeanddate.com/time/zones/kst
        rv = field.deserialize_value('2016-04-30 01:02:03 +0900', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, 9 * 60 * 60)

        # ACST - http://www.timeanddate.com/time/zones/acst
        rv = field.deserialize_value('2016-04-30 01:02:03 +0930', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, (9 * 60 + 30) * 60)

        # MST - http://www.timeanddate.com/time/zones/mst
        rv = field.deserialize_value('2016-04-30 01:02:03 -0700', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, -7 * 60 * 60)

        # MART - http://www.timeanddate.com/time/zones/mart
        rv = field.deserialize_value('2016-04-30 01:02:03 -0930', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, -(9 * 60 + 30) * 60)

        # with timezone name (case 1)
        rv = field.deserialize_value('2016-04-30 01:02:03 KST +0900', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, 9 * 60 * 60)

        # with timezone name (case 2)
        rv = field.deserialize_value('2016-04-30 01:02:03 KST+0900', pad=pad)
        assert isinstance(rv, datetime.datetime)
        assert rv.year == 2016
        assert rv.month == 4
        assert rv.day == 30
        assert rv.hour == 1
        assert rv.minute == 2
        assert rv.second == 3
        assert rv.tzinfo._offset == datetime.timedelta(0, 9 * 60 * 60)