def do_showmerge(self, ctx, ignore): if not ctx.locals.key_a or not ctx.locals.key_b: raise page_common.PageError('Select an A and B form') key_a = int(ctx.locals.key_a) key_b = int(ctx.locals.key_b) if key_a == key_b: raise page_common.PageError('Select separate A and B forms') case_id = ctx.locals.formmerge_record.case_row.case_id merge = formmerge.FormMerge(case_id, key_a, key_b) ctx.push_page('mergeform', merge)
def do_deploy(self, ctx, ignore): if not ctx.locals.diffs.okay(): raise page_common.PageError('Resolve column incompatibilities first') if ctx.locals.diffs.is_drop_all(): raise page_common.PageError(null_rollforward_msg) rollforward_map = ctx.locals.diffs.rollforward_map() self.check_unsaved_or_confirmed(ctx) if ctx.locals.form_meta.has_changed(): ctx.locals.form_meta.save(globals.db) ctx.locals.form_meta.deploy(globals.db, rollforward_map) ctx.pop_page()
def do_showmerge(self, ctx, ignore): case_id_a, case_id_b = ctx.locals.case_id_a, ctx.locals.case_id_b try: case_id_a = int(case_id_a) except ValueError: raise page_common.PageError('Invalid ID: %s' % case_id_a) try: case_id_b = int(case_id_b) except ValueError: raise page_common.PageError('Invalid ID: %s' % case_id_b) merge = personmerge.merge_case_persons(case_id_a, case_id_b) ctx.push_page('mergeperson', merge)
def commit(self, ctx): group = ctx.locals.group if not group.group_name: raise page_common.PageError('Please specify a name') if not group.description: raise page_common.PageError('Please specify a description') group.rights = str(credentials.Rights(ctx.locals.rights)) is_new = group.is_new() ctx.admin_log(group.db_desc()) group.db_update() globals.db.commit() units = credentials.group_units(globals.db, group.group_id) globals.notify.notify('units', *units)
def do_login(self, ctx, ignore): cred = ctx.locals._credentials assert cred.user if not ctx.locals.unit_id: raise page_common.PageError('Please select a unit') cred.set_unit(globals.db, int(ctx.locals.unit_id)) ctx.set_page('main')
def do_save(self, ctx, ignore): if (not ctx.locals.reportparams.label or not ctx.locals.reportparams.label.strip()): ctx.locals.report_tabs.select('info') raise page_common.PageError('A report name must be specified') ctx.locals.reportparams.save(ctx.locals._credentials) globals.db.commit() ctx.add_message('Report parameters saved')
def do_report_import(self, ctx, ignore): if 'EXPORT' not in ctx.locals._credentials.rights: return if len(ctx.locals.report_import_file) != 1: raise page_common.PageError('Choose one file') reportparams = reports.parse_file( ctx.locals.report_syndrome_id, ctx.locals.report_import_file[0].file) ctx.push_page('report_edit', reportparams) ctx.locals.report_upload_mode = False
def do_imprules(self, ctx, ignore): if ctx.locals.confirm is not None: new_editor = ctx.locals.confirm.editor else: if len(ctx.locals.imprules_file) != 1: raise page_common.PageError('Choose one file') file = ctx.locals.imprules_file[0].file syndrome_id = ctx.locals.editor.syndrome_id new_editor = editor.load_file(ctx, syndrome_id, None, file) if ctx.locals.editor.has_changed(): raise page_common.ConfirmSave(editor=new_editor) ctx.locals.editor = new_editor ctx.locals.dataimp_tabs.select('params')
def do_delete(self, ctx, ignore): if ctx.locals.queue.queue_id: if ctx.locals.queue_stats.active: raise page_common.PageError( 'workqueue %r cannot be deleted as it has outstanding tasks' % ctx.locals.queue.name) if not self.confirmed: raise ConfirmDelete( message= 'Deleting this task queue will irreversably delete %d completed task records' % ctx.locals.queue_stats.completed) else: tasks.delete_queue(ctx.locals.queue.queue_id) globals.db.commit() globals.notify.notify('workqueues', ctx.locals.queue.queue_id) ctx.add_message('Deleted queue %r' % ctx.locals.queue.name) ctx.pop_page()
def commit(self, ctx): unit = ctx.locals.unit if unit.name: unit.name = unit.name.strip() if not unit.name: raise page_common.PageError('A unit name must be given') unit.rights = str(credentials.Rights(ctx.locals.urights)) ctx.admin_log(unit.db_desc()) unit.db_update() ctx.locals.group_edit.set_key(unit.unit_id) ctx.admin_log(ctx.locals.group_edit.db_desc()) ctx.locals.group_edit.db_update() globals.db.commit() ctx.add_message('Updated %s %r' % (config.unit_label.lower(), unit.name)) globals.notify.notify('units', unit.unit_id) globals.notify.notify('unit_groups', unit.unit_id) globals.notify.notify('syndrome_units', unit.unit_id)
def page_process(self, ctx): ctx.locals.editor.update_rules() src_file = getattr(ctx.locals, 'src_file', None) if src_file: if len(src_file) > 1: raise page_common.PageError('Choose one file') new_dataimp_src = DataImpSrc(src_file[0].filename, src_file[0].file) if new_dataimp_src: if ctx.locals.dataimp_src: ctx.locals.dataimp_src.release() ctx.locals.dataimp_src = new_dataimp_src self.update_preview(ctx) if (ctx.locals.dataimp_src.preview and ctx.locals.dataimp_src.preview.n_rows > 1000): ctx.msg( 'warn', 'WARNING: importing a large number of records' ' may be very slow and time-outs may occur') page_common.PageOpsBase.page_process(self, ctx)
def page_enter(ctx): if not ctx.locals.syndromes: raise page_common.PageError('No %s' % config.syndrome_label)
def do_recreate(self, ctx, ignore): try: ctx.locals.diffs.recreate(ctx.locals.old_select, ctx.locals.new_select) except tablediff.TableDiffError, e: raise page_common.PageError(str(e))
def do_mergeforms(self, ctx, ignore): if not ctx.locals.case.can_merge_forms(): raise page_common.PageError('There are no forms eligible to ' 'be merged') self.check_unsaved_or_confirmed(ctx) ctx.push_page('selmergeforms', ctx.locals.case)
def normalise_date(label, dt): if dt is not None: try: return str(datetime.mx_parse_datetime(dt)) except datetime.Error, e: raise page_common.PageError('%s: %s' % (label, e))
def validate(self, ctx): ctx.locals.form_errors = ctx.locals.edit_form.validate() if ctx.locals.form_errors: raise page_common.PageError('There are errors in some fields -' ' please fix them and try again')