Exemple #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)
Exemple #2
0
 def __init__(self, json, user_id):
     self.date = unix_time()
     self.title = json['title']
     self.content = sanitize(json['content'])
     self.sticky = False
     self.user_id = user_id
     self.tags = [get_or_create(tag['name'], Tag, name=tag['name'])
                  for tag in json['tags']]
     self.images = [get_or_create(link, ImageLink, link=link)
                    for link in json['images']]
Exemple #3
0
def edit_post(id):
    errors = []
    json = request.get_json(force=True)
    post = Post.query.get(id)

    if not post:
        errors.append("Post does not exist.")
    elif post.user_id != current_user.id:
        errors.append("Forbidden.")

    if not errors:
        post.title = json['title']
        post.content = sanitize(json['content'])
        post.tags = [get_or_create(tag['name'], Tag, name=tag['name'])
                     for tag in json['tags']]
        post.images = [get_or_create(link, ImageLink, link=link)
                       for link in json['images']]
        db.session.commit()
    return jsonify(success=not errors, errors=errors)
Exemple #4
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)