Ejemplo n.º 1
0
def list(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	db = jodb.connect()
	tasks = db.query("SELECT t.tid, t.descr, t.sql, COUNT(DISTINCT tw.wid) FROM task t " +
	                 "LEFT JOIN task_word tw ON (t.tid = tw.tid) " +
		       "GROUP BY t.tid, t.descr, t.sql ORDER BY t.tid")
	if tasks.ntuples() == 0:
		joheaders.error_page(req, _(u'There are no tasks.'))
		return '\n'
	joheaders.page_header_navbar_level1(req, _(u"tasks"), uid, uname)
	jotools.write(req, u"<p>%s:</p>\n" % _(u'Choose a task'))
	jotools.write(req, (u'<table class="border"><tr><th>%s</th><th>%s</th>' +
	                   u'<th>%s *</th><th>%s *</th></tr>\n') \
		         % (_(u'Task'), _(u'Total words'), _(u'Words left'), _(u'Completed')))
	for task in tasks.getresult():
		wordcount = db.query("SELECT COUNT(*) FROM (%s) AS q" % task[2]).getresult()[0][0]
		jotools.write(req, u'<tr><td><a href="work?tid=%i">' % task[0])
		jotools.write(req, u'%s</a></td>' % jotools.escape_html(unicode(task[1],'UTF-8')))
		jotools.write(req, u'<td>%i</td>' % wordcount)
		jotools.write(req, u'<td>%i</td>' % (wordcount - task[3]))
		if wordcount == 0: pleft = u'-'
		else: pleft = task[3] * 100 / wordcount
		jotools.write(req, u'<td>%s %%</td></tr>\n' % pleft)
	jotools.write(req, u"</table>\n")
	# "Words left" is an approximation, because all of the checked words may not belong to
	# this task any more. Calculating the exact numbers is too slow to do here.
	jotools.write(req, u"<p>*) %s.</p>" % _(u'Number of words left is an estimate'))
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 2
0
def _html(req, db, query):
	offset_s = `jotools.toint(jotools.get_param(req, 'offset', u'0'))`
	limit_s = `jotools.toint(jotools.get_param(req, 'limit', u'200'))`
	if limit_s == u'0': limit_s = u'ALL'
	
	param_s = u''
	for field in req.form.list:
		if not field.name in ['limit', 'offset'] and jotools.checkid(field.name):
			param_s = param_s + field.name + u'=' + jotools.get_param(req, field.name, u'') + u'&'
	
	results = db.query("%s LIMIT %s OFFSET %s" % (query, limit_s, offset_s))
	if results.ntuples() == 0:
		joheaders.error_page(req, _(u'No matching words were found'))
		return "\n"
	elif results.ntuples() == 1:
		joheaders.redirect_header(req, _config.WWW_ROOT_DIR + "/word/edit?wid=%i" \
		                               % results.getresult()[0][0])
		return "\n"
	else:
		(uid, uname, editable) = jotools.get_login_user(req)
		joheaders.page_header_navbar_level1(req, _('Search results'), uid, uname)
		jotools.write(req, u'<table><tr><th>%s</th><th>%s</th></tr>\n' \
		                   % (_("Word"), _("Word class")))
		for result in results.getresult():
			jotools.write(req, _print_html_line(db, result[0],
			              unicode(result[1], 'UTF-8'),
				    unicode(result[2], 'UTF-8')))
		jotools.write(req, u"</table>\n")
		if not limit_s == u'ALL' and results.ntuples() == jotools.toint(limit_s):
			jotools.write(req, (u'<p><a href="wlist?%soffset=%i&limit=%s">' +
			              u"%s ...</a></p>\n") % (param_s, int(offset_s)+int(limit_s),
				    limit_s, _(u'More results')))	
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 3
0
def categories(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	if not editable:
		joheaders.error_page(req, _(u'You are not allowed to edit data'))
		return '\n'
	db = jodb.connect()
	results = db.query("SELECT coalesce(info, ''), count(*) FROM raw_word " +
	                   "WHERE processed = FALSE " +
	                   "GROUP BY coalesce(info, '') " +
	                   "ORDER BY coalesce(info, '') ")
	if results.ntuples() == 0:
		joheaders.error_page(req, _(u'There are no words to be added'))
		return '\n'
	joheaders.page_header_navbar_level1(req, _(u"Add words"), uid, uname)
	jotools.write(req, u"<p>%s:</p>\n" \
	                   % _(u'Choose a category from which you want to add words'))
	jotools.write(req, u"<table><tr><th>%s</th><th>%s</th></tr>\n" \
	                   % (_(u'Category'), _(u'Words left')))
	for result in results.getresult():
		cat = unicode(result[0], 'UTF-8')
		if cat == u'': cats = u'(' + _(u'no category') + u')'
		else: cats = cat
		jotools.write(req, (u'<tr><td><a href="add_from_db?category=%s">%s</a></td>' +
		                    u'<td>%i</td></tr>\n') \
		  % (jotools.escape_url(result[0]), jotools.escape_html(cats), result[1]))
	jotools.write(req, u"</table>\n")
	jotools.write(req, u'<p><a href="add_from_db">%s ...</a></p>\n' % _(u'All words'))
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 4
0
def form(req):
	db = jodb.connect()
	(uid, uname, editable) = jotools.get_login_user(req)
	joheaders.page_header_navbar_level1(req, _(u'Search database'), uid, uname)
	jotools.write(req, u'<form method="get" action="wlist">\n<p>')
	jotools.write(req, u'<label>%s: <input type="text" name="word" /></label></p>\n' % _(u'Word'))
	jotools.write(req, u'<p><label><input type="checkbox" name="wordre" /> %s</label>\n' \
	              % _(u'Use regular expression'))
	jotools.write(req, u' <b>%s</b> <label><input type="checkbox" name="wordsimplere" /> %s</label><br />\n' \
	              % (_(u'or'), _(u'Case insensitive search')))
	jotools.write(req, u'<label><input type="checkbox" name="altforms" /> %s</label></p>\n' \
	              % _(u'Search from alternative spellings'))
	
	wclasses = db.query("SELECT classid, name FROM wordclass ORDER BY classid").getresult()
	jotools.write(req, u'<h2>%s</h2>\n' % _(u'Word class'))
	jotools.write(req, u'<p>%s ' % _(u'Word class is'))
	jotools.write(req, u'<select name="wordclass">\n')
	jotools.write(req, u'<option selected="selected" value="">(%s)</option>\n' % _(u'any'))
	for (classid, name) in wclasses:
		jotools.write(req, u'<option value="%i">%s</option>\n' % (classid, unicode(name, 'UTF-8')))
	jotools.write(req, u'</select></p>\n')
	
	textattrs = db.query("SELECT aid, descr FROM attribute WHERE type = 1 ORDER BY descr, aid").getresult()
	jotools.write(req, u'<h2>%s</h2>\n' % _(u'Text attributes'))
	jotools.write(req, u'<p><select name="textaid">\n')
	jotools.write(req, u'<option selected="selected" value="">(%s)</option>\n' % _(u'select attribute'))
	for (aid, dsc) in textattrs:
		jotools.write(req, u'<option value="%i">%s</option>\n' % (aid, unicode(dsc, 'UTF-8')))
	jotools.write(req, u'</select> %s <input type="text" name="textvalue" /><br />\n' % _(u'is'))
	
	flagattrs = db.query("SELECT aid, descr FROM attribute WHERE type = 2 ORDER BY descr, aid").getresult()
	jotools.write(req, u'</p><h2>%s</h2>' % _(u'Flags set'))
	jotools.write(req, u'<ul class="cblist">')
	for (aid, dsc) in flagattrs:
		jotools.write(req, u'<li><label><input type="checkbox" name="flagon%i" />%s</label></li>\n' \
		              % (aid, unicode(dsc, 'UTF-8')))
	jotools.write(req, u'</ul>\n')
	jotools.write(req, u'<h2>%s</h2>' % _(u'Flags not set'))
	jotools.write(req, u'<ul class="cblist">')
	for (aid, dsc) in flagattrs:
		jotools.write(req, u'<li><label><input type="checkbox" name="flagoff%i" />%s</label></li>\n' \
		              % (aid, unicode(dsc, 'UTF-8')))
	jotools.write(req, u'</ul>\n')
	
	jotools.write(req, u'<h2>%s</h2>\n<p>' % _(u'Output type'))
	for (tname, tdesc) in jooutput.list_supported_types():
		if tname == 'html': selected = u'checked="checked"'
		else: selected = u''
		jotools.write(req, (u'<label><input type="radio" name="listtype" value="%s" %s />' +
		                    u'%s</label><br />\n') % (tname, selected, tdesc))
	jotools.write(req, u'</p><p><input type="submit" value="%s" /><input type="reset" value="%s" /></p>\n' \
	              % (_(u'Search'), _(u'Reset')))
	jotools.write(req, u'</form>\n')
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 5
0
def add_from_db(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	if not editable:
		joheaders.error_page(req, _(u'You are not allowed to edit data'))
		return '\n'
	if req.method != 'GET':
		joheaders.error_page(req, _(u'Only GET requests are allowed'))
		return '\n'
	db = jodb.connect()
	words_per_page = 15
	category = jotools.get_param(req, 'category', None)
	if category == None: condition = ""
	else: condition = "AND coalesce(info, '') = '%s'" \
	                  % jotools.escape_sql_string(category)
	results = db.query("SELECT count(*) FROM raw_word WHERE processed = FALSE %s" \
	                   % condition)
	nwords = results.getresult()[0][0]
	if nwords <= words_per_page: limit = ""
	else: limit = "LIMIT %i OFFSET %i" % (words_per_page,
	              random.randint(0, nwords - words_per_page))
	results = db.query(("SELECT word, coalesce(notes, '') FROM raw_word " +
	                    "WHERE processed = FALSE %s " +
	                    "ORDER BY word %s") % (condition, limit))
	if results.ntuples() == 0 and category == None:
		joheaders.error_page(req, _(u'There are no words to be added'))
		return '\n'
	if results.ntuples() == 0 and category != None:
		joheaders.error_page(req, _(u'There are no words to be added') + u' ' +
		          _(u'in category %s') % jotools.escape_html(category))
		return '\n'
	class_res = db.query("select classid, name from wordclass").getresult()
	joheaders.page_header_navbar_level1(req, _(u"Add words"), uid, uname)
	jotools.write(req, u'<form method="post" action="add">\n')
	jotools.write(req, u'<table class="border">\n')
	jotools.write(req, u'<tr><th>%s</th><th>%s</th><th>%s</th></tr>\n' \
	                   % (_(u'Word'), _(u'Word class'), _(u'Notes')))
	i = 0
	for result in results.getresult():
		word = unicode(result[0], 'UTF-8')
		notes = unicode(result[1], 'UTF-8')
		jotools.write(req, u'<tr><td><input type="hidden" name="origword%i" value=%s />' \
			                   % (i, jotools.escape_form_value(word)))
		jotools.write(req, u'<input type="text" name="word%i" value=%s /></td><td>' \
		                   % (i, jotools.escape_form_value(word)))
		jotools.write(req, _get_class_selector(class_res, None, i, True))
		jotools.write(req, u'</td><td>')
		jotools.write(req, jotools.escape_html(notes))
		jotools.write(req, u'</td></tr>\n')
		i = i + 1
	jotools.write(req, u'</table>\n' +
	                   u'<p><input type="submit" value="%s"></p></form>\n' % _(u"Add words"))
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 6
0
def passwdform(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	if uid == None:
		joheaders.error_page(req, _(u'You must be logged in to do this'))
		return '\n'
	joheaders.page_header_navbar_level1(req, _(u'Change password'), uid, uname)
	jotools.write(req, u'''
<form method="post" action="changepasswd">
<table>
<tr><td>%s</td><td><input type="password" name="oldpw" /></td></tr>
<tr><td>%s</td><td><input type="password" name="newpw" /></td></tr>
</table>
<input type="submit" value="%s" />
</form>
'''        % (_(u'Old password'), _(u'New password'), _(u'Change password')))
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 7
0
def add_manual(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	if not editable:
		joheaders.error_page(req, _(u'You are not allowed to edit data'))
		return '\n'
	if req.method != 'GET':
		joheaders.error_page(req, _(u'Only GET requests are allowed'))
		return '\n'
	db = jodb.connect()
	words_per_page = 15
	joheaders.page_header_navbar_level1(req, _(u"Add words"), uid, uname)
	jotools.write(req, u'<form method="post" action="add">\n' +
	                   u'<table class="border">\n<tr><th>%s</th><th>%s</th></tr>\n' \
	                   % (_(u'Word'), _(u'Word class')))
	_add_entry_fields(req, db, None, words_per_page)
	jotools.write(req, u'</table>\n' +
	                   u'<p><input type="submit" value="%s"></p></form>\n' % _(u"Add words"))
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 8
0
def addform(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	if not jotools.is_admin(uid):
		joheaders.error_page(req, _(u'You must be an administrator to do this'))
		return '\n'
	joheaders.page_header_navbar_level1(req, _(u'Add user'), uid, uname)
	jotools.write(req, u'''
<form method="post" action="add">
<table>
<tr><td>%s</td><td><input type="text" name="firstname" /></td></tr>
<tr><td>%s</td><td><input type="text" name="lastname" /></td></tr>
<tr><td>%s</td><td><input type="text" name="uname" /></td></tr>
<tr><td>%s</td><td><input type="text" name="email" /></td></tr>
<tr><td>%s</td><td><input type="text" name="passwd" /></td></tr>
</table>
<input type="submit" value="%s" />
</form>
'''        % (_(u'First name'), _(u'Last name'), _(u'Username'), _(u'Email address'),
              _(u'Password'), _(u'Add user')))
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 9
0
def index(req):
	db = jodb.connect()
	privdb = jodb.connect_private()
	(uid, uname, editable) = jotools.get_login_user(req)
	joheaders.page_header_navbar_level1(req, u"Ehdota uusia sanoja", uid, uname)
	
	word = jotools.get_param(req, "word", u"").strip()
	wtype = jotools.get_param(req, "type", u"").strip()
	comment = jotools.get_param(req, "comment", u"").strip()
	
	if word != u"":
		if not jotools.checkword(word):
			jotools.write(req, u'<p class="error">Sanassa on kiellettyjä merkkejä.</p>')
			_print_entry_form(req, db)
		else:
			db.query("BEGIN")
			error = _is_old_word(req, db, word)
			if error != None:
				jotools.write(req, u'<p class="error">%s</p>' % error)
				_print_entry_form(req, db)
			elif not (editable or _allow_new_word(req, privdb, True)):
				_print_error_forbidden(req)
			else:
				db.query("INSERT INTO raw_word(word, info, notes) " +
				         "VALUES('%s', '%s', '%s')" % \
				         (jotools.escape_sql_string(word),
				          jotools.escape_sql_string(wtype),
				          jotools.escape_sql_string(comment)))
				jotools.write(req, u'<p class="ok">Ehdotuksesi on tallennettu. ' +
				                   u'Kiitos avusta!</p>')
				_print_entry_form(req, db)
			db.query("COMMIT")
	
	elif editable or _allow_new_word(req, privdb, False):
		_print_entry_form(req, db)
	else:
		_print_error_forbidden(req)
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 10
0
def classlist(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	joheaders.page_header_navbar_level1(req, u'Etsi sanalle taivutusluokka', uid, uname)
	
	word = jotools.get_param(req, 'word', u'')
	if not jotools.checkword(word):
		joheaders.error_page(req, u'Sanassa on kiellettyjä merkkejä')
		return '\n'
	
	# Sanaa ei annettu, joten näytetään pelkkä lomake
	if len(word) == 0:
		_display_form(req, 1, u'-', u'')
		joheaders.page_footer_plain(req)
		return '\n'
	
	classid = jotools.toint(jotools.get_param(req, 'class', u'0'))
	if classid == 1:
		classdatafile = VOIKKO_DATA + "/subst.aff"
	elif classid == 3:
		classdatafile = VOIKKO_DATA + "/verb.aff"
	elif classid == 0:
		joheaders.page_footer_plain(req)
		return '\n'
	else:
		joheaders.error_page(req, u'Sanaluokkaa ei ole olemassa')
		return '\n'
	
	grad_type = jotools.get_param(req, 'gclass', u'-')
	if not grad_type in [u'-', u'av1', u'av2', u'av3', u'av4', u'av5', u'av6']:
		joheaders.error_page(req, u'Taivutusluokkaa ei ole olemassa')
		return '\n'
	if grad_type == u'-':
		grad_type_s = u''
	else:
		grad_type_s = u'-' + grad_type
	
	_display_form(req, classid, grad_type, word)
	
	word_classes = voikkoinfl.readInflectionTypes(classdatafile)
	
	for word_class in word_classes:
		if len(word_class.joukahainenClasses) == 0: continue
		infclass_main = word_class.joukahainenClasses[0]
		inflected_words = voikkoinfl.inflectWordWithType(word, word_class, infclass_main, grad_type)
		if inflected_words == []: continue
		
		previous_inflected = voikkoinfl.InflectedWord()
		inflist = []
		inflected_words.append(voikkoinfl.InflectedWord())
		jotools.write(req, '<hr /><h2 class="infclass">' + infclass_main + grad_type_s + '</h2>')
		if word_class.note != u'':
			jotools.write(req, u'<p>%s</p>\n' % word_class.note)
		jotools.write(req, u'<p>Kotus-luokka: %s</p>' % \
		              reduce(lambda x, y: u"%s, %s" % (x, y), word_class.kotusClasses))
		
		jotools.write(req, u'<table class="border">\n')
		for inflected_word in inflected_words:
			if previous_inflected.formName != inflected_word.formName:
				if previous_inflected.formName != u"" and len(inflist) > 0:
					if previous_inflected.isCharacteristic:
						infs = reduce(lambda x, y: u"%s, %s" % (x, y), inflist)
						jotools.write(req, (u"<tr><td>%s</td><td>%s</td></tr>\n" %
						          (previous_inflected.formName, infs)))
				inflist = []
				previous_inflected = inflected_word
			if not inflected_word.inflectedWord in inflist:
				inflist.append(inflected_word.inflectedWord)
		jotools.write(req, u'</table>\n')
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 11
0
def process_template(req, db, static_vars, template_name, lang, module, level):
	tmplfilename = _config.INSTALLATION_DIRECTORY + '/langpacks/' + \
	               lang + '/' + template_name + '.txt'
	tmplfile = codecs.open(tmplfilename, 'r', 'utf-8')
	var_re = re.compile("^(.*)\\$\\$(.*)\\$\\$(.*)$")
	func_re = re.compile("^(.*)\\((.*)\\)$")
	file_cont = True
	first_line = True
	cattributes = None
	while file_cont:
		# FIXME: only one variable/function allowed on one line
		line = tmplfile.readline()
		file_cont = line.endswith('\n')
		
		if line == u"@BEGIN IF_EDIT_ALLOWED\n":
			if not static_vars.has_key('EDITABLE') or not static_vars['EDITABLE']:
				while line.endswith('\n') and line != u"@END IF_EDIT_ALLOWED\n": line = tmplfile.readline()
			continue
		if line == u"@END IF_EDIT_ALLOWED\n": continue
		
		if line.startswith(u"@BEGIN ATTRIBUTE_ENCLOSURE "):
			if cattributes is None:
				cattributes = word_classes_for_attributes(db)
			aid = int(line[27:].strip())
			if static_vars['CLASSID'] not in cattributes[aid]:
				while line.endswith('\n') and line != u"@END ATTRIBUTE_ENCLOSURE\n": line = tmplfile.readline()
			continue
		if line == u"@END ATTRIBUTE_ENCLOSURE\n": continue

		var_match = var_re.match(line)
		line_str = u''
		if var_match != None:
			line_str = line_str + var_match.group(1)
			func_match = func_re.match(var_match.group(2))
			if func_match == None:
				line_str = line_str + unicode(static_vars[var_match.group(2)])
			else:
				paramlist = []
				for param in func_match.group(2).split(','):
					param = param.strip()
					if param == '':
						paramlist.append(None)
					elif param[0] in '0123456789':
						paramlist.append(int(param))
					else:
						paramlist.append(static_vars[param])
				retstr = _call_handler(db, module, func_match.group(1), paramlist)
				line_str = line_str + retstr
			line_str = line_str + var_match.group(3) + u'\n'
		else:
			line_str = line_str + line
		if first_line:
			if static_vars.has_key('UID'): uid = static_vars['UID']
			else: uid = 0
			if static_vars.has_key('UNAME'): uname = static_vars['UNAME']
			else: uname = 0
			if static_vars.has_key('WID'): wid = static_vars['WID']
			else: wid = 0
			if level == 0:
				joheaders.page_header_navbar_level0(req, line_str.strip(),
				                                    uid, uname)
			if level == 1:
				joheaders.page_header_navbar_level1(req, line_str.strip(),
				                                    uid, uname, wid)
			first_line = False
		else: write(req, line_str)
	tmplfile.close()
Ejemplo n.º 12
0
def listchanges(req, sdate = None, edate = None):
	db = jodb.connect()
	(uid, uname, editable) = jotools.get_login_user(req)
	joheaders.page_header_navbar_level1(req, _(u'List changes'), uid, uname)
	
	edt = datetime.datetime.now()
	sdt = edt - datetime.timedelta(days=1)
	if sdate != None:
		try:
			stime = time.strptime(sdate, u'%Y-%m-%d')
			sdt = datetime.datetime(*stime[0:5])
		except:
			jotools.write(req, "<p>%s</p>\n" % _("Invalid start date"))
	if edate != None:
		try:
			etime = time.strptime(edate, u'%Y-%m-%d')
			edt = datetime.datetime(*etime[0:5])
		except:
			jotools.write(req, "<p>%s</p>\n" % _("Invalid end date"))
	sdate_s = sdt.strftime('%Y-%m-%d')
	edate_s = edt.strftime('%Y-%m-%d')
	
	jotools.write(req, u"""
<form method="get" action="listchanges">
<label>%s <input type="text" name="sdate" value="%s"/></label><br />
<label>%s <input type="text" name="edate" value="%s"/></label><br />
<input type="submit" /> <input type="reset" />
</form>
	""" % (_(u'Start date'), sdate_s, _(u'End date'), edate_s))
	
	# Increase edt by one day to make the the SQL between operator act on timestamps
	# in a more intuitive way.
	edt = edt + datetime.timedelta(days=1)
	edate_s = edt.strftime('%Y-%m-%d')
	
	results = db.query("""
	SELECT u.uname, to_char(w.ctime, 'YYYY-MM-DD HH24:MI:SS'),
	       coalesce(u.firstname, ''), coalesce(u.lastname, ''),
	       '%s', NULL, w.wid, w.word
	FROM word w, appuser u WHERE w.cuser = u.uid AND w.ctime BETWEEN '%s' AND '%s'
	UNION
	SELECT u.uname, to_char(e.etime, 'YYYY-MM-DD HH24:MI:SS'),
	       coalesce(u.firstname, ''), coalesce(u.lastname, ''),
	       e.message, e.comment, w.wid, w.word
	FROM appuser u, event e, word w WHERE u.uid = e.euser AND e.eword = w.wid
	AND e.etime BETWEEN '%s' AND '%s'
	ORDER BY 2 DESC""" % (_(u'Word created').encode('UTF-8'), sdate_s, edate_s, sdate_s, edate_s));
	
	if results.ntuples() > 1000:
		jotools.write(req, u'<p>%s</p>' % _(u'Too many changes, use narrower date interval.'))
		joheaders.page_footer_plain(req)
		return '\n'
	retstr = u''
	for result in results.getresult():
		wordlink = u'<a href="../word/edit?wid=%i">%s</a>' \
		           % (result[6], jotools.escape_html(unicode(result[7], 'UTF-8')))
		date = result[1]
		user = jotools.escape_html(unicode(result[2], 'UTF-8')) + u" " + \
		       jotools.escape_html(unicode(result[3], 'UTF-8')) + u" (" + \
		       jotools.escape_html(unicode(result[0], 'UTF-8')) + u")"
		retstr = retstr + (u'<div class="logitem"><p class="date">%s %s %s</p>\n' \
		                   % (wordlink, user, date))
		if result[4] != None:
			msg = jotools.escape_html(unicode(result[4], 'UTF-8')).strip()
			msg = msg.replace(u'\n', u'<br />\n')
			retstr = retstr + u'<p class="logmsg">%s</p>\n' % msg
		if result[5] != None:
			comment = jotools.escape_html(unicode(result[5], 'UTF-8')).strip()
			comment = comment.replace(u'\n', u'<br />\n')
			comment = jotools.comment_links(comment)
			retstr = retstr + u'<p class="comment">%s</p>\n' % comment
		retstr = retstr + u"</div>\n"
	
	jotools.write(req, retstr)
	joheaders.page_footer_plain(req)
	return '\n'
Ejemplo n.º 13
0
def add(req):
	(uid, uname, editable) = jotools.get_login_user(req)
	if not editable:
		joheaders.error_page(req, _(u'You are not allowed to edit data'))
		return '\n'
	db = jodb.connect()
	if req.method != 'POST':
		joheaders.error_page(req, _(u'Only POST requests are allowed'))
		return '\n'
	db.query("BEGIN")
	if jotools.get_param(req, 'confirm', u'') == u'on': confirm = True
	else: confirm = False
	nwordlist = []
	added_count = 0
	need_confirm_count = 0
	i = -1
	while True:
		i = i + 1
		nword = jotools.get_param(req, 'word%i' % i, u'')
		if nword == u'': break
		word = {'word': nword, 'try_again': True, 'confirmed': False, 'wid': None}
		word['oword'] = jotools.get_param(req, 'origword%i' % i, None)
		nclass = jotools.get_param(req, 'class%i' % i, None)
		if not nclass in [None, u'']: nclass = jotools.toint(nclass)
		else: nclass = None
		word['cid'] = nclass
		if confirm and nclass != 0 and jotools.get_param(req, 'confirm%i' % i, u'') != u'on':
			word['error'] = _(u'Word was not added')
			word['try_again'] = False
		if jotools.get_param(req, 'confirm%i' % i, u'') == u'on': word['confirmed'] = True
		stored_word = _store_word(db, word, uid)
		if stored_word['wid'] != None: added_count = added_count + 1
		if stored_word['try_again']: need_confirm_count = need_confirm_count + 1
		nwordlist.append(stored_word)
	db.query("COMMIT")
	if added_count == 1 and len(nwordlist) == 1:
		# No confirmation screen if exactly 1 word was successfully added
		joheaders.redirect_header(req, "edit?wid=%i" % nwordlist[0]['wid'])
		return '\n'
	joheaders.page_header_navbar_level1(req, _(u"Add words"), uid, uname)
	if need_confirm_count > 0:
		jotools.write(req, u'<p>' + _(u'''Adding some words failed or requires confirmation.
Make the required changes and mark the words that you still want to add.''') + u'</p>')
		jotools.write(req, u'<form method="post" action="add">\n')
		jotools.write(req,
		  u'<table class="border"><tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n' \
		  % (_(u'Word'), _(u'Word class'), _(u'Confirm addition'), _(u'Notes')))
		_add_entry_fields(req, db, nwordlist, None)
		jotools.write(req, u'</table>\n<p>' +
		                   u'<input type="hidden" name="confirm" value="on">' +
		                   u'<input type="submit" value="%s"></p></form>\n' % _(u'Continue'))
		joheaders.page_footer_plain(req)
		return '\n'
	else:
		jotools.write(req, u'<p>%s:</p>' % _(u'The following changes were made'))
		jotools.write(req,
		  u'<table class="border"><tr><th>%s</th><th>%s</th><th>%s</th></tr>\n' \
		  % (_(u'Word'), _(u'Word class'), _(u'Notes')))
		_add_entry_fields(req, db, nwordlist, None)
		jotools.write(req, u'</table>\n')
		jotools.write(req, u'<p><a href="../">%s ...</a></p>\n' \
		                   % _(u'Back to main page'))
		joheaders.page_footer_plain(req)
		return '\n'