How to use the biblib.metajson.Common function in biblib

To help you get started, we’ve selected a few biblib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github medialab / reference_manager / biblib / metajson.py View on Github external
if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_CALL


# Collection
class Collection(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_metajson" not in self:
            self["rec_metajson"] = constants.METAJSON_VERSION
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_COLLECTION


# Creator
class Creator(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "agent" in self:
            agent = self["agent"]
            if agent and "rec_class" in agent:
                rec_class = agent["rec_class"]
                if constants.REC_CLASS_PERSON == rec_class:
                    self["agent"] = Person(self["agent"])
                elif constants.REC_CLASS_ORGUNIT == rec_class:
                    self["agent"] = Orgunit(self["agent"])
                elif constants.REC_CLASS_EVENT == rec_class:
                    self["agent"] = Event(self["agent"])
                elif constants.REC_CLASS_FAMILY == rec_class:
                    self["agent"] = Family(self["agent"])
                elif constants.REC_CLASS_BRAND == rec_class:
                    self["agent"] = Family(self["agent"])
github medialab / reference_manager / biblib / metajson.py View on Github external
# Family
class Family(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_FAMILY

    def formatted_name(self):
        if "name_family" in self:
            return self["name_family"]


# Identifier
class Identifier(Common):
    pass


# Orgunit
class Orgunit(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_ORGUNIT

    def formatted_name(self):
        if "name" in self:
            #logging.debug("Orgunit.formatted_name : {}".format(self["name"]))
            return self["name"]
github medialab / reference_manager / biblib / metajson.py View on Github external
def get_first_value_for_type_in_list(self, my_list, my_type):
        if len(my_list) > 0:
            for item in my_list:
                    if "type" in item and "value" in item and item["value"]:
                        if item["type"] == my_type:
                            return item["value"]

    def get_property_for_item_in_list(self, my_list, my_property):
        if len(my_list) > 0:
            for item in my_list:
                if my_property in item and item[my_property]:
                    return item[my_property]


# Event
class Event(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_EVENT

    def formatted_name(self):
        if "title" in self:
            return self["title"]


# Family
class Family(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_FAMILY
github medialab / reference_manager / biblib / services / metajson_service.py View on Github external
elif meta_dict["rec_class"] == "Family":
        return Family(meta_dict)
    elif meta_dict["rec_class"] == "Field":
        return Field(meta_dict)
    elif meta_dict["rec_class"] == "Resource":
        return Resource(meta_dict)
    elif meta_dict["rec_class"] == "Target":
        return Target(meta_dict)
    elif meta_dict["rec_class"] == "Type":
        return Type(meta_dict)
    elif meta_dict["rec_class"] == "Collection":
        return Collection(meta_dict)
    else:
        logging.debug(jsonbson.dumps_bson(meta_dict))
        logging.warning("Unknown rec_class: {O}".format(meta_dict["rec_class"]))
        return Common(meta_dict)
github medialab / reference_manager / biblib / metajson.py View on Github external
result = ""
        if style == STYLE_FAMILY_COMMA_GIVEN:
            if "name_family" in self and self["name_family"]:
                result += self["name_family"]
            if "name_given" in self and self["name_given"]:
                result += ", " + self["name_given"]
        else:
            if "name_given" in self and self["name_given"]:
                result += self["name_given"] + " "
            if "name_family" in self and self["name_family"]:
                result += self["name_family"]
        return result


# Project
class Project(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_PROJECT


# Resource
class Resource(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_RESOURCE


# Rights
class Rights(Common):
github medialab / reference_manager / biblib / metajson.py View on Github external
def add_items_to_key(self, items, key):
        if items is not None and len(items) != 0:
            for item in items:
                self.add_item_to_key(item, key)

    def add_item_to_key(self, item, key):
        if item:
            try:
                self[key].append(item)
            except:
                self[key] = [item]


# Brand
class Brand(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_BRAND

    def formatted_name(self):
        if "name" in self:
            return self["name"]

# Call
class Call(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_CALL
github medialab / reference_manager / biblib / metajson.py View on Github external
elif constants.REC_CLASS_FAMILY == rec_class:
                    return agent.formatted_name()
                elif constants.REC_CLASS_BRAND == rec_class:
                    return agent.formatted_name()


# Field
class Field(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_FIELD


# Document
class Document(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_DOCUMENT
        if "creators" in self:
            self["creators"] = [Creator(x) for x in self["creators"]]
        if "absorbs" in self:
            self["absorbs"] = [Document(x) for x in self["absorbs"]]
        if "aggregates" in self:
            self["aggregates"] = [Document(x) for x in self["aggregates"]]
        if "becomes" in self:
            self["becomes"] = [Document(x) for x in self["becomes"]]
        if "conforms_tos" in self:
            self["conforms_tos"] = [Document(x) for x in self["conforms_tos"]]
        if "continues" in self:
            self["continues"] = [Document(x) for x in self["continues"]]
github medialab / reference_manager / biblib / metajson.py View on Github external
self["rec_class"] = constants.REC_CLASS_BRAND

    def formatted_name(self):
        if "name" in self:
            return self["name"]

# Call
class Call(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_CALL


# Collection
class Collection(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_metajson" not in self:
            self["rec_metajson"] = constants.METAJSON_VERSION
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_COLLECTION


# Creator
class Creator(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "agent" in self:
            agent = self["agent"]
            if agent and "rec_class" in agent:
                rec_class = agent["rec_class"]
github medialab / reference_manager / biblib / metajson.py View on Github external
class SearchResponse(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_metajson" not in self:
            self["rec_metajson"] = constants.METAJSON_VERSION
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_SEARCH_RESPONSE


# Subject
class Subject(Common):
    pass


# Target
class Target(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_TARGET


# Type
class Type(Common):
    def __init__(self, *args, **kwargs):
        Common.__init__(self, *args, **kwargs)
        if "rec_class" not in self:
            self["rec_class"] = constants.REC_CLASS_TYPE


# Warpper
class Warpper(Common):