def update_diary_from_form(dbo, username, data): """ Updates a diary note from form data """ l = dbo.locale diaryid = utils.df_ki(data, "diaryid") if utils.df_ks(data, "diarydate") == "": raise utils.ASMValidationError(i18n._("Diary date cannot be blank", l)) if utils.df_kd(data, "diarydate", l) is None: raise utils.ASMValidationError(i18n._("Diary date is not valid", l)) if utils.df_ks(data, "subject") == "": raise utils.ASMValidationError(i18n._("Diary subject cannot be blank", l)) if utils.df_ks(data, "note") == "": raise utils.ASMValidationError(i18n._("Diary note cannot be blank", l)) diarytime = utils.df_ks(data, "diarytime").strip() if diarytime != "": if diarytime.find(":") == -1: raise utils.ASMValidationError(i18n._("Invalid time, times should be in HH:MM format", l)) if not utils.is_numeric(diarytime.replace(":", "")): raise utils.ASMValidationError(i18n._("Invalid time, times should be in HH:MM format", l)) sql = db.make_update_user_sql(dbo, "diary", username, "ID=%d" % diaryid, ( ( "DiaryDateTime", utils.df_dt(data, "diarydate", "diarytime", l) ), ( "DiaryForName", utils.df_t(data, "diaryfor") ), ( "Subject", utils.df_t(data, "subject") ), ( "Note", utils.df_t(data, "note") ), ( "Comments", utils.df_t(data, "comments") ), ( "DateCompleted", utils.df_d(data, "completed", l) ) )) preaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) audit.edit(dbo, username, "diary", audit.map_diff(preaudit, postaudit))
def insert_diary_from_form(dbo, username, linktypeid, linkid, data): """ Creates a diary note from the form data username: User creating the diary linktypeid, linkid: The link data: The web.py form object """ l = dbo.locale if utils.df_ks(data, "diarydate") == "": raise utils.ASMValidationError(i18n._("Diary date cannot be blank", l)) if utils.df_kd(data, "diarydate", l) is None: raise utils.ASMValidationError(i18n._("Diary date is not valid", l)) if utils.df_ks(data, "subject") == "": raise utils.ASMValidationError( i18n._("Diary subject cannot be blank", l)) if utils.df_ks(data, "note") == "": raise utils.ASMValidationError(i18n._("Diary note cannot be blank", l)) diarytime = utils.df_ks(data, "diarytime").strip() if diarytime != "": if diarytime.find(":") == -1: raise utils.ASMValidationError( i18n._("Invalid time, times should be in HH:MM format", l)) if not utils.is_numeric(diarytime.replace(":", "")): raise utils.ASMValidationError( i18n._("Invalid time, times should be in HH:MM format", l)) linkinfo = get_link_info(dbo, linktypeid, linkid) diaryid = db.get_id(dbo, "diary") sql = db.make_insert_user_sql( dbo, "diary", username, (("ID", db.di(diaryid)), ("LinkID", db.di(linkid)), ("LinkType", db.di(linktypeid)), ("LinkInfo", db.ds(linkinfo)), ("DiaryDateTime", utils.df_dt(data, "diarydate", "diarytime", l)), ("DiaryForName", utils.df_t(data, "diaryfor")), ("Subject", utils.df_t(data, "subject")), ("Note", utils.df_t(data, "note")), ("DateCompleted", utils.df_d(data, "completed", l)))) db.execute(dbo, sql) audit.create(dbo, username, "diary", str(diaryid)) return diaryid
def insert_diary_from_form(dbo, username, linktypeid, linkid, data): """ Creates a diary note from the form data username: User creating the diary linktypeid, linkid: The link data: The web.py form object """ l = dbo.locale if utils.df_ks(data, "diarydate") == "": raise utils.ASMValidationError(i18n._("Diary date cannot be blank", l)) if utils.df_kd(data, "diarydate", l) is None: raise utils.ASMValidationError(i18n._("Diary date is not valid", l)) if utils.df_ks(data, "subject") == "": raise utils.ASMValidationError(i18n._("Diary subject cannot be blank", l)) if utils.df_ks(data, "note") == "": raise utils.ASMValidationError(i18n._("Diary note cannot be blank", l)) diarytime = utils.df_ks(data, "diarytime").strip() if diarytime != "": if diarytime.find(":") == -1: raise utils.ASMValidationError(i18n._("Invalid time, times should be in HH:MM format", l)) if not utils.is_numeric(diarytime.replace(":", "")): raise utils.ASMValidationError(i18n._("Invalid time, times should be in HH:MM format", l)) linkinfo = get_link_info(dbo, linktypeid, linkid) diaryid = db.get_id(dbo, "diary") sql = db.make_insert_user_sql(dbo, "diary", username, ( ( "ID", db.di(diaryid)), ( "LinkID", db.di(linkid) ), ( "LinkType", db.di(linktypeid) ), ( "LinkInfo", db.ds(linkinfo) ), ( "DiaryDateTime", utils.df_dt(data, "diarydate", "diarytime", l) ), ( "DiaryForName", utils.df_t(data, "diaryfor") ), ( "Subject", utils.df_t(data, "subject") ), ( "Note", utils.df_t(data, "note") ), ( "DateCompleted", utils.df_d(data, "completed", l) ) )) db.execute(dbo, sql) audit.create(dbo, username, "diary", str(diaryid)) return diaryid
def update_diary_from_form(dbo, username, data): """ Updates a diary note from form data """ l = dbo.locale diaryid = utils.df_ki(data, "diaryid") if utils.df_ks(data, "diarydate") == "": raise utils.ASMValidationError(i18n._("Diary date cannot be blank", l)) if utils.df_kd(data, "diarydate", l) is None: raise utils.ASMValidationError(i18n._("Diary date is not valid", l)) if utils.df_ks(data, "subject") == "": raise utils.ASMValidationError( i18n._("Diary subject cannot be blank", l)) if utils.df_ks(data, "note") == "": raise utils.ASMValidationError(i18n._("Diary note cannot be blank", l)) diarytime = utils.df_ks(data, "diarytime").strip() if diarytime != "": if diarytime.find(":") == -1: raise utils.ASMValidationError( i18n._("Invalid time, times should be in HH:MM format", l)) if not utils.is_numeric(diarytime.replace(":", "")): raise utils.ASMValidationError( i18n._("Invalid time, times should be in HH:MM format", l)) sql = db.make_update_user_sql( dbo, "diary", username, "ID=%d" % diaryid, (("DiaryDateTime", utils.df_dt(data, "diarydate", "diarytime", l)), ("DiaryForName", utils.df_t(data, "diaryfor")), ("Subject", utils.df_t(data, "subject")), ("Note", utils.df_t(data, "note")), ("Comments", utils.df_t(data, "comments")), ("DateCompleted", utils.df_d(data, "completed", l)))) preaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) db.execute(dbo, sql) postaudit = db.query(dbo, "SELECT * FROM diary WHERE ID=%d" % diaryid) audit.edit(dbo, username, "diary", audit.map_diff(preaudit, postaudit))