def get_performance_graph(graph_type, vm, graph_period): error = None img = IMG(_src = URL("static" , "images/no_graph.jpg") , _style = "height:100px") try: rrd_file = get_rrd_file(vm) if os.path.exists(rrd_file): if create_graph(vm, graph_type, rrd_file, graph_period): img_pos = "images/vm_graphs/" + vm + "_" + graph_type + ".png" img = IMG(_src = URL("static", img_pos), _style = "height:100%") rrd_logger.info("Graph created successfully") else: rrd_logger.warn("Unable to create graph from rrd file!!!") error = "Unable to create graph from rrd file" else: rrd_logger.warn("VMs RRD File Unavailable!!!") error = "VMs RRD File Unavailable!!!" except: rrd_logger.warn("Error occured while creating graph.") import sys, traceback etype, value, tb = sys.exc_info() error = ''.join(traceback.format_exception(etype, value, tb, 10)) rrd_logger.debug(error) finally: if error != None: return error else: rrd_logger.info("Returning image.") return img
def get_vm_snapshots(vm_id): vm_snapshots_list = [] snapshot_dict = {} for snapshot in db(db.snapshot.vm_id == vm_id).select(): snapshot_dict['name'] = snapshot.snapshot_name snapshot_dict['delete'] = A(IMG(_src=URL('static','images/delete-snapshot.gif'), _height = 20, _width = 20), _href=URL(r=request, f='delete_snapshot', args= [vm_id, snapshot.id]), _title = "Delete this snapshot", _alt = "Delete this snapshot") snapshot_dict['revert'] = A(IMG(_src=URL('static','images/revertTosnapshot.png'),_height = 20, _width = 20), _href=URL(r=request, f='revert_to_snapshot', args= [vm_id, snapshot.id]), _title = "Revert to this snapshot", _alt = "Revert to this snapshot") vm_snapshots_list.append(snapshot_dict) return vm_snapshots_list
def layout(item): name = "Rheinland-Pfalz" current_user = current.auth.user if current_user: user_org_id = current_user.organisation_id if user_org_id: otable = current.s3db.org_organisation query = (otable.id == user_org_id) & \ (otable.deleted == False) row = current.db(query).select( otable.name, limitby=(0, 1), ).first() if row: name = row.name logo = IMG( _src="/%s/static/themes/RLP/img/logo_rlp.png" % current.request.application, _alt=name, _width=38, ) # Note: render using current.menu.org.render()[0] + current.menu.org.render()[1] return (name, logo)
def related_articles(self): from helpers.article import related_articles related_articles = related_articles(self.db, self.context.article.tags, self.context.article.category_id, self.context.article.id) if related_articles: self.context.related_articles = UL( *[ LI( DIV( IMG(_src=self.get_image( related.thumbnail, related.content_type_id.identifier), _width=120)), A(related.title, _href=self.CURL('article', 'show', args=[related.id, related.slug])), **{ '_data-url': self.CURL('article', 'show', args=[related.id, related.slug]) }) for related in related_articles ], **dict(_class="related-articles")) else: self.context.related_articles = False
def layout(item): name = current.T("Cumbria County Council") current_user = current.auth.user if current_user: user_org_id = current_user.organisation_id if user_org_id: otable = current.s3db.org_organisation query = (otable.id == user_org_id) & \ (otable.deleted == False) row = current.db(query).select(otable.name, limitby = (0, 1), ).first() if row: name = row.name logo = IMG(_src = "/%s/static/themes/CCC/img/logo_small.png" % current.request.application, _alt = name, _width = 140, ) # Note: render using current.menu.org.render()[0] + current.menu.org.render()[1] return (name, logo)
def get_html(self): contest_data = self.get_data() card_content_table = TABLE(_class="bordered centered highlight", _style="line-height: 20px") tbody = TBODY() for contest in contest_data: tbody.append( TR( TD(contest[0]), TD( IMG(_src=current.get_static_url("images/%s_small.png" % str(contest[1])), _class="parent-site-icon-small")), TD( A(I(_class="fa fa-external-link-square"), _class= "btn-floating btn-small accent-4 green view-contest", _href=contest[2], _target="_blank")))) card_content_table.append(tbody) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content_table, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def layout(item): name = "" current_user = current.auth.user if current_user: user_org_id = current_user.organisation_id if user_org_id: otable = current.s3db.org_organisation query = (otable.id == user_org_id) & \ (otable.deleted == False) row = current.db(query).select( otable.name, limitby=(0, 1), ).first() if row: name = row.name menu_logo = current.deployment_settings.get_ui_menu_logo() if not menu_logo: menu_logo = "/%s/static/img/sahanalarge_14.png" % current.request.application logo = IMG( _src=menu_logo, _alt=name, _width=40, ) # Note: render using current.menu.org.render()[0] + current.menu.org.render()[1] return (name, logo)
def preview_photo(): item = application.getItemByUUID(request.args(0)) photo = db.plugin_photoset_photo(request.args(1)) return IMG( _src=URL('default', 'download', args=[photo.picture]), _class="img-responsive center-block", _alt=item.slugline, )
def get_html(self): contest_data = self.get_data() card_content_table = TABLE(_class="bordered centered highlight", _style="line-height: 20px") tbody = TBODY() for contest in contest_data: try: start_time = datetime.datetime.strptime( contest["start_time"], "%Y-%m-%dT%H:%M:%S.000Z") end_time = datetime.datetime.strptime( contest["end_time"], "%Y-%m-%dT%H:%M:%S.000Z") except Exception as e: print "Unable to parse datetime", contest start_time = datetime.datetime.strptime( contest["start_time"], "%Y-%m-%d %H:%M:%S %Z") end_time = datetime.datetime.strptime(contest["end_time"], "%Y-%m-%d %H:%M:%S %Z") start_time += datetime.timedelta(minutes=330) end_time += datetime.timedelta(minutes=330) contest["start_time"] = start_time contest["end_time"] = end_time tbody.append( TR( TD(contest["name"]), TD( IMG(_src=current.get_static_url( "images/%s_small.png" % str(contest["site"].lower())), _class="parent-site-icon-small")), TD( A(I(_class="fa fa-external-link-square"), _class= "btn-floating btn-small accent-4 green view-contest", _href=contest["url"], _target="_blank")), TD(utilities.get_reminder_button(contest)))) card_content_table.append(tbody) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content_table, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def ICONLINK(user, icon, text, action=None, title="Click", theme_name="basic"): from gluon import current request = current.request bt = A(_class="icon-link", _onclick=action if user else "window.location = '%s'" % URL('default', 'user', args='login', vars=dict(_next=URL('article', 'show', args=request.args))), _style="cursor:pointer;", _title=title) bt.append( CAT( IMG(_src=URL('static', '%s/images/icons' % theme_name, args="%s.png" % icon), _width=16), SPAN(text, _style="line-height:16px;"))) return bt
def get_html(self): submissions_data = self.get_data() card_content_table = TABLE(_class="bordered highlight") tbody = TBODY() for row in submissions_data: user_record = utilities.get_user_records([row[0]], "id", "id", True) tr = TR( TD( A(user_record.first_name + " " + user_record.last_name, _href=URL("user", "profile", args=user_record.stopstalk_handle, extension=False), _target="_blank"))) td = TD() for site in row[1]: if site == "total": continue else: td.append( SPAN(IMG(_src=current.get_static_url( "images/%s_small.png" % str(site).lower()), _class="parent-site-icon-very-small"), " " + str(row[1][site]), _style="padding-right: 10px;")) tr.append(td) tbody.append(tr) card_content_table.append(tbody) card_html = BaseCard.get_html( self, **dict(card_title=self.card_title, card_content=card_content_table, cta_links=self.get_cta_html(), card_color_class="white", card_text_color_class="black-text")) return card_html
def render_table(submissions, duplicates=[], user_id=None): """ Create the HTML table from submissions @param submissions (Dict): Dictionary of submissions to display @param duplicates (List): List of duplicate user ids @return (TABLE): HTML TABLE containing all the submissions """ T = current.T status_dict = { "AC": "Accepted", "WA": "Wrong Answer", "TLE": "Time Limit Exceeded", "MLE": "Memory Limit Exceeded", "RE": "Runtime Error", "CE": "Compile Error", "SK": "Skipped", "HCK": "Hacked", "PS": "Partially Solved", "OTH": "Others" } table = TABLE(_class="bordered centered submissions-table") table.append( THEAD( TR(TH(T("Name")), TH(T("Site Profile")), TH(T("Time of submission")), TH(T("Problem")), TH(T("Language")), TH(T("Status")), TH(T("Points")), TH(T("View/Download Code"))))) tbody = TBODY() # Dictionary to optimize lookup for solved and unsolved problems # Multiple lookups in the main set is bad plink_to_class = {} for submission in submissions: span = SPAN() if submission.user_id: person_id = submission.user_id else: person_id = submission.custom_user_id # Check if the given custom_user is a duplicate # We need to do this because there might be a case # when a duplicate custom_user is created and then # his name or institute is changed for duplicate in duplicates: if duplicate[1] == person_id and duplicate[0]: person_id = current.db.custom_friend(duplicate[0]) break span = SPAN(_class="orange tooltipped", data={"position": "right", "delay": "50", "tooltip": T("Custom User")}, _style="cursor: pointer; " + \ "float:right; " + \ "height:10px; " + \ "width:10px; " + \ "border-radius: 50%;") tr = TR() append = tr.append append( TD( DIV( span, A(person_id.first_name + " " + person_id.last_name, _href=URL("user", "profile", args=person_id.stopstalk_handle, extension=False), _class="submission-user-name", _target="_blank")))) append(TD(A(IMG(_src=current.get_static_url("images/" + \ submission.site.lower() + \ "_small.png"), _style="height: 30px; width: 30px;"), _class="submission-site-profile", _href=current.get_profile_url(submission.site, submission.site_handle), _target="_blank"))) append(TD(submission.time_stamp, _class="stopstalk-timestamp")) link_class = "" plink = submission.problem_link if plink_to_class.has_key(plink): link_class = plink_to_class[plink] else: link_class = get_link_class(plink, user_id) plink_to_class[plink] = link_class link_title = (" ".join(link_class.split("-"))).capitalize() append( TD( problem_widget(submission.problem_name, submission.problem_link, link_class, link_title))) append(TD(submission.lang)) append( TD( IMG(_src=current.get_static_url("images/" + submission.status + ".jpg"), _title=status_dict[submission.status], _alt=status_dict[submission.status], _class="status-icon"))) append(TD(submission.points)) if submission.view_link: submission_data = { "view-link": submission.view_link, "site": submission.site } button_class = "btn waves-light waves-effect" if current.auth.is_logged_in(): if submission.site != "HackerEarth": td = TD(BUTTON(T("View"), _class="view-submission-button " + button_class, _style="background-color: #FF5722", data=submission_data), " ", BUTTON(T("Download"), _class="download-submission-button " + \ button_class, _style="background-color: #2196F3", data=submission_data)) else: td = TD( A(T("View"), _href=submission.view_link, _class="btn waves-light waves-effect", _style="background-color: #FF5722", _target="_blank")) append(td) else: append( TD( BUTTON(T("View"), _class="btn tooltipped disabled", _style="background-color: #FF5722", data={ "position": "bottom", "delay": "50", "tooltip": T("Login to View") }), " ", BUTTON(T("Download"), _class="btn tooltipped disabled", _style="background-color: #2196F3", data={ "position": "bottom", "delay": "50", "tooltip": T("Login to Download") }))) else: append(TD()) tbody.append(tr) table.append(tbody) return table
def render_table(submissions): """ Create the HTML table from submissions """ status_dict = { "AC": "Accepted", "WA": "Wrong Answer", "TLE": "Time Limit Exceeded", "MLE": "Memory Limit Exceeded", "RE": "Runtime Error", "CE": "Compile Error", "SK": "Skipped", "HCK": "Hacked", "OTH": "Others" } table = TABLE(_class="striped centered") table.append( THEAD( TR(TH("User Name"), TH("Site"), TH("Site Handle"), TH("Time of submission"), TH("Problem"), TH("Language"), TH("Status"), TH("Points"), TH("View Code")))) tbody = TBODY() for submission in submissions: tr = TR() append = tr.append person_id = submission.custom_user_id if submission.user_id: person_id = submission.user_id append( TD( A(person_id.first_name + " " + person_id.last_name, _href=URL("user", "profile", args=[submission.stopstalk_handle]), _target="_blank"))) append(TD(submission.site)) append( TD( A(submission.site_handle, _href=get_link(submission.site, submission.site_handle), _target="_blank"))) append(TD(submission.time_stamp)) append( TD( A(submission.problem_name, _href=URL("problems", "index", vars={ "pname": submission.problem_name, "plink": submission.problem_link }), _target="_blank"))) append(TD(submission.lang)) append( TD( IMG(_src=URL("static", "images/" + submission.status + ".jpg"), _title=status_dict[submission.status], _style="height: 25px; width: 25px;"))) append(TD(submission.points)) if submission.view_link: append( TD( A("View", _href=submission.view_link, _class="btn waves-light waves-effect", _style="background-color: #FF5722", _target="_blank"))) else: append(TD()) tbody.append(tr) table.append(tbody) return table
def pdf(self, r, **attr): """ Generate the PDF Args: r: the S3Request instance attr: controller attributes """ T = current.T db = current.db s3db = current.s3db # Look up the report organisation logo = None org_id, org_label = self.get_report_organisation(r) if org_id: # Look up the root organisation's logo otable = s3db.org_organisation rotable = otable.with_alias("root_organisation") join = rotable.on(rotable.id == otable.root_organisation) field = rotable.logo row = db(otable.id == org_id).select( field, join=join, limitby=(0, 1), ).first() if row and row.logo: if field.uploadfolder: path = field.uploadfolder else: path = os.path.join(current.request.folder, 'uploads') logo = os.path.join(path, row.logo) # Look up the report programme prog_id, prog_label = self.get_report_programme(r) # Extract the HR records data, pictures = self.extract(r.resource) # Construct the header title = T("Official Volunteer List") header = TABLE(_class="no-grid", ) trow = TR() if logo: trow.append( TD( IMG(_src=logo, _width="80"), _rowspan=3 if prog_id else 2, )) trow.append(TD(H4(title), _colspan=3)) header.append(trow) if org_id: header.append(TR(TD(H5(org_label), _colspan=3))) if prog_id: header.append(TR(TD(prog_label, _colspan=3))) header.append(TR(TD())) # Should we show the branch column? branches = set(row["_row"]["hrm_human_resource.organisation_id"] for row in data.rows) if org_id: show_branch = len(branches) > 1 org_repr = s3db.org_OrganisationRepresent( show_link=False, parent=False, acronym=True, ) else: show_branch = True org_repr = r.table.organisation_id.represent org_repr.bulk(list(branches)) # Construct the table header labels = TR( TH(T("Picture")), TH(T("Name")), TH(T("Last Name")), TH(T("National ID")), TH(T("Volunteer ID")), TH(T("Signature")), ) if not prog_id: labels.insert(1, TH(T("Program"))) if show_branch: labels.insert(1, TH(T("Branch"))) # Build the table body = TABLE(labels, _class="repeat-header shrink-to-fit") # Add the data rows for row in data.rows: raw = row._row # Picture picture = pictures.get(raw["pr_person.pe_id"]) if picture: picture = IMG( _src=picture, _width=80, ) else: picture = "" # Name name = s3_format_fullname( fname=raw["pr_person.first_name"], mname=raw["pr_person.middle_name"], lname="", truncate=False, ) # Build the row trow = TR( TD(picture), TD(name), TD(row["pr_person.last_name"]), TD(row["pr_national_id_identity.value"]), TD(row["hrm_human_resource.code"]), TD(), ) if not prog_id: trow.insert(1, TD(row["hrm_programme_hours.programme_id"])) if show_branch: trow.insert( 1, TD(org_repr(raw["hrm_human_resource.organisation_id"]))) body.append(trow) footer = DIV() from s3.codecs.pdf import EdenDocTemplate, S3RL_PDF doc = EdenDocTemplate(title=title) printable_width = doc.printable_width get_html_flowable = S3RL_PDF().get_html_flowable header_flowable = get_html_flowable(header, printable_width) body_flowable = get_html_flowable(body, printable_width) footer_flowable = get_html_flowable(footer, printable_width) # Build the PDF doc.build( header_flowable, body_flowable, footer_flowable, ) filename = "siglist.pdf" # Return the generated PDF response = current.response response.headers["Content-Type"] = contenttype(".pdf") disposition = "attachment; filename=\"%s\"" % filename response.headers["Content-disposition"] = disposition return doc.output.getvalue()
def layout(item): """ Layout Method (Item Renderer) """ # Manage flags: hide any disabled/unauthorized items if not item.authorized and not item.opts.always_display: item.enabled = False item.visible = False elif item.enabled is None or item.enabled: item.enabled = True item.visible = True if item.enabled and item.visible: items = item.render_components() if item.parent is not None: if item.attr._class: classes = item.attr._class.split(" ") else: classes = [] if item.parent.parent is None: # Item at the top-level? toplevel = True if item.opts.right: classes.append("menu-right") else: toplevel = False if item.components: classes.append("has-dropdown not-click") _class = " ".join(classes) # Menu item with Dropdown if item.get_first(enabled=True): _href = item.url() return LI( A(item.label, _href=_href, _id=item.attr._id), UL(items, _class="dropdown"), _class=_class, ) else: # Menu item without Drop-Down if toplevel: item_url = item.url() if item_url == URL(c="default", f="index"): classes.append("menu-home") if item.selected: classes.append("active") _class = " ".join(classes) icon = item.opts.icon if icon: label = LABEL(ICON(icon), item.label) else: label = item.label return LI( A( label, _href=item_url, _id=item.attr._id, _target=item.attr._target, ), _class=_class, ) else: # Submenu item if isinstance(item.label, dict): if "id" in item.label: return S3MainMenuDefaultLayout.checkbox_item( item) elif "name" in item.label: label = item.label["name"] else: return None else: label = item.label link = A( label, _href=item.url(), _id=item.attr._id, _target=item.attr._target, ) _class = " ".join(classes) return LI(link, _class=_class) else: # The main menu itself T = current.T settings = current.deployment_settings if item.opts.title_area: # Custom override title_area = item.opts.title_area else: # Standard: render a menu logo logo = settings.get_ui_menu_logo() if logo is None: # Render an icon logo = SPAN( settings.get_system_name_short(), _class="logo", ) elif isinstance(logo, str): # Assume image-URL logo = IMG( _src=logo, _class="logo", _alt=settings.get_system_name_short(), ) #else: # use as-is (assume HTML or T()) title_area = A( logo, _href=URL(c="default", f="index"), _title=T("Homepage"), ) # Arrange items left/right right = [] left = [] for item in items: if "menu-right" in item["_class"]: item.remove_class("menu-right") right.append(item) else: left.append(item) right.reverse() # Reverse if right-to-left if current.response.s3.rtl: right, left = left, right # Build top-bar HTML return NAV( UL( LI( title_area, _class="name", ), LI( A(SPAN(T("Menu"))), _class="toggle-topbar menu-icon", ), _class="title-area", ), SECTION( UL( right, _class="right", ), UL( left, _class="left", ), _class="top-bar-section", ), _class="top-bar", data={"topbar": " "}, ) else: return None
def render_table(submissions, duplicates=[]): """ Create the HTML table from submissions @param submissions (Dict): Dictionary of submissions to display @param duplicates (List): List of duplicate user ids @return (TABLE): HTML TABLE containing all the submissions """ status_dict = {"AC": "Accepted", "WA": "Wrong Answer", "TLE": "Time Limit Exceeded", "MLE": "Memory Limit Exceeded", "RE": "Runtime Error", "CE": "Compile Error", "SK": "Skipped", "HCK": "Hacked", "OTH": "Others"} table = TABLE(_class="striped centered") table.append(THEAD(TR(TH("User Name"), TH("Site"), TH("Site Handle"), TH("Time of submission"), TH("Problem"), TH("Language"), TH("Status"), TH("Points"), TH("View/Download Code")))) tbody = TBODY() for submission in submissions: span = SPAN() if submission.user_id: person_id = submission.user_id else: person_id = submission.custom_user_id # Check if the given custom_user is a duplicate # We need to do this because there might be a case # when a duplicate custom_user is created and then # his name or institute is changed for duplicate in duplicates: if duplicate[1] == person_id and duplicate[0]: person_id = current.db.custom_friend(duplicate[0]) break span = SPAN(_class="orange tooltipped", data={"position": "right", "delay": "50", "tooltip": "Custom User"}, _style="cursor: pointer; " + \ "float:right; " + \ "height:10px; " + \ "width:10px; " + \ "border-radius: 50%;") tr = TR() append = tr.append append(TD(DIV(span, A(person_id.first_name + " " + person_id.last_name, _href=URL("user", "profile", args=person_id.stopstalk_handle, extension=False), _target="_blank")))) append(TD(submission.site)) append(TD(A(submission.site_handle, _href=get_link(submission.site, submission.site_handle), _target="_blank"))) append(TD(submission.time_stamp)) append(TD(A(submission.problem_name, _href=URL("problems", "index", vars={"pname": submission.problem_name, "plink": submission.problem_link}, extension=False), _target="_blank"))) append(TD(submission.lang)) append(TD(IMG(_src=URL("static", "images/" + submission.status + ".jpg", extension=False), _title=status_dict[submission.status], _alt=status_dict[submission.status], _style="height: 25px; width: 25px;"))) append(TD(submission.points)) if submission.view_link: if current.auth.is_logged_in(): td = TD(A("View", _href=submission.view_link, _class="btn waves-light waves-effect", _style="background-color: #FF5722", _target="_blank"), " ") if submission.site != "HackerEarth": td.append(A("Download", _class="download-submission-button btn waves-light waves-effect", _style="background-color: #2196F3", _target="_blank", data={"view-link": submission.view_link, "site": submission.site})) append(td) else: append(TD(A("View", _class="btn tooltipped disabled", _style="background-color: #FF5722", _target="_blank", data={"position": "bottom", "delay": "50", "tooltip": "Login to View"}), " ", A("Download", _class="btn tooltipped disabled", _style="background-color: #2196F3", _target="_blank", data={"position": "bottom", "delay": "50", "tooltip": "Login to Download"}))) else: append(TD()) tbody.append(tr) table.append(tbody) return table
def get_vm_operations(vm_id): valid_operations_list = [] vmstatus = int(db(db.vm_data.id == vm_id).select(db.vm_data.status).first()['status']) if (vmstatus == VM_STATUS_RUNNING) or (vmstatus == VM_STATUS_SUSPENDED) or (vmstatus == VM_STATUS_SHUTDOWN): valid_operations_list.append(A(IMG(_src=URL('static','images/snapshot.png'), _height=20, _width=20), _href=URL(r=request, c='user' ,f='snapshot', args=[vm_id]), _title="Take VM snapshot", _alt="Take VM snapshot")) valid_operations_list.append(A(IMG(_src=URL('static','images/performance.jpg'), _height=20, _width=20), _href=URL(r=request, c='default' ,f='page_under_construction', args=[vm_id]), _title="Check VM performance", _alt="Check VM Performance")) if is_moderator(): if (db(db.host.id > 0).count() >= 2): valid_operations_list.append(A(IMG(_src=URL('static','images/migrate.png'), _height=20, _width=20), _href=URL(r=request, c = 'admin' , f='migrate_vm', args=[vm_id]), _title="Migrate this virtual machine", _alt="Migrate this virtual machine")) if is_moderator() or is_orgadmin() or is_faculty(): valid_operations_list.append(A(IMG(_src=URL('static','images/delete.png'), _height=20, _width=20), _onclick="confirm_vm_deletion()", _title="Delete this virtual machine", _alt="Delete this virtual machine")) if vmstatus == VM_STATUS_SUSPENDED: valid_operations_list.append(A(IMG(_src=URL('static','images/play2.png'), _height=20, _width=20), _href=URL(r=request, f='resume_machine', args=[vm_id]), _title="Unpause this virtual machine", _alt="Unpause on this virtual machine")) valid_operations_list.append(A(IMG(_src=URL('static','images/cpu.png'), _height=20, _width=20), _href=URL(r=request, f='adjrunlevel', args = vm_id), _title="Adjust your machines resource utilization", _alt="Adjust your machines resource utilization")) if vmstatus == VM_STATUS_SHUTDOWN: valid_operations_list.append(A(IMG(_src=URL('static','images/on-off.png'), _height=20, _width=20), _href=URL(r=request, f='start_machine', args=[vm_id]), _title="Turn on this virtual machine", _alt="Turn on this virtual machine")) valid_operations_list.append(A(IMG(_src=URL('static','images/clonevm.png'), _height=20, _width=20), _href=URL(r=request,c='default', f='request_clonevm', args=vm_id), _title="Request Clone vm", _alt="Request Clone vm")) valid_operations_list.append(A(IMG(_src=URL('static','images/disk.jpg'), _height=20, _width=20), _href=URL(r=request, c='default' ,f='page_under_construction', args=[vm_id]), _title="Attach Extra Disk", _alt="Attach Extra Disk")) if is_moderator(): valid_operations_list.append(A(IMG(_src=URL('static','images/vnc.jpg'), _height=20, _width=20), _href=URL(r=request, c='default' ,f='page_under_construction', args=[vm_id]), _title="Assign VNC", _alt="Assign VNC")) valid_operations_list.append(A(IMG(_src=URL('static','images/editme.png'), _height=20, _width=20), _href=URL(r = request, c = 'admin', f = 'edit_vmconfig', args = vm_id), _title="Edit VM Config", _alt="Edit VM Config")) if vmstatus == VM_STATUS_RUNNING: valid_operations_list.append(A(IMG(_src=URL('static','images/pause2.png'), _height=20, _width=20), _href=URL(r=request, f='pause_machine', args=[vm_id]), _title="Pause this virtual machine", _alt="Pause this virtual machine")) valid_operations_list.append(A(IMG(_src=URL('static','images/shutdown2.png'), _height=20, _width=20), _href=URL(r=request, f='shutdown_machine', args=[vm_id]), _title="Gracefully shut down this virtual machine", _alt="Gracefully shut down this virtual machine")) if (vmstatus == VM_STATUS_RUNNING) or (vmstatus == VM_STATUS_SUSPENDED): valid_operations_list.append(A(IMG(_src=URL('static','images/on-off.png'), _height=20, _width=20), _href=URL(r=request, f='destroy_machine', args= [vm_id]), _title="Forcefully power off this virtual machine", _alt="Forcefully power off this virtual machine")) if is_moderator(): valid_operations_list.append(A(IMG(_src=URL('static','images/user_add.png'), _height=20, _width=20), _href=URL(r = request, c = 'admin', f = 'user_details', args = vm_id), _title="Add User to VM", _alt="Add User to VM")) else: logger.error("INVALID VM STATUS!!!") raise return valid_operations_list
def render_table(submissions, duplicates=[]): """ Create the HTML table from submissions """ status_dict = { "AC": "Accepted", "WA": "Wrong Answer", "TLE": "Time Limit Exceeded", "MLE": "Memory Limit Exceeded", "RE": "Runtime Error", "CE": "Compile Error", "SK": "Skipped", "HCK": "Hacked", "OTH": "Others" } table = TABLE(_class="striped centered") table.append( THEAD( TR(TH("User Name"), TH("Site"), TH("Site Handle"), TH("Time of submission"), TH("Problem"), TH("Language"), TH("Status"), TH("Points"), TH("View Code")))) tbody = TBODY() for submission in submissions: tr = TR() append = tr.append span = SPAN() if submission.user_id: person_id = submission.user_id else: person_id = submission.custom_user_id # Check if the given custom_user is a duplicate # We need to do this because there might be a case # when a duplicate custom_user is created and then # his name or institute is changed for f in duplicates: if f[1] == person_id and f[0] != None: person_id = current.db.custom_friend(f[0]) break span = SPAN(_class="orange tooltipped", data={"position": "right", "delay": "50", "tooltip": "Custom User"}, _style="cursor: pointer; " + \ "float:right; " + \ "height:10px; " + \ "width:10px; " + \ "border-radius: 50%;") append( TD( DIV( span, A(person_id.first_name + " " + person_id.last_name, _href=URL("user", "profile", args=[person_id.stopstalk_handle], extension=False), _target="_blank")))) append(TD(submission.site)) append( TD( A(submission.site_handle, _href=get_link(submission.site, submission.site_handle), _target="_blank"))) append(TD(submission.time_stamp)) append( TD( A(submission.problem_name, _href=URL("problems", "index", vars={ "pname": submission.problem_name, "plink": submission.problem_link }, extension=False), _target="_blank"))) append(TD(submission.lang)) append( TD( IMG(_src=URL("static", "images/" + submission.status + ".jpg", extension=False), _title=status_dict[submission.status], _alt=status_dict[submission.status], _style="height: 25px; width: 25px;"))) append(TD(submission.points)) if submission.view_link: append( TD( A("View", _href=submission.view_link, _class="btn waves-light waves-effect", _style="background-color: #FF5722", _target="_blank"))) else: append(TD()) tbody.append(tr) table.append(tbody) return table
def comment_internal(self): is_author = False if self.session.auth and self.session.auth.user: is_author = True if self.session.auth.user.id == self.context.article.author else False self.db.Comments.article_id.default = self.context.article.id self.db.Comments.user_id.default = self.session.auth.user.id self.db.Comments.commenttime.default = self.request.now self.db.Comments.comment_text.label = self.T("Post your comment") from plugin_ckeditor import CKEditor ckeditor = CKEditor() self.db.Comments.comment_text.widget = ckeditor.basicwidget form = SQLFORM(self.db.Comments, formstyle='divs') if form.process( message_onsuccess=self.T('Comment included')).accepted: self.new_article_event( 'new_article_comment', self.session.auth.user, data={ 'event_text': form.vars.comment_text, 'event_link': "%s/%s#comment_%s" % (self.context.article.id, self.context.article.slug, form.vars.id) }) else: form = A( self.T("Login to post comments"), _class="button", _href=self.CURL( 'default', 'user', args='login', vars=dict(_next=self.CURL('article', 'show', args=[ self.context.article.id, self.context.article.slug ])))) comments = self.db( self.db.Comments.article_id == self.context.article.id).select( orderby=self.db.Comments.created_on) if comments and is_author: edit_in_place = ckeditor.bulk_edit_in_place( ["comment_%(id)s" % comment for comment in comments], URL('editcomment')) elif comments and self.session.auth and self.session.auth.user: usercomments = comments.find( lambda row: row.user_id == self.session.auth.user.id) if usercomments: edit_in_place = ckeditor.bulk_edit_in_place( ["comment_%(id)s" % comment for comment in usercomments], URL('editcomment')) else: edit_in_place = ('', '') else: edit_in_place = ('', '') return DIV(H4( IMG(_src=URL('static', '%s/images/icons' % self.context.theme_name, args='board.24.png')), self.T("Comments")), UL( *[ LI(H5( A(self.T("%s %s" % (comment.nickname or comment.user_id, self.db.pdate(comment.commenttime))), _href=self.CURL('person', 'show', args=comment.nickname or comment.user_id))), DIV( XML(comment.comment_text), **{ '_class': 'editable commentitem', '_data-object': 'comment', '_data-id': comment.id, '_id': "comment_%s" % comment.id }), _class="comment_li") for comment in comments ], **dict(_class="comment_ul")), edit_in_place[1], form, _class="internal-comments article-box")