Пример #1
0
def edit_project(id):
    json = request.get_json(force=True)
    errors = []
    project = Project.query.get(id)
    contact = User.query.get(json['contact_id'])
    prj_url = json['title'].replace(' ', '_').lower()
    prj_tag = get_or_create(prj_url, Tag, name=prj_url)

    if project is None:
        errors.append("Does not exist.")

    if contact is None:
        errors.append('Project contact does not exist.')

    if prj_url == '':
        errors.append('Invalid project title.')

    if not has_content(json['content']):
        errors.append('Project must have content.')

    if not errors:
        project.title = json['title']
        project.completed = json['completed']
        project.repo = json['repo']
        project.contact = contact
        project.image_link = json['image']
        project.image_caption = json['caption']
        project.description = json['description']
        project.content = sanitize(json['content'])
        project.url = prj_url
        project.associated_tag = prj_tag
        db.session.commit()

    return jsonify(success=not errors, errors=errors,
                   url=prj_url, tag=prj_tag.serialize)
Пример #2
0
def new_post():
    errors = []
    json = request.get_json(force=True)
    post = Post(json, current_user.id)

    if not has_content(post.content):
        errors.append("Can't create empty post.")

    if not errors:
        db.session.add(post)
        db.session.commit()
    return jsonify(success=not errors, errors=errors)
Пример #3
0
def new_project():
    json = request.get_json(force=True)
    errors = []
    contact = User.query.get(json['contact_id'])
    prj_url = json['title'].replace(' ', '_').lower()
    prj_tag = get_or_create(prj_url, Tag, name=prj_url)

    if contact is None:
        errors.append('Project contact does not exist.')

    if prj_url == '':
        errors.append('Invalid project title.')

    if Project.query.filter_by(url=prj_url).first():
        errors.append('A project already exists with that title')

    if not has_content(json['content']):
        errors.append('Project must have content.')

    if not errors:
        project = Project(
            title=json['title'],
            completed=json['completed'],
            repo=json['repo'],
            contact=contact,
            image=json['image'],
            caption=json['caption'],
            description=json['description'],
            content=sanitize(json['content']),
            url=prj_url,
            tag=prj_tag
        )
        db.session.add(project)
        db.session.commit()

    return jsonify(success=not errors, errors=errors,
                   url=prj_url, tag=prj_tag.serialize)