Exemplo n.º 1
0
def save_projects(title, description, rank, image, _id=None):
    from models import db
    rank = int(rank)
    some_rank = int(rank)
    value = update_ranks(some_rank)

    projects_item = db.Project() if not _id else db.Project.find_one({'_id': ObjectId(_id)})
    image_name = str(title).replace(' ', '_')
    if BASE_URl in image:
        pass
    else:
        image = image_decode_save(image, image_name, 'projects')
        if 'error' in image:
            return {'failed_msg': 'Could not upload image to the sever'}
        else:
            image = image.get('url')
    if value:
        projects_item['description'] = description
        projects_item['title'] = title
        projects_item['image'] = image
        projects_item['rank'] = rank
        try:
            projects_item.save()
        except Exception as exp:
            raise
            return {'failed_msg': "Database issues, unable to save Carousel, contact admin"}
    else:
        return {'failed_msg': "Database issues, unable to save Carousel, contact admin"}

    return get_projects(cond=dict(projects_item))
Exemplo n.º 2
0
def save_contact(image, description, rank, title, _id=None, count=0):
    from models import db
    rank = int(rank)
    some_rank = int(rank)
    value = update_ranks(some_rank)

    a_contact = db.Contact() if not _id else db.Contact.find_one(
        {'_id': ObjectId(_id)})
    image_name = str(title).replace(' ', '_')
    if BASE_URl in image:
        pass
    else:
        image = image_decode_save(image, image_name, 'contact')
        if 'error' in image:
            return {'failed_msg': 'Could not upload image to the sever'}
        else:
            image = image.get('url')
    if value:
        a_contact['description'] = description
        a_contact['image'] = image
        a_contact['rank'] = rank
        a_contact['title'] = title
        try:
            a_contact.save()
        except Exception as exp:
            raise
            return {
                'failed_msg':
                "Database issues, unable to save contact, contact admin"
            }
    else:
        return {
            'failed_msg':
            "Database issues, unable to save contact, contact admin"
        }

    return get_contacts(cond=dict(a_contact))
Exemplo n.º 3
0
def save_image(image, name):
    return image_decode_save(image, name, 'others')