<commit_before>#!/usr/bin/env python
# vim: fileencoding=utf-8 tabstop=2 softtabstop=2 shiftwidth=2 expandtab

import httplib
import json

from flask import abort, render_template, request
from sqlalchemy.exc import IntegrityError

from kanban_gallen import app, db
from .models import KanbanColumn, KanbanPortlet


def create_column_result(success, id=None, title=None):
  return json.dumps({'success': success, 'id': id, 'title': title})


def create_portlet_result(success, id=None, title=None, content=None):
  return json.dumps({'success': success, 'id': id, 'title': title,
                    'content': content})


@app.route('/', methods=['GET'])
def index():
  columns = KanbanColumn.query.all()
  return render_template('index.html', columns=columns)


@app.route('/create/column', methods=['POST'])
@app.route('/create/column/', methods=['POST'])
def create_column():
  new_title = 'New Column'
  column = KanbanColumn(new_title)

  try:
    db.session.add(column)
    db.session.commit()
  except IntegrityError:
    abort(httplib.BAD_REQUEST, 'BAD REQUEST')
    return create_column_result(False)
  return create_column_result(True, column.id, column.title)


@app.route('/create/portlet/<column_id>', methods=['POST'])
@app.route('/create/portlet/<column_id>/', methods=['POST'])
def create_portlet(column_id):
  column = KanbanColumn.query.get(column_id)

  if not column:
    abort(httplib.NOT_FOUND, 'COLUMN NOT FOUND')

  new_title = "New Portlet"
  new_content = "Lorem ipsum"
  portlet = KanbanPortlet(new_title, new_content)
  try:
    column.portlets.append(portlet)
    db.session.add(portlet)
    db.session.commit()
  except IntegrityError:
    abort(httplib.BAD_REQUEST, 'BAD REQUEST')
    return create_portlet_result(False)
  return create_portlet_result(True, portlet.id, portlet.title,
                               portlet.content)


@app.route('/edit/portlet/<portlet_id>', methods=['PUT'])
@app.route('/edit/portlet/<portlet_id>/', methods=['PUT'])
def edit_portlet(portlet_id):
  portlet = KanbanPortlet.query.get(portlet_id)
  print dir(request)
  title = request.values['title']
  portlet.title = title<commit_msg>remove debug code<commit_after>#!/usr/bin/env python
# vim: fileencoding=utf-8 tabstop=2 softtabstop=2 shiftwidth=2 expandtab

import httplib
import json

from flask import abort, render_template, request
from sqlalchemy.exc import IntegrityError

from kanban_gallen import app, db
from .models import KanbanColumn, KanbanPortlet


def create_column_result(success, id=None, title=None):
  return json.dumps({'success': success, 'id': id, 'title': title})


def create_portlet_result(success, id=None, title=None, content=None):
  return json.dumps({'success': success, 'id': id, 'title': title,
                    'content': content})


@app.route('/', methods=['GET'])
def index():
  columns = KanbanColumn.query.all()
  return render_template('index.html', columns=columns)


@app.route('/create/column', methods=['POST'])
@app.route('/create/column/', methods=['POST'])
def create_column():
  new_title = 'New Column'
  column = KanbanColumn(new_title)

  try:
    db.session.add(column)
    db.session.commit()
  except IntegrityError:
    abort(httplib.BAD_REQUEST, 'BAD REQUEST')
    return create_column_result(False)
  return create_column_result(True, column.id, column.title)


@app.route('/create/portlet/<column_id>', methods=['POST'])
@app.route('/create/portlet/<column_id>/', methods=['POST'])
def create_portlet(column_id):
  column = KanbanColumn.query.get(column_id)

  if not column:
    abort(httplib.NOT_FOUND, 'COLUMN NOT FOUND')

  new_title = "New Portlet"
  new_content = "Lorem ipsum"
  portlet = KanbanPortlet(new_title, new_content)
  try:
    column.portlets.append(portlet)
    db.session.add(portlet)
    db.session.commit()
  except IntegrityError:
    abort(httplib.BAD_REQUEST, 'BAD REQUEST')
    return create_portlet_result(False)
  return create_portlet_result(True, portlet.id, portlet.title,
                               portlet.content)


@app.route('/edit/portlet/<portlet_id>', methods=['PUT'])
@app.route('/edit/portlet/<portlet_id>/', methods=['PUT'])
def edit_portlet(portlet_id):
  portlet = KanbanPortlet.query.get(portlet_id)
  title = request.values['title']
  portlet.title = title
{'fraction_non_alphanumeric': 0.1422906461394915, 'fraction_numerical': 0.0018661068346162819, 'mean_word_length': 4.834013605442177, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5072922', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1439, 'n_words': 289}