Exemple #1
0
def show_text (name_in_url, read_only = False, template = text_with_edit_tpl, mode_switchers = True):
 
  try:
     text = db.Text.get( db.Text.name_in_url == name_in_url )#foreign key refers to the whole row in peewee
  except db.Text.DoesNotExist:
     abort(404,"File not Found")     

  fragments = []
  for row in db.Fragment.select().where( db.Fragment.text==text ).order_by(db.Fragment.number_in_text):
     frag_vars = json.loads(row.content)
     lang_keys = json.loads(row.lang_keys)
     fragment = {}
  
     variants = []
     for k in [lang['key'] for lang in lang_keys]:#list comprehension, 
       variant = {}
     
       variant['content'] = output_fragment (k+str(row.id),accents(frag_vars[k]))
       if detect_hebrew(variant['content']):
          variant['class_name'] = k + ' hebrew'
       else:
          variant['class_name'] = k

       variant['var_id'] = k+str(row.id)
       variants = variants + [variant]

     fragment['variant'] = variants
     fragment['id'] = row.id
     fragments = fragments + [fragment]

  html = rr.render(template,{'root': root, "welcome":generateWelcome(), 'name_in_url': name_in_url, 'fragment': fragments, 'read_only': read_only , 'text_title': text.name, 'mode_switchers': mode_switchers})

  return html_code (html, css_files=[root+'css/global.css',root+'css/phrases.css'], 
     js_files=[root+'jquery-1.11.3.min.js',root+'%s/text_name.js' % name_in_url, root+'phrases.js']) 
Exemple #2
0
def new_fragment(name_in_url):
  aaa.require(fail_redirect='/login')
  try:
    text=db.Text.select().where(db.Text.name_in_url==name_in_url).get()   
  except db.Text.DoesNotExist:
    abort(404,"File not Found")

  lang_keys = json.loads(text.lang_keys)
  form_html=rr.render(form_tpl_new_fragment, {'url':root+name_in_url, "welcome":generateWelcome(), 'new_fragment_form':new_fragment_form(lang_keys), 'text_title': text.name, 'name_in_url': name_in_url})
  return html_code (form_html, head_code='<title>Add new fragment</title>',css_files=\
    [root+'css/global.css',root+'css/new_fragment.css'])
Exemple #3
0
def edit_fragment_text (id):
  aaa.require(fail_redirect='/login')
  try:
   row=db.Fragment.get(db.Fragment.id==id)
  except db.Fragment.DoesNotExist:
    abort(404,"File not Found")

  frag_vars = json.loads(row.content)
  lang_keys = json.loads(row.lang_keys)
  form_html=rr.render(form_tpl_edit_fragment, {'id':id, "welcome":generateWelcome(), 'edit_fragment_form':edit_fragment_form(lang_keys, frag_vars), 'text_title': row.text.name, 'name_in_url': row.text.name_in_url, 'confirm_block':(len(json.loads(row.connections))!=0)})
  return html_code (form_html, head_code='<title>Edit fragment</title>',css_files=\
    [root+'css/global.css'])
Exemple #4
0
def editor (id):
   aaa.require(fail_redirect='/login')
   html =''
   row=db.Fragment.get(db.Fragment.id==id)
   frag_vars = json.loads(row.content)
   lang_keys = json.loads(row.lang_keys)
   html = html + "\n".join ( [("<div class=\"%s\" id=\"%s\" >" % (k,k+str(row.id)))+output_fragment (k+str(row.id),accents(frag_vars[k]))+"</div>" for k in [lang['key'] for lang in lang_keys] ] )
   html='<div class="button" id="edit_button"> Edit group </div> <div class="button" id="save_button"> Save group </div> <div class="button" id="new_button"> New group </div> <div class="button" id="read_mode"> Read mode </div> <div class="button" id="edit_text"> Edit text </div>'+wrap_in_div('text',html)+'<div class="comment"></div><div id="comments"></div>'
   html=wrap_in_div('main', html)
   html=page_template(menu_array, html, [{'title':'Texts', 'url': root+'texts.html'}, {'title':row.text.name, 'url':root+'edit/%s.html#fragment_%s'%(row.text.name_in_url,id)}, {'title':'Edit fragment', 'url':''}])
   return html_code (html, css_files=[root+'css/editor.css', root+'css/global.css', root+'cleditor/jquery.cleditor.css'], 
     js_files=[root+'jquery-1.11.3.min.js', root+'editor.js', root+'cleditor/jquery.cleditor.js'], head_code='<title>Connections Editor</title>')
Exemple #5
0
def show_text (name_in_url, read_only = False, template = text_with_edit_tpl, mode_switchers = True):
 
  try:
     text = db.Text.get( db.Text.name_in_url == name_in_url )#foreign key refers to the whole row in peewee
  except db.Text.DoesNotExist:
     abort(404,"File not Found")    
  #text.user_id, text.user))
  #not read_only and 
  #if(text.user_id != aaa.current_user.id):
  #	print('ai ai ai') 
  eml = 'anonymous'
  show_edit = False
  if not aaa.user_is_anonymous:
  	eml = aaa.current_user.email_addr
  	tEml = text.user.email_addr
  	if eml==tEml:
  		show_edit = read_only #show edit link, when the author is in session
  	elif not read_only:#only author can edit
  		abort(401,'only author can edit this text')
  #print("show_text of {} user_id {} email {} vs current_user.email {}".format(name_in_url, text.user_id, text.user.email_addr,eml))
  fragments=[]
  for row in db.Fragment.select().where( db.Fragment.text==text ).order_by(db.Fragment.number_in_text):
     frag_vars = json.loads(row.content)
     lang_keys = json.loads(row.lang_keys)
     fragment = {}
  
     variants = []
     for k in [lang['key'] for lang in lang_keys]:#list comprehension, 
       variant = {}
     
       variant['content'] = output_fragment (k+str(row.id),accents(frag_vars[k]))
       if detect_hebrew(variant['content']):
          variant['class_name'] = k + ' hebrew'
       else:
          variant['class_name'] = k

       variant['var_id'] = k+str(row.id)
       variants = variants + [variant]

     fragment['variant'] = variants
     fragment['id'] = row.id
     fragments = fragments + [fragment]

  html = rr.render(template,{'root': root, "welcome":generateWelcome(), 'name_in_url': name_in_url, 'fragment': fragments, 'read_only': read_only, 'show_edit': show_edit, 'text_title': text.name, 'mode_switchers': mode_switchers})

  return html_code (html, css_files=[root+'css/global.css',root+'css/phrases.css'], 
     js_files=[root+'jquery-1.11.3.min.js',root+'%s/text_name.js' % name_in_url, root+'phrases.js']) 
Exemple #6
0
def new_text():
  aaa.require(fail_redirect='/login')
  return html_code (new_text_form, head_code='<title>Add new text</title>',css_files=[root+'css/global.css'])
Exemple #7
0
def texts():
  
  tpl= texts_list_tpl
  rows=db.Text.select().where((db.Text.name_in_url != 'trash') and (db.Text.visible == 1)).order_by(db.Text.order)
  return html_code (rr.render(tpl,{"text": rows, "root": root, "welcome":generateWelcome()}), head_code='<title>Texts</title>',css_files=[root+'css/global.css',root+'css/text_list.css'])
Exemple #8
0
def about():
  tpl=about_tpl
  return html_code (rr.render(tpl, {"root":root, "welcome":generateWelcome()}),head_code='<title>About the project</title>',css_files=[root+'css/global.css',root+'css/about.css'])