def topNav(self): """ The top navigation area of the webpage. """ out = header( section(a("Data Ethics", href="/", _class="navbar-brand"), _class="navbar-section"), # Generate navbar items from site map section(*[ self.navbarItem(name, slug) for name, slug in self.siteMap.items() ], _class="navbar-section"), _class="navbar") return out
def _render_response(resp): with H.section(): with H.div(_class=u'message-display'): with H.h2(), H.code(): # Status line # See above regarding spaces. if resp.version: H.span(printable(resp.version), **_for_object(resp.version)) with H.span(**_for_object(resp.status)): _render_known(resp.status) H.span(printable(find_reason_phrase(resp))) _render_message(resp) # Headers, body and all that _render_complaints(resp)
def dominate_enter_page(): """ 第三頁:確認資訊頁面,對應到 @app.route('/jump') 及其函數 registerpage_run [if request.method == 'POST'] 目標:利用dominate寫出 enter_page 的 html並在 templates 資料夾中存成 index3.html 分為三個區塊 doc = dominate.document() with doc.head (包含css的style;meta確保中文可以運行在utf-8下) with doc.body (包含 6 information: name/ password/ student_id/ telephone_number/ school_bike_license/ bike_lock_number and a button confirm) 最後寫入文件中(在templates資料夾中存成index3.html) """ doc = dominate.document(title="entered") with doc.head: tags.meta(name='charset', content="utf-8") tags.style("""\ body { background-color: #F9F8F1; color: #2C232A; font-family: sans-serif; font-size: 14; text-align: center; } """) with doc.body: tags.h1('welcome' + str(name_list_temp[0])) tags.h2('please confirm your information') with tags.section(cls='information check'): with tags.div(cls='name', style="text-align: center"): tags.label('your name is ' + str(name_list_temp[0])) with tags.div(cls='password', style="text-align: center"): tags.label('your password is ' + str(password_temp[0])) with tags.div(cls='student_id', style="text-align: center"): tags.label('your student id is ' + str(student_id_temp[0])) with tags.div(cls='telephone', style="text-align: center"): tags.label('your telephone number is ' + str(telephone_number_temp[0])) with tags.div(cls='license', style="text-align: center"): tags.label('the status of your bike_lice ' + str(school_bike_license_temp[0])) with tags.div(cls='lock_number', style="text-align: center"): tags.label('your bike lock number is ' + str(bike_lock_number_temp[0])) with tags.div(cls='button', style="margin:0 auto; width:250px;"): tags.input(type='button', value='confirm', style="width:120px; background-color:pink;", onclick="location.href='http://127.0.0.1:5000/entered'") fn = 'templates/index3.html' with open(file=fn, mode='w', encoding='utf-8') as f: f.write(doc.render()) print(f)
def dominate_homepage(): """ 第一頁:歡迎頁面,對應到 @app.route('/') 及其函數 homepage_run() 目標:利用dominate寫出homepage的html並在templates資料夾中存成index1.html 分為三個區塊 doc = dominate.document() with doc.head (包含css的style;meta確保中文可以運行在utf-8下) with doc.body (包含welcome words and a button) 最後寫入文件中(在templates資料夾中存成index1.html) """ doc = dominate.document(title='homepage') with doc.head: tags.meta(name='charset', content="utf-8") tags.style("""\ body { background-color: #F9F8F1; color: #2C232A; font-family: sans-serif; font-size: 30; text-align: center; } section{ width: 300px; height: 300px; position: absolute; top: 50%; left: 50%; overflow: auto; text-align: center; margin-left:-150px; margin-top:-150px; } """) with doc.body: with tags.section(): with tags.div(cls='headline', style='font-size: 30;'): tags.h1('Find Your Bike') tags.input(type='button', value='click me', onclick="location.href='http://127.0.0.1:5000/jump'", style="width:120px; background-color:pink; font-size: 14;") fn = 'templates/index1.html' with open(file=fn, mode='w', encoding='utf-8') as f: f.write(doc.render()) print(f)
def _render_request(req): with H.section(): with H.div(_class=u'message-display'): with H.h2(), H.code(): # Request line # We don't insert spaces here because we assume that # Dominate will render each element on its own line, # thus implicitly creating whitespace. # https://github.com/Knio/dominate/issues/68 with H.span(**_for_object(req.method)): _render_known(req.method) H.span(printable(req.target), **_for_object(req.target)) if req.version: H.span(printable(req.version), **_for_object(req.version)) _render_message(req) # Headers, body and all that _render_complaints(req)
def _render_request(req): with H.section(): with H.div(_class=u'message-display'): with H.h2(), H.code(): # Request line # We don't insert spaces here because, # without ``__pretty=False``, # Dominate renders each element on its own line, # thus implicitly creating whitespace. with H.span(**_for_object(req.method)): _render_known(req.method) H.span(printable(req.target), **_for_object(req.target)) if req.version: H.span(printable(req.version), **_for_object(req.version)) _render_message(req) # Headers, body and all that _render_complaints(req)
def _render_response(resp): with H.section(): with H.div(_class=u'message-display'): if resp.remark: H.p(printable(resp.remark), _class=u'message-remark') with H.h2(), H.code(): # Status line # See above regarding spaces. if resp.version: H.span(printable(resp.version), **_for_object(resp.version)) with H.span(**_for_object(resp.status)): _render_known(resp.status) H.span(printable(find_reason_phrase(resp))) _render_message(resp) # Headers, body and all that _render_complaints(resp)
def dominate_wrong_information_page(): """ 第五頁:資料庫連接錯誤頁面,對應到 @app.route('/entered') 及其函數 eneter_success() 目標:利用dominate寫出homepage的html並在templates資料夾中存成index5.html 分為三個區塊 doc = dominate.document() with doc.head (包含css的style;meta確保中文可以運行在utf-8下) with doc.body (包含 words and a button) 最後寫入文件中(在templates資料夾中存成index5.html) """ doc = dominate.document(title='error_page') with doc.head: tags.meta(name='charset', content="utf-8") tags.style("""\ body { background-color: #F9F8F1; color: #2C232A; font-family: sans-serif; font-size: 30; text-align: center; } section{ width: 300px; height: 300px; position: absolute; top: 50%; left: 50%; overflow: auto; text-align: center; margin-left:-150px; margin-top:-150px; } """) with doc.body: with tags.section(): with tags.div(cls='headline', style='font-size: 30;'): tags.h2("wrong information! please try again") tags.input(type='button', value='return back', onclick="location.href='http://127.0.0.1:5000/'", style="width:120px; background-color:pink; font-size: 14;") fn = 'templates/index6.html' with open(file=fn, mode='w', encoding='utf-8') as f: f.write(doc.render()) print(f)
def _render_request(req): with H.section(): with H.div(_class=u'message-display'): if req.remark: H.p(printable(req.remark), _class=u'message-remark') with H.h2(), H.code(): # Request line # We don't insert spaces here because, # without ``__pretty=False``, # Dominate renders each element on its own line, # thus implicitly creating whitespace. with H.span(__pretty=False, **_for_object(req.method)): _render_known(req.method) H.span(printable(req.target), **_for_object(req.target)) if req.version: H.span(printable(req.version), **_for_object(req.version)) _render_message(req) # Headers, body and all that _render_complaints(req)
def _render_response(resp): with H.section(): with H.div(_class=u'message-display'): if resp.remark: H.p(printable(resp.remark), _class=u'message-remark') with H.h2(), H.code(): # Status line # See above regarding spaces. if resp.version: H.span(printable(resp.version), **_for_object(resp.version)) # httpolice-devtool (the Chrome extension) relies # on the ``StatusCode`` class. Avoid breaking it, at least # as long as it doesn't inconvenience HTTPolice itself. with H.span(**_for_object(resp.status, u'StatusCode')): _render_known(resp.status) text_node(u' ' + printable(find_reason_phrase(resp))) _render_message(resp) # Headers, body and all that _render_complaints(resp)
def dominate_error_page(): """ 第五頁:資料庫連接錯誤頁面,對應到 @app.route('/entered') 及其函數 eneter_success() 目標:利用dominate寫出homepage的html並在templates資料夾中存成index5.html 分為三個區塊 doc = dominate.document() with doc.head (包含css的style;meta確保中文可以運行在utf-8下) with doc.body (包含 words and a button) 最後寫入文件中(在templates資料夾中存成index5.html) """ doc = dominate.document(title='error_page') with doc.head: tags.meta(name='charset', content="utf-8") tags.style("""\ body { background-color: #F9F8F1; color: #2C232A; font-family: sans-serif; font-size: 30; text-align: center; } """) with doc.body: with tags.section(): with tags.div(cls='headline', style='font-size: 30;'): tags.h1('Register failed! You have registered before!') tags.input(type='button', value='return back', onclick="location.href='http://127.0.0.1:5000/'", style="width:120px; background-color:pink; font-size: 14;") fn = 'templates/index5.html' with open(file=fn, mode='w', encoding='utf-8') as f: f.write(doc.render()) print(f)
def cli(source_dir, destination): root = pathlib.Path(source_dir) container = div(id='publications') for source in sorted(root.glob('*-*')): topic_title = source.name.split('-')[1] topic_title = topic_title.replace('_', ' ') topic_section = section() topic_section.add(h2(topic_title)) paper_list = ul() topic_section.add(paper_list) with source.open() as f: data = bibtexparser.load(f) for entry in data.entries: list_item = li() paper_list.add(list_item) paper_title = h3(entry['title']) list_item.add(paper_title) authors = p(entry['author']) list_item.add(authors) if 'journal' in entry: journal = p(entry['journal']) list_item.add(journal) container.add(topic_section) destination.write(str(container))
def dominate_register_page(): """ 第二頁:註冊頁面,對應到 @app.route('/jump') 及其函數 registerpage_run 目標:利用dominate寫出registerpage的html並在templates資料夾中存成index2.html 分為三個區塊 doc = dominate.document() with doc.head (包含css的style;meta確保中文可以運行在utf-8下) with doc.body (包含 a form with 7 legends: name/ password/ student_id/ telephone_number/ school_bike_license/ bike_lock_number/ picture uploading and a button submit) 最後寫入文件中(在templates資料夾中存成index2.html) """ doc = dominate.document(title="registerpage") with doc.head: tags.meta(name='charset', content="utf-8") tags.style("""\ body { background-color: #F9F8F1; color: #2C232A; font-family: sans-serif; font-size: 14; text-align: center; } section{ width: 800px; height: 800px; position: absolute; top: 15%; left: 15%; overflow: auto; text-align: center; } label{ cursor: pointer; display: inline-block; padding: 3px 6px; text-align: center; width: 500px; vertical-align: top; } input{ font-size: inherit; } """) with doc.body: with tags.div(clas='headline', style='font-size: 20;'): tags.h1('Register Page') with tags.section(): with tags.form(method='POST', action="/jump", enctype="multipart/form-data"): with tags.legend(): tags.label('請輸入姓名(中文)') tags.input(type='text', name='name', size=20) with tags.legend(): tags.label('請輸入密碼') tags.input(type='text', name='password', size=20) with tags.legend(): tags.label('請輸入學號(1個大寫英文字母+8個數字)') tags.input(type='text', name='student_id', size=20) with tags.legend(): tags.label('請輸入電話(請輸入10位數字)') tags.input(type='text', name='telephone_number', size=20) with tags.legend(): tags.label('是否有台大車證(Y/N)') tags.input(type='text', name='school_bike_license', size=20) with tags.legend(): tags.label('腳踏車的密碼(選填、請輸入數字)') tags.input(type='text', name='bike_lock_number', size=20) with tags.legend(): tags.label('上傳圖片') tags.input(type='file', name='photo', size=20) with tags.div(cls='button', style="margin:0 auto; width:250px;"): tags.input(type='submit', value='click me', style="width:120px; background-color:pink;") fn = 'templates/index2.html' with open(file=fn, mode='w', encoding='utf-8') as f: f.write(doc.render())
def profile_to_html(profile_info): html_body = body() with html_body: with section(_class="leading animated fadeInDown"): with a(href='/'): p(profile_info['personal_info']['name'], _class="leading-bigtext") p(profile_info['personal_info']['summary'][:-4], _class="leading-text") for section_title in ['education', 'jobs', 'volunteering']: with section(_class=f"cards animated fadeInUp {section_title}"): div(section_title, _class='section-title') roles = profile_info['experiences'][section_title] for role in roles: if len(set(role.values())) > 1: with article(): with div(_class='cventry'): if section_title == "jobs": with div(_class='entry-header'): div(role['title'], _class='entry-title') div(role['date_range'], _class='entry-date') with div(_class="entry-subheader"): div(role['company'], _class='entry-organisation') div(role['location'], _class='entry-location') with div(_class='entry-body'): split = role['description'].split('- ') if len(split) > 1: with ul(): for para in split[1:]: li(para) else: p(role['description']) elif section_title == "education": with div(_class='entry-header'): div(role['name'], _class='entry-title') div(role['date_range'], _class='entry-date') with div(_class="entry-subheader"): div(role['field_of_study'], _class='entry-organisation') with div(_class='entry-location'): span(role['degree']) if role['grades'] != '' and role[ 'degree'] != '': span(', ') i(f"{role['grades']}", style="font-weight:300") with div(_class='entry-body'): split = role['description'].split('- ') if len(split) > 1: with ul(): for para in split[1:]: li(para) else: p(role['description']) elif section_title == "volunteering": with div(_class='entry-header'): div(role['title'], _class='entry-title') div(role['date_range'], _class='entry-date') with div(_class="entry-subheader"): div(role['company'], _class='entry-organisation') # div(role['cause'], _class='entry-location') with div(_class='entry-body'): split = role['description'].split('- ') if len(split) > 1: with ul(): for para in split[1:]: li(para) else: p(role['description']) with section(_class="cards animated fadeInDown skills"): div('skills', _class='section-title') with article(): for skill in profile_info['skills']: div(skill['name'], _class='skill') return str(html_body)