Esempio n. 1
0
def get_package(package_id, user=None):
    username, pack_id, version = format_id(package_id)

    try:
        user = user or User.objects.get(username=username)
        package = Package.objects.get(pack_id=pack_id, user=user,
                                      version=version)
    except ObjectDoesNotExist:
        return None

    return package
Esempio n. 2
0
def get_generator(generator_id, user=None):
    username, gen_id, version = format_id(generator_id)

    try:
        user = user or User.objects.get(username=username)
        ver = version or get_latest_version(gen_id, user)
        gen = Generator.objects.get(gen_id=gen_id, user=user, version=ver)
    except ObjectDoesNotExist:
        return None

    return gen
Esempio n. 3
0
def get_relatives(gen, type, limit=None, user=None, search_term=None):
    all_relations = gen.generatorrelations_set.filter(relation=type)

    if search_term:
        all_relations = all_relations.filter(gen_id__icontains=search_term)

    total = all_relations.count()
    limit = limit or total
    relations = all_relations[:limit].values('to_gen')

    relations = [str(r['to_gen']) for r in relations]

    for i, generator_id in enumerate(relations):
        username, gen_id, version = format_id(generator_id)

        if not version and type != 'category':
            user = user or get_user(username)
            latest_ver = get_latest_version(gen_id, user)
            relations[i] = '-'.join([generator_id, latest_ver])

    return (relations, total)