Exemplo n.º 1
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']]
Exemplo n.º 2
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)
Exemplo n.º 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)
Exemplo n.º 4
0
    def edit(self, json):
        landing = get_or_create(
            json['landing_image'], ImageLink, link=json['landing_image']
        )
        officers = get_or_create(
            json['officers_image'], ImageLink, link=json['officers_image']
        )

        db.session.commit()
        self.voting_started = json['voting_started']
        self.lounge_open = json['lounge_open']
        self.run_console_visible = json['run_console_visible']
        if json['lounge_password']:
            self.lounge_password = \
                generate_password_hash(json['lounge_password'])
        if json['officers_password']:
            self.officers_password = \
                generate_password_hash(json['officers_password'])
        self.voting_end_date = datetime.datetime\
            .fromtimestamp(json['voting_end_date'])
        self.landing_image_id = landing.id
        self.officers_image_id = officers.id
        db.session.commit()
Exemplo n.º 5
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)