No 2 projects with same name

This commit is contained in:
2018-07-22 00:25:31 +02:00
parent 59dcbeb101
commit a23efc330c
2 changed files with 20 additions and 16 deletions

View File

@@ -9,7 +9,7 @@
CREATE TABLE project (
id integer primary key,
username text, -- User the project belongs to.
name text, -- Project name.
name text unique, -- Project name.
status text, -- Project status.
created_at date, -- When the project was created?
updated_at date -- When the project was last updated?

View File

@@ -3,6 +3,7 @@ import getpass
import datetime
import logging
import sys
import sqlite3
import task
@@ -91,7 +92,6 @@ def parse_project_args(project, args):
def create_project(project, conn):
# TODO Project is same name is forbidden
logging.info(">> Create project")
query = """
@@ -100,21 +100,25 @@ def create_project(project, conn):
"""
cursor = conn.cursor()
cursor.execute(
query,
(getpass.getuser(), project.name, project.status, datetime.datetime.now()),
)
project_id = cursor.lastrowid
action_message = "{} (status: {})".format(project.name, project.status)
record_action(cursor, TypeAction.CREATE, action_message, project_id=project_id)
logging.debug(action_message)
print(
"created project {}: {} (status: {})".format(
project_id, project.name, project.status
try:
cursor.execute(
query,
(getpass.getuser(), project.name, project.status, datetime.datetime.now()),
)
)
project_id = cursor.lastrowid
action_message = "{} (status: {})".format(project.name, project.status)
record_action(cursor, TypeAction.CREATE, action_message, project_id=project_id)
logging.debug(action_message)
print(
"created project {}: {} (status: {})".format(
project_id, project.name, project.status
)
)
except sqlite3.IntegrityError as error:
print("project with the same name already exists")
logging.info(error)
def edit_project(project, project_id, conn):