def get_fields(request, base, table): """ Return Dajax json for fields of selected table """ dajax = Dajax() query = """ SELECT group_concat(column_name) AS cols FROM information_schema.COLUMNS WHERE table_schema='%s' AND table_name = '%s'""" % (base, table) fields = utmGet(query)[0] fields = fields['cols'].split(',') out = "" if fields: for field in fields: out += "<option value='%s'>%s</option>" % (field, field) dajax.assign('#fields_ins', 'innerHTML', out) dajax.assign('#fields_upd', 'innerHTML', out) dajax.script('$("#fields_ins").trigger("liszt:updated")') dajax.script('$("#fields_upd").trigger("liszt:updated")') return dajax.json()
def get_files(request, form): """ Return Dajax json for changed files by tasknum """ # form = {"task_num": "1800", "repo": "beta_building", "hide_sql": "1", "branch": "default", "csrfmiddlewaretoken": "TQ9OoZ0ciWUzqIquytVtL12eDmU4hKyq", "start_date": "01.01.12"} dajax = Dajax() form = QueryDict(form).dict() os.chdir(HG_ROOT + form['repo']) try: os.system('hg pull') # i hope this unnec[c]essary except: pass repo = hglib.open(HG_ROOT + form['repo']) repo.pull() d, m, y = form['start_date'].split('.') start_date = '%s/%s/%s' % (m, d, y) log = repo.log(date='>%s' % start_date, branch=form['branch'], keyword='#%s' % form['task_num']) query = 'SELECT * FROM redmine.issues where id = %s' % form['task_num'] task = utmGet(query, base='redmine')[0] files = [] for commit in log: p = Popen(["hg", "log", "-M", "-r", commit[0], "--template", "'{node}%{files}'"], stdin=PIPE, stdout=PIPE) # hglib's abilities so poor=( resp = p.communicate() if resp and resp[0]: rev, fs = resp[0].split('%') files.append({'rev': rev.strip("'")[:12], 'files': []}) for f in fs.split(' '): f = f.strip("'") if ('hide_sql' in form and not f.endswith('.sql')) or 'hide_sql' not in form: files[-1]['files'].append(f) file_list = {} for rev in files: for file_name in rev['files']: if not file_name in file_list: file_list[file_name] = rev['rev'] args = {'log': log, 'task': task, 'files': file_list.items(), 'task_num': form['task_num'], 'repo': form['repo']} html = render_to_string('releases/list.html', args, context_instance=RequestContext(request)) dajax.assign('#output', 'innerHTML', html) return dajax.json()
def get_script(request, guid): """ Return Dajax json for fields of selected table """ # import simplejson # return simplejson.dumps('fafadf') dajax = Dajax() out = '' query = """ SELECT item_body FROM __script_collection where guid = '%s'""" % (guid) out = utmGet(query)[0]["item_body"] out = out.replace("\n", "<br>") if not out: out = 'Body is empty.' dajax.assign('#output', 'innerHTML', out) return dajax.json()
def get_tables(request, base): """ Return Dajax json for tables of selected database """ dajax = Dajax() tables = [] try: _tables = utmGet('show tables in %s' % base) for table in _tables: tables.append(table.values()[0]) except: pass out = "<option>---</option>" if tables: for table in tables: out += "<option value='%s'>%s</option>" % (table, table) dajax.assign('#table_name', 'innerHTML', out) dajax.script('$("#table_name").trigger("liszt:updated")') return dajax.json()