Exemple #1
0
def suggest_scenario(scenario_id):
    errors = []
    content = request.form.get('content', '')
    if content == '':
        errors.append(gettext('Suggest content is required'))
        return json.dumps(errors), 400
    
    scenario = Scenario.query.get(scenario_id)
    if scenario is None:
        errors.append('Scenario not found')
        return json.dumps(errors), 404
    comment_topic = scenario.comment_topic
    
    new_comment = Comment(g.user, comment_topic, content)
    new_comment.description = gettext('Suggest for scenario')
    db.session.add(new_comment)
    db.session.commit()

    #send email to admins about the suggested content
    admin_group = Group.query.get(1)
    admins = admin_group.users
    admin_emails = []
    for admin in admins:
        admin_emails.append(admin.email)
    send_mail(admin_emails, '[SketchupOulu] New suggest for ' + scenario.name, render_template("users/suggest_scenario_email_content.html", suggest_content=content, scenario=scenario.to_dict(), user=g.user.username))
    return json.dumps(new_comment.to_dict(include_owner=True)), 200
Exemple #2
0
def suggest_scenario(scenario_id):
    errors = []
    content = request.form.get('content', '')
    if content == '':
        errors.append(gettext('Suggest content is required'))
        return json.dumps(errors), 400

    scenario = Scenario.query.get(scenario_id)
    if scenario is None:
        errors.append('Scenario not found')
        return json.dumps(errors), 404
    comment_topic = scenario.comment_topic

    new_comment = Comment(g.user, comment_topic, content)
    new_comment.description = gettext('Suggest for scenario')
    db.session.add(new_comment)
    db.session.commit()

    #send email to admins about the suggested content
    admin_group = Group.query.get(1)
    admins = admin_group.users
    admin_emails = []
    for admin in admins:
        admin_emails.append(admin.email)
    send_mail(
        admin_emails, '[SketchupOulu] New suggest for ' + scenario.name,
        render_template("users/suggest_scenario_email_content.html",
                        suggest_content=content,
                        scenario=scenario.to_dict(),
                        user=g.user.username))
    return json.dumps(new_comment.to_dict(include_owner=True)), 200
Exemple #3
0
def add_comment():
    errors = []
    comment_type = request.form.get('comment_type', '')
    object_id = request.form.get('object_id', '')
    content = request.form.get('content', '')
    if content == '':
        errors.append(gettext('Comment content is required'))
        return json.dumps(errors), 400
    if object_id == '':
        errors.append(gettext('Comment object is required'))
        return json.dumps(errors), 400

    comment_topic = None
    if comment_type == 'scenario':
        scenario = Scenario.query.get(object_id)
        if scenario is None:
            errors.append('Scenario not found')
            return json.dumps(errors), 404
        if not scenario.can_access(g.user):
            errors.append(
                gettext('You don\'t have permission to add comment here'))
            return json.dumps(errors), 401
        comment_topic = scenario.comment_topic
    elif comment_type == 'building_model':
        building_model = BuildingModel.query.get(object_id)
        if building_model is None:
            errors.append('Building model not found')
            return json.dumps(errors), 404
        comment_topic = building_model.comment_topic
    elif comment_type == 'user':
        user = User.query.get(object_id)
        if user is None:
            errors.append('User not found')
            return json.dumps(errors), 404
        comment_topic = user.comment_topic
    else:
        errors.append(gettext('Comment type not found'))
        return json.dumps(errors), 401

    new_comment = Comment(g.user, comment_topic, content)
    db.session.add(new_comment)
    db.session.commit()

    return json.dumps(new_comment.to_dict(include_owner=True)), 200
Exemple #4
0
def add_comment():
    errors = []
    comment_type = request.form.get('comment_type', '')
    object_id = request.form.get('object_id', '')
    content = request.form.get('content', '')
    if content == '':
        errors.append(gettext('Comment content is required'))
        return json.dumps(errors), 400
    if object_id == '':
        errors.append(gettext('Comment object is required'))
        return json.dumps(errors), 400

    comment_topic = None
    if comment_type == 'scenario':
        scenario = Scenario.query.get(object_id)
        if scenario is None:
            errors.append('Scenario not found')
            return json.dumps(errors), 404
        if not scenario.can_access(g.user):
            errors.append(gettext('You don\'t have permission to add comment here'))
            return json.dumps(errors), 401
        comment_topic = scenario.comment_topic
    elif comment_type == 'building_model':
        building_model = BuildingModel.query.get(object_id)
        if building_model is None:
            errors.append('Building model not found')
            return json.dumps(errors), 404
        comment_topic = building_model.comment_topic
    elif comment_type == 'user':
        user = User.query.get(object_id)
        if user is None:
            errors.append('User not found')
            return json.dumps(errors), 404
        comment_topic = user.comment_topic
    else:
        errors.append(gettext('Comment type not found'))
        return json.dumps(errors), 401

    new_comment = Comment(g.user, comment_topic, content)
    db.session.add(new_comment)
    db.session.commit()

    return json.dumps(new_comment.to_dict(include_owner=True)), 200