Esempio n. 1
0
def create_type(request):
    success = False
    form = EntityTypeForm(request.POST)
    if form.is_valid():
        entity_name = form.cleaned_data["entity_type_regex"]
        entity_name = [entity_name.strip().lower()]
        try:
            manager = get_database_manager(request.user)

            if entity_type_already_defined(manager, entity_name):
                raise EntityTypeAlreadyDefined(u"Type: %s is already defined" %
                                               u'.'.join(entity_name))

            create_registration_form(manager, entity_name)
            define_type(manager, entity_name)
            message = _("Entity definition successful")
            success = True
            UserActivityLog().log(request,
                                  action=ADDED_IDENTIFICATION_NUMBER_TYPE,
                                  project=entity_name[0].capitalize())
        except EntityTypeAlreadyDefined:
            message = _("%s already exists.") % (entity_name[0].capitalize(), )
    else:
        message = form.errors['entity_type_regex']
    return HttpResponse(json.dumps({
        'success': success,
        'message': _(message)
    }))
Esempio n. 2
0
def define_type(dbm, entity_type):
    """
    Add this entity type to the tree of all entity types and save it
    to the database. entity_type may be a string or a list of
    strings.
    """
    assert is_not_empty(entity_type)
    assert is_sequence(entity_type)
    type_path = ([entity_type] if is_string(entity_type) else entity_type)
    type_path = [item.strip() for item in type_path]
    if entity_type_already_defined(dbm, type_path):
        raise EntityTypeAlreadyDefined(u"Type: %s is already defined" %
                                       u'.'.join(entity_type))
        # now make the new one
    entity_tree = _get_entity_type_tree(dbm)
    entity_tree.add_path([atree.AggregationTree.root_id] + entity_type)
    entity_tree.save()
Esempio n. 3
0
def define_type(dbm, entity_type):
    """
    Add this entity type to the tree of all entity types and save it
    to the database. entity_type may be a string or a list of
    strings.
    """
    assert is_not_empty(entity_type)
    assert is_sequence(entity_type)
    assert isinstance(dbm, DatabaseManager)
    if entity_type_already_defined(dbm, entity_type):
        raise EntityTypeAlreadyDefined(u"Type: %s is already defined" %
                                       u'.'.join(entity_type))
    entity_tree = AggregationTree.get(dbm,
                                      ENTITY_TYPE_TREE_ID,
                                      get_or_create=True)
    entity_tree.add_path([AggregationTree.root_id] + entity_type)
    entity_tree.save()