Exemplo n.º 1
0
def make_project(title, description, theme_slug, tags=None):
    theme = Theme.query.filter_by(slug=theme_slug).first()
    if not theme:
        raise InvalidUsage.theme_not_found()
    project = Project(title=title,
                      description=description,
                      author=current_user.profile,
                      theme=theme)
    if tags is not None:
        for tag in tags:
            mtag = Tags.query.filter_by(tagname=tag).first()
            if not mtag:
                mtag = Tags(tag)
                mtag.save()
            project.add_tag(mtag)

    config = theme.config

    if len(config['spaces']) == 1:
        space = Space(author=current_user.profile)
        space.save()

        fields_to_generate = config['spaces'][0]['fields']
        generate_fields(space, fields_to_generate)
        project.add_space(space)

    project.save()
    return project
Exemplo n.º 2
0
def update_theme(slug, **kwargs):
    theme = Theme.query.filter_by(slug=slug,
                                  author_id=current_user.profile.id).first()
    if not theme:
        raise InvalidUsage.theme_not_found()
    theme.update(udpatedAt=datetime.datetime.utcnow(), **kwargs)
    theme.save()
    return theme
Exemplo n.º 3
0
def make_project(title, description, theme_slug, tags=None):
    theme = Theme.query.filter_by(slug=theme_slug).first()
    if not theme:
        raise InvalidUsage.theme_not_found()
    project = Project(title=title,
                      description=description,
                      author=current_user.profile,
                      theme=theme)
    if tags is not None:
        for tag in tags:
            mtag = Tags.query.filter_by(tagname=tag).first()
            if not mtag:
                mtag = Tags(tag)
                mtag.save()
            project.add_tag(mtag)
    project.save()
    return project
Exemplo n.º 4
0
def get_theme(slug):
    theme = Theme.query.filter_by(slug=slug).first()
    if not theme:
        raise InvalidUsage.theme_not_found()
    return theme