def charger_ouvrage(rq): prp = json.loads(rq.text) sel_auteur = SELECT(name='auteur', id='auteur') sel_auteur <= (OPTION('{titre} {prenom} {particule} {nom}'.format( **auteur).replace("' ", "'"), value=auteur['id'], selected=(auteur['id'] == prp['auteur']['id'])) for auteur in json.loads(requete('/db/liste/auteurs'))) sel_editeur = SELECT(name='editeur', id='editeur') sel_editeur <= (OPTION(editeur['nom'], value=editeur['id'], selected=(editeur['id'] == prp['editeur']['id'])) for editeur in json.loads(requete('/db/liste/editeurs'))) bouton = BUTTON('Modifier') bouton.bind('click', lambda ev: enregistrer(ev, 'ouvrage')) return ( INPUT(type='hidden', value=str(prp['id']), id='id') + tableau([ [ 'Titre', INPUT( type='text', name='titre', value=prp['titre'], id='titre') ], ['Auteur', sel_auteur], ['Éditeur', sel_editeur], ], entete=False, trier=False) + bouton)
def init_show_hide(): # initialize options element = set() weapon = set() for char in characters: if char == 'traveler': continue element.add(characters[char]['element']) weapon.add(characters[char]['weapon']) # selected cst = SELECT(Id=f"selected", Class=f"save onehundred") for s in ['any', 'checked', 'unchecked']: cst <= OPTION(s.capitalize(), value=s) # element est = SELECT(Id=f"element", Class=f"save onehundred") for s in ['any'] + sorted(element): est <= OPTION(s.capitalize(), value=s) # weapon wst = SELECT(Id=f"weapon", Class=f"save onehundred") for s in ['any'] + sorted(weapon): wst <= OPTION(s.capitalize(), value=s) t = TABLE(TR(TH() + TH('Option'))) t <= TR(TD('Character', Class="right_text") + TD(cst)) t <= TR(TD('Element', Class="right_text") + TD(est)) t <= TR(TD('Weapon', Class="right_text") + TD(wst)) t <= TR(TD('Character Search', Class="right_text") + TD(INPUT(Type='text', Id="keywords") + BUTTON('x', Id='clear_keywords'))) doc['show_hide'] <= t + P("Note that all selections have to be true for a character to be visible. Additionally the keyword search overrides all other filter settings so clear it to use them.")
class BuscaAlimento(DIV): sel = None nutTab = None inText = None def __init__(self): DIV.__init__(self) #, style={'max-width':'90px'}) selTable = TABLE() self <= selTable self.inText = INPUT(Class="form-control") self.inText.bind('keyup', self.entrou) selTable <= TR(TD(P("Busca: ") + self.inText)) #,name="intext")) self.sel = SELECT(size=8, Class='form-control') # style={'max_width':'90px'}) self.sel.bind('input', self.selec) selTable <= TR(TD(self.sel)) self.sel.style.display = 'none' self.nutTab = MostraNut() self <= self.nutTab def entrou(self, event): if event.which == 13: req = ajax.ajax() req.bind('complete', self.complete) req.open('POST', '/nutsvc', True) req.set_header('content-type', 'application/x-www-form-urlencoded') d = {'op': 'QUERY', 'q': event.currentTarget.value} req.send(d) def complete(self, r): if r.status == 200 or r.status == 0: result = json.loads(r.text) if len(result) == 0: alert("Nenhum alimento encontrado") self.sel.style.display = 'none' return self.sel.clear() for l in result: self.sel.style.display = 'block' self.sel.style.width = '90pw' self.sel <= OPTION(l[1], value=l[0]) def selec(self, event): self.sel.style.display = 'none' #alert(dir(event.currentTarget)) #alert(event.currentTarget.options[event.currentTarget.selectedIndex].text) #alert(event.currentTarget.text[event.currentTarget.selectionRange]) #alert(dir(self.inText)) #self.inText.set_text(event.currentTarget.options[event.currentTarget.selectedIndex].text) self.inText.value = event.currentTarget.options[ event.currentTarget.selectedIndex].text medida = EscolheMedida(event.currentTarget.value, self.selected) self <= medida medida.showModal() def selected(self): alert("selected")
class BuscaAlimento(DIV): sel=None nutTab=None inText=None def __init__(self): DIV.__init__(self) #, style={'max-width':'90px'}) selTable = TABLE() self <= selTable self.inText = INPUT(Class="form-control") self.inText.bind('keyup',self.entrou) selTable<=TR(TD(P("Busca: ")+self.inText)) #,name="intext")) self.sel = SELECT(size=8,Class='form-control') # style={'max_width':'90px'}) self.sel.bind('input',self.selec) selTable<=TR(TD(self.sel)) self.sel.style.display = 'none' self.nutTab = MostraNut() self <= self.nutTab def entrou(self, event): if event.which==13: req = ajax.ajax() req.bind('complete',self.complete) req.open('POST','/nutsvc', True) req.set_header('content-type','application/x-www-form-urlencoded') d = {'op':'QUERY','q':event.currentTarget.value} req.send(d) def complete(self,r): if r.status==200 or r.status==0: result = json.loads(r.text) if len(result)==0: alert("Nenhum alimento encontrado") self.sel.style.display = 'none' return self.sel.clear() for l in result: self.sel.style.display = 'block' self.sel.style.width='90pw' self.sel<=OPTION(l[1], value=l[0]) def selec(self, event): self.sel.style.display = 'none' #alert(dir(event.currentTarget)) #alert(event.currentTarget.options[event.currentTarget.selectedIndex].text) #alert(event.currentTarget.text[event.currentTarget.selectionRange]) #alert(dir(self.inText)) #self.inText.set_text(event.currentTarget.options[event.currentTarget.selectedIndex].text) self.inText.value = event.currentTarget.options[event.currentTarget.selectedIndex].text medida = EscolheMedida(event.currentTarget.value, self.selected) self<=medida medida.showModal() def selected(self): alert("selected")
def __init__(self): DIV.__init__(self) #, style={'max-width':'90px'}) selTable = TABLE() self <= selTable self.inText = INPUT(Class="form-control") self.inText.bind('keyup', self.entrou) selTable <= TR(TD(P("Busca: ") + self.inText)) #,name="intext")) self.sel = SELECT(size=8, Class='form-control') # style={'max_width':'90px'}) self.sel.bind('input', self.selec) selTable <= TR(TD(self.sel)) self.sel.style.display = 'none' self.nutTab = MostraNut() self <= self.nutTab
def __init__(self, idAli, cb): DIALOG.__init__(self) tab = TABLE() self <= tab self.callback = cb #self.inText = INPUT(Class="form-control") #self.inText.bind('keyup',self.entrou) #tab<=TR(TD('Peso (g):')+TD(self.inText)) self.sel = SELECT(Class='form-control', size=8) # style={'max_width':'90px'}) ##self.sel.bind('input',self.selected) #tab<=TH("Escolha medida", colspan=2) self.inMedQty = INPUT(Class="form-control", size=4) tab <= TR(TD('Medida caseira, quantidade') + TD(self.inMedQty)) tab <= TR(TD(self.sel, colspan=2)) add = SPAN(Class='glyphicon glyphicon-ok-circle') add.bind('click', self.added) can = SPAN(Class='glyphicon glyphicon-remove-circle') can.bind('click', self.cancelled) tab <= TR( TD(can, style={ 'text-align': 'right', 'padding': '6pw' }) + TD(add, style={ 'text-align': 'center', 'padding': '6pw' })) req = ajax.ajax() req.bind('complete', self.complete) req.open('POST', '/nutsvc', True) req.set_header('content-type', 'application/x-www-form-urlencoded') d = {'op': 'MEDIDAS', 'q': idAli} req.send(d)
def create_base_list(): sel = SELECT(size=1, multiple=False, id="base") for base in bases: sel <= OPTION(base) doc['baselist'] <= sel if check_storage('base') and get_storage('base') in bases: doc['base'].value = get_storage('base')
def create_league_list(): sel = SELECT(size=1, multiple=False, id="league") for league in leagues: sel <= OPTION(league) doc['leaguelist'] <= sel if check_storage('league') and get_storage('league') in leagues: doc['league'].value = get_storage('league')
def __init__(self): DIV.__init__(self) #, style={'max-width':'90px'}) selTable = TABLE() self <= selTable self.inText = INPUT(Class="form-control") self.inText.bind('keyup',self.entrou) selTable<=TR(TD(P("Busca: ")+self.inText)) #,name="intext")) self.sel = SELECT(size=8,Class='form-control') # style={'max_width':'90px'}) self.sel.bind('input',self.selec) selTable<=TR(TD(self.sel)) self.sel.style.display = 'none' self.nutTab = MostraNut() self <= self.nutTab
def init_characters(): t = TABLE(Class='body') t <= COLGROUP( COL() + COL() + COL(Class='left_border') + COL(Class='left_dotted') + COL(Class='left_border') + COL(Class='left_dotted') + COL(Class='left_border') + COL(Class='left_dotted') + COL(Class='left_border') + COL(Class='left_dotted') + COL(Class='left_border') + COL(Class='left_dotted') + COL(Class='left_dotted') + COL(Class='left_border') + COL(Class='left_dotted') + COL(Class='left_dotted') ) t <= TR( TH(strings["character"], colspan=2) + TH(strings["level"], colspan=2) + TH(strings["normal"], colspan=2) + TH(strings["skill"], colspan=2) + TH(strings["burst"], colspan=2) + TH(strings["weapon"], colspan=3) + TH(strings["artifacts"], colspan=3) ) t <= TR( TH() + TH(strings["name"]) + TH(strings["now"]) + TH(strings["goal"]) + TH(strings["now"]) + TH(strings["goal"]) + TH(strings["now"]) + TH(strings["goal"]) + TH(strings["now"]) + TH(strings["goal"]) + TH() + TH(strings["now"]) + TH(strings["goal"]) + TH(strings["click_to_remove"], colspan=3) ) for char in sorted(characters): if char == 'traveler': continue # set up level select lvlc = SELECT(Id=f"level_c-{char}", Class=f"{char} save") lvlt = SELECT(Id=f"level_t-{char}", Class=f"{char} save") for lvl in [lvlc, lvlt]: for c, val in [(0, "1"), (1, "20"), (11, "20 A"), (2, "40"), (12, "40 A"), (3, "50"), (13, "50 A"), (4, "60"), (14, "60 A"), (5, "70"), (15, "70 A"), (6, "80"), (16, "80 A"), (7, "90")]: lvl <= OPTION(f"{val}", value=c) # Set up talent select t1c = SELECT(Id=f"talent_1_c-{char}", Class=f"{char} save") t1t = SELECT(Id=f"talent_1_t-{char}", Class=f"{char} save") t2c = SELECT(Id=f"talent_2_c-{char}", Class=f"{char} save") t2t = SELECT(Id=f"talent_2_t-{char}", Class=f"{char} save") t3c = SELECT(Id=f"talent_3_c-{char}", Class=f"{char} save") t3t = SELECT(Id=f"talent_3_t-{char}", Class=f"{char} save") for st in [t1t, t1c, t2t, t2c, t3t, t3c]: for cost in costs['talent']: st <= OPTION(cost) # Set up weapon select ws = SELECT(Id=f"weapon-{char}", data_id=f"select-{char}", Class=f'weapon {char} save') ws <= OPTION('--', value='--') sort_dict_wep = {} for item in weapons[characters[char]['weapon']]: if weapons[characters[char]['weapon']][item]['wam'] != 'unk': sort_dict_wep[strings[item]] = item else: if f"missing-{item}" not in doc: doc['missing'] <= LI(strings[item], Id=f"missing-{item}") for k in sorted(sort_dict_wep): ws <= OPTION(k, value=sort_dict_wep[k]) wlvlc = SELECT(Id=f"weapon_c-{char}", Class=f"{char} save") wlvlt = SELECT(Id=f"weapon_t-{char}", Class=f"{char} save") for lvl in [wlvlc, wlvlt]: for c, val in [(0, "1"), (1, "20"), (11, "20 A"), (2, "40"), (12, "40 A"), (3, "50"), (13, "50 A"), (4, "60"), (14, "60 A"), (5, "70"), (15, "70 A"), (6, "80"), (16, "80 A"), (7, "90")]: lvl <= OPTION(f"{val}", value=c) # Create table row for character t <= TR( TD(INPUT(Id=f"check-{char}", type='checkbox', data_id=f"check-{char}", Class='char_select save')) + TD(IMG(src=f"img/{char}.png", alt=strings[char], title=strings[char], loading="lazy")) + TD(lvlc) + TD(lvlt) + TD(t1c) + TD(t1t) + TD(t2c) + TD(t2t) + TD(t3c) + TD(t3t) + TD(ws) + TD(wlvlc) + TD(wlvlt) + TD(INPUT(Id=f"use_arti-{char}", type='checkbox', Class='save', checked='checked')) + TD(BUTTON(strings["add"], Class='arti_list text_button', data_id=f"arti-{char}")) + TD(DIV(Id=f"arti-{char}", Class=f'arti_span')) , data_id=f"check-{char}", Class='unchecked', data_color=characters[char]['element'], data_weapon=characters[char]['weapon'] ) # set up traveler base row # set up level select char = 'traveler' lvlc = SELECT(Id=f"level_c-{char}", Class=f"{char} save") lvlt = SELECT(Id=f"level_t-{char}", Class=f"{char} save") for lvl in [lvlc, lvlt]: for c, val in [(0, "1"), (1, "20"), (11, "20 A"), (2, "40"), (12, "40 A"), (3, "50"), (13, "50 A"), (4, "60"), (14, "60 A"), (5, "70"), (15, "70 A"), (6, "80"), (16, "80 A"), (7, "90")]: lvl <= OPTION(f"{val}", value=c) # Set up weapon select ws = SELECT(Id=f"weapon-{char}", data_id=f"select-{char}", Class=f'weapon {char} save') ws <= OPTION('--', value='--') sort_dict_wep = {} for item in weapons[characters[char]['weapon']]: if weapons[characters[char]['weapon']][item]['wam'] != 'unk': sort_dict_wep[strings[item]] = item else: if f"missing-{item}" not in doc: doc['missing'] <= LI(strings[item], Id=f"missing-{item}") for k in sorted(sort_dict_wep): ws <= OPTION(k, value=sort_dict_wep[k]) wlvlc = SELECT(Id=f"weapon_c-{char}", Class=f"{char} save") wlvlt = SELECT(Id=f"weapon_t-{char}", Class=f"{char} save") for lvl in [wlvlc, wlvlt]: for c, val in [(0, "1"), (1, "20"), (11, "20 A"), (2, "40"), (12, "40 A"), (3, "50"), (13, "50 A"), (4, "60"), (14, "60 A"), (5, "70"), (15, "70 A"), (6, "80"), (16, "80 A"), (7, "90")]: lvl <= OPTION(f"{val}", value=c) # Create table row for character t <= TR( TD(INPUT(Id=f"check-{char}", type='checkbox', data_id=f"check-{char}", Class='char_select save')) + TD(IMG(src=f"img/{char}.png", alt=strings[char], title=strings[char], loading="lazy")) + TD(lvlc) + TD(lvlt) + TD() + TD() + TD() + TD() + TD() + TD() + TD(ws) + TD(wlvlc) + TD(wlvlt) + TD(INPUT(Id=f"use_arti-{char}", type='checkbox', Class='save', checked='checked')) + TD(BUTTON(strings["add"], Class='arti_list text_button', data_id=f"arti-{char}")) + TD(DIV(Id=f"arti-{char}", Class=f'arti_span')) , data_id=f"check-{char}", Class='unchecked', data_color='multi', data_weapon=characters[char]['weapon'] ) # set up traveler anemo/geo row for char in sorted(traveler_talent): ele = char.split('_')[1] # Set up talent select t1c = SELECT(Id=f"talent_1_c-{char}", Class=f"{char} save") t1t = SELECT(Id=f"talent_1_t-{char}", Class=f"{char} save") t2c = SELECT(Id=f"talent_2_c-{char}", Class=f"{char} save") t2t = SELECT(Id=f"talent_2_t-{char}", Class=f"{char} save") t3c = SELECT(Id=f"talent_3_c-{char}", Class=f"{char} save") t3t = SELECT(Id=f"talent_3_t-{char}", Class=f"{char} save") for st in [t1t, t1c, t2t, t2c, t3t, t3c]: for cost in costs['talent']: st <= OPTION(cost) # Create table row for character t <= TR( TD(INPUT(Id=f"check-{char}", type='checkbox', data_id=f"check-{char}", Class='char_select save')) + TD(IMG(src=f"img/{char}.png", alt=strings['traveler'], title=strings['traveler'], loading="lazy")) + TD() + TD() + TD(t1c) + TD(t1t) + TD(t2c) + TD(t2t) + TD(t3c) + TD(t3t) + TD() + TD() + TD() + TD() + TD() + TD() , data_id=f"check-{char}", Class='unchecked', data_color=ele, data_weapon=characters['traveler']['weapon'] ) doc['character_list'] <= t
def usersLoaded(req): users = loads(req.text) container = DIV() container <= H2('Edycja zadania') form = FORM(method='PATCH', action='#') input0 = INPUT(name='id', type='hidden', value=task_details['id'], id='id_field') form <= input0 row1 = DIV() row1.class_name = 'row' cell11 = DIV() cell11.class_name = 'large-6 columns' label11 = LABEL('Nazwa') input11 = INPUT(placeholder='Nazwa zadania', type='text', value=task_details['name'], name='name', id='name_field') label11 <= input11 cell11 <= label11 error_panel1 = DIV(id='name_error') error_panel1.class_name = 'panel error' cell11 <= error_panel1 row1 <= cell11 row2 = DIV() row2.class_name = 'row' cell2 = DIV() cell2.class_name = 'large-6 columns' label2 = LABEL('Opis') input2 = INPUT(placeholder='Opis zadania', name='description', id='description_field', type='text') input2.value = task_details['description'] label2 <= input2 cell2 <= label2 row2 <= cell2 cell3 = DIV() cell3.class_name = 'large-6 columns' label3 = LABEL('Przypisane do') input3 = SELECT(name='assignee', id='assignee_field') input3 <= OPTION('---', value=None) for user in users: input3 <= OPTION(user['username'], value=getApiLink('users', user['id'])) input3.value = task_details['assignee'] label3 <= input3 cell3 <= label3 row1 <= cell3 cell7 = DIV() cell7.class_name = 'large-6 columns' label7 = LABEL('Termin wykonania') input7 = INPUT(name='deadline', id='deadline_field', placeholder='yyyy-mm-dd', type='text') input7.value = task_details['deadline'] if task_details['deadline'] else '' label7 <= input7 cell7 <= label7 error_panel7 = DIV(id='deadline_error') error_panel7.class_name = 'panel error' cell7 <= error_panel7 row2 <= cell7 row3 = DIV() row3.class_name = 'row' cell33 = DIV() cell33.class_name = 'large-6 columns' label33 = LABEL('Trudność') input33 = SELECT(name='difficulty', id='difficulty_field') input33 <= OPTION('---', value='None') input33 <= OPTION('łatwe', value='easy') input33 <= OPTION('średnie', value='intermediate') input33 <= OPTION('trudne', value='hard') if task_details['difficulty'] and task_details['difficulty'] in ('easy', 'intermediate', 'hard'): input33.value = task_details['difficulty'] label33 <= input33 cell33 <= label33 cell34 = DIV() cell34.class_name = 'large-6 columns' label34 = LABEL('') label34 <= BR() input34 = BUTTON('Archiwizuj', id='archive_task', data_task_id=task_details['id']) input34.class_name = 'button tiny' label34 <= input34 cell34 <= label34 row3 <= cell33 row3 <= cell34 input34.bind('click', archiveTask) row6 = DIV() row6.class_name = 'row' cell6 = DIV() cell6.class_name = 'large-12 columns' cell6.id = 'comments-container' cell6 <= H4('Komentarze') def appendCommentToDom(author, when, content): length = len(cell6.get(selector='.comment')) colour = '' if length % 2 == 0 else ' callout' #colour = '' panel = DIV() panel.class_name = 'panel comment' + colour panel <= B('{0} dnia {1}'.format(author, when)) panel <= P(content) cell6 <= panel if len(task_details['comments']) == 0: panel = DIV() panel.class_name = 'panel' panel <= P('No comments') cell6 <= panel else: i = 0 for comment in task_details['comments']: author = [user['username'] for user in users if getApiLink('users', user['id']) == comment['author']].pop() when = comment['created_at'] content = comment['content'] appendCommentToDom(author, when, content) row6 <= cell6 row5 = DIV() row5.class_name = 'row' cell5 = DIV() cell5.class_name = 'large-12 columns' label5 = LABEL('Skomentuj') input5 = TEXTAREA(placeholder='Treść komentarza', name='comment', id='comment_field') label5 <= input5 cell5 <= label5 comment_btn = A('Dodaj komentarz', href='#') comment_btn.class_name = 'button tiny' cell5 <= comment_btn row5 <= cell5 def addComment(event): event.preventDefault() content = document['comment_field'].value author = document['body'].__getattribute__('data-username') author_id = document['body'].__getattribute__('data-userid') when = window.Date() if content: appendCommentToDom(author, when, content) data = { 'author': getApiLink('users', author_id), 'content': content, 'task': getApiLink('tasks', task_details['id']) } a2 = ajax.ajax() a2.open('POST', '/api/comments2/?format=json') a2.set_header('content-type', 'application/x-www-form-urlencoded') a2.set_header('X-CSRFToken', document.get(name='csrfmiddlewaretoken')[0].value) a2.send(data) document['comment_field'].value = '' comment_btn.bind('click', addComment) row4 = DIV() row4.class_name = 'row' cell4 = DIV() cell4.class_name = 'large-12 columns' submit_btn = A('Zapisz zmiany', type='submit', href='#') submit_btn.class_name = 'button tiny' cell4 <= submit_btn row4 <= cell4 form <= row1 form <= row2 form <= row3 form <= row4 form <= row6 form <= row5 container <= form for i in range(1, 6): colour_name = 'colour{0}'.format(i) if str(i) in task_details['colours']: document[colour_name].class_name = 'colour-btn checked' else: document[colour_name].class_name = 'colour-btn' #/api/tasks/ def on_submit(event): assignee = None if document['assignee_field'].value == 'None' \ else document['assignee_field'].value deadline = '' if document['deadline_field'].value == '' \ else document['deadline_field'].value + 'T01:01' difficulty = None if document['difficulty_field'].value == '---' \ or document['difficulty_field'].value not in ('easy', 'intermediate', 'hard') \ else document['difficulty_field'].value colours = [] for checked_colour in document.get(selector='a.colour-btn.checked'): colours.append(checked_colour.id[-1]) data = { 'id': document['id_field'].value, 'name': document['name_field'].value, 'description': document['description_field'].value, 'assignee': assignee, 'deadline': deadline, 'difficulty': difficulty, 'colours': ','.join(colours) } def taskUpdated(req): data = loads(req.text) if 'id' in data: # zapisalo sie poprawnie document['task_' + str(data['id'])].clear() data['colours'] = data['colours'].split(',') if data['colours'] else [] addColours(data, document['task_' + str(data['id'])]) document['task_' + str(data['id'])] <= H3(data['name'], **{'data-task-id': data['id']}) hide_modal() else: for field, errors in data.items(): error_field_name = field + '_error' for error in errors: document[error_field_name] <= error for error_field in document.get(selector='.panel.error'): error_field.clear() a = ajax.ajax() a.open('PATCH', '/api/tasks/' + str(data['id']) + '/?format=json') a.bind('complete', taskUpdated) a.set_header('content-type', 'application/x-www-form-urlencoded') a.set_header('X-CSRFToken', document.get(name='csrfmiddlewaretoken')[0].value) a.send(data) return False submit_btn.bind('click', on_submit) show_modal(container)