def start_smpp_connector(cid): if not cid: flash.set('You need to select a connector to start') redirect(URL('manage_smpp_connectors')) con = cid t = jasmin.connector(['start', con]) flash.set("Started Connector %s" % con) redirect(URL('manage_smpp_connectors'))
def lobbies(): print("lobby page reached") return dict( # URLS used for callbacks and HTTP requests add_lobby_url=URL('add_lobby', signer=url_signer), load_lobbies_url=URL('load_lobbies', signer=url_signer), )
def index(): return dict( # COMPLETE: return here any signed URLs you need. # test pycharm connection load_posts_url=URL('load_posts', signer=url_signer), add_post_url=URL('add_post', signer=url_signer), delete_post_url=URL('delete_post', signer=url_signer), )
def __call__(self, id=None): return XML( ThumbRater.THUMBRATER.format(url=URL(self.url, id, signer=self.signer), callback_url=URL(self.callback_url, id, signer=self.signer)))
def __call__(self, id=None, redirect_url=None): """This method returns the element that can be included in the page. @param id: if an id is specified, the form is an update form for the specified record id. @param redirect_url: URL to which to redirect after success.""" return XML(VueForm.FORM.format(url=URL(self.url, id, signer=self.signer), check_url=URL(self.url_check, id, signer=self.signer), redirect_url=redirect_url))
def delete_contact(person_id=None, phone_id=None): p = db.person[person_id] if p is None: redirect(URL('index')) # else delete person if has access if (p.user_email == auth.current_user.get('email')): db(db.phone.id == phone_id).delete() redirect(URL('edit_phones', person_id))
def render_table_header(self): up = I(**self.param.grid_class_style.get("grid-sorter-icon-up")) dw = I(**self.param.grid_class_style.get("grid-sorter-icon-down")) columns = [] sort_order = request.query.get("orderby", "") for index, field in enumerate(self.param.fields): if field.readable and (field.type != "id" or self.param.show_id): key = "%s.%s" % (field.tablename, field.name) heading = ( self.param.headings[index] if index < len(self.param.headings) else field.label ) heading = title(heading) # add the sort order query parm sort_query_parms = dict(self.query_parms) attrs = {} if isinstance(field, FieldVirtual): col = DIV(heading) elif key == sort_order: sort_query_parms["orderby"] = "~" + key url = URL(self.endpoint, vars=sort_query_parms) attrs = self.attributes_plugin.link(url=url) col = A(heading, up, **attrs) else: sort_query_parms["orderby"] = key url = URL(self.endpoint, vars=sort_query_parms) attrs = self.attributes_plugin.link(url=url) col = A(heading, dw if "~" + key == sort_order else "", **attrs) columns.append((key, col)) thead = THEAD(_class=self.param.grid_class_style.classes.get("grid-thead", "")) for key, col in columns: col_class = " grid-col-%s" % key thead.append( TH( col, _class=self.param.grid_class_style.classes.get("grid-th", "") + col_class, _style=self.param.grid_class_style.styles.get("grid-th"), ) ) if ( self.param.details or self.param.editable or self.param.deletable or self.param.pre_action_buttons or self.param.post_action_buttons ): thead.append( TH("", **self.param.grid_class_style.get("grid-th-action-button")) ) return thead
def api(self): """The API must return the data to fill the table. The data is a dictionary, containing: - page: <integer> - search_placeholder: <string> - has_more: <boolean> - rows: <list of rows (see below)> A row is a dictionary, containing: - is_header: <boolean> - cells: <cells> <cells> is a list of dictionaries, containing: - text: <text> - url: <text> or None - is_button: <boolean> - sortable: <boolean> (valid only of the row is a header) - sort: <int> (+1 for sort up, -1 for sort down, 0 for no sort) - el_class: <text> or None (class of element, if needed) All the fields except text are optional. This is a sample implementation only, to test code. You should over-ride the api method to provide your own input for the table. """ page = request.query.get('page') or 1 q = request.query.get("q", "") # Query string sort_order = request.query.get("sort_order") or None header = dict(is_header=True, cells=[ dict(text="Animal", sortable=True), dict(text="N. paws", sortable=True), dict(text="Class") ]) # Copies the sort_order into the header, to reflect that the request has been # satisfied. Note that we are doing server-side sorting, as the set of # results can be very large and the web UI may have only a small set of the results. # The reason why sort order is repeated in the answer is that the server might # want to be able to communicate to the web UI what sort order has truly been # used when producing the table. if sort_order is not None: for hc, so in zip(header["cells"], json.loads(sort_order)): hc["sort"] = so row1 = dict(cells=[ dict(text="Cat"), dict(text="4"), dict(text="Mammal", url=URL('mammals/cat'), is_button=True) ]) row2 = dict(cells=[ dict(text="Dog"), dict(text="4"), dict(text="Mammal", url=URL('mammals/dog'), is_button=True) ]) row3 = dict(cells=[ dict(text="Owl"), dict(text="2"), dict(text="Bird", url=URL('bird/owl'), is_button=True) ]) return dict(page=int(page), search_placeholder=self.search_placeholder, has_more=True, rows=[header, row1, row2, row3])
def __call__(self, redirect_url=None): """This method returns the element that can be included in the page. The *args and **kwargs are used when subclassing, to allow for forms that are 'custom built' for some need.""" return XML( VueForm.FORM.format(url=URL(self.url, signer=self.signer), check_url=URL(self.url_check, signer=self.signer), redirect_url=redirect_url))
def delete_http_con(cid): if not cid: flash.set('Please select a connector to delete') redirect(URL('manage_http_connectors')) con = cid t = jasmin.http_cons(['remove', con]) flash.set('Removed Connector %s' % con) db(db.http_cons.hcon_cid == con).delete() redirect(URL('manage_http_connectors'))
def index(): return dict( # This is the signed URL for the callback. star_url=URL('star', signer=url_signer), load_classes_url=URL('load_classes', signer=url_signer), load_contacts_url=URL('load_contacts', signer=url_signer), file_info_url=URL('file_info', signer=url_signer), )
def delete_contact(contact_id=None): # We read the product. user = auth.current_user.get('email') c = db.contact[contact_id] if c is None or c.user_email!=user: # Nothing to edit. This should happen only if you tamper manually with the URL. redirect(URL('index')) db(db.contact.id==contact_id).delete() redirect(URL('index'))
def index(): return dict( # This is an example of a signed URL for the callback. # See the index.html template for how this is passed to the javascript. posts_url=URL('posts', signer=url_signer), delete_url=URL('delete_post', signer=url_signer), user_email=auth.current_user.get('email'), author_name=auth.current_user.get('first_name') + " " + auth.current_user.get('last_name'))
def delete_filter(fid): if not fid: flash.set('You need to select a filter to delet') redirect(URL('manage_filters')) res = jasmin.filters(['delete', fid]) flash.set('Removed Filter %s' % fid) query = db.mt_filter.fid == fid db(query).delete() redirect(URL('manage_filters'))
def delete_contact(person_id=None, phone_id=None): # We read the product. user = auth.current_user.get('email') person = db.contact[person_id] if person is None or person.user_email!=user or phone_id is None: # Nothing to edit. This should happen only if you tamper manually with the URL. redirect(URL('list_phone',person_id)) db(db.phone.id==phone_id).delete() redirect(URL('list_phone',person_id))
def api(self, id=None): """Returns data according to the API request.""" # Builds the header. header = dict( is_header=True, cells=[ dict(text="First Name", sortable=True), dict(text="Last Name", sortable=True), dict(text="Arrival Time", sortable=True), dict(text="", sortable=False), # Icons ], ) # Gets the request parameters, and copies the sort order in the header. req = self._get_request_params(header) timezone = request.query.get("timezone") q = request.query.get("q", "") # Query string # Forms the query. if q: query = db( db.vue_form_table.first_name.contains(q) | db.vue_form_table.last_name.contains(q)) else: query = db.vue_form_table # Forms the select. rows = db(query).select(**req.search_args) # Builds the result rows. result_rows = [] for r in rows: cells = [] cells.append(dict(text=r.first_name)) cells.append(dict(text=r.last_name)) cells.append(dict(text=r.arrival_time.isoformat(), type="date")) cells.append( dict(raw_html=SPAN( A( I(_class="fa fa-eye"), _href=URL("vue_view_form", r.id, signer=self.signer), ), " ", A( I(_class="fa fa-pen"), _href=URL("vue_edit_form", r.id, signer=self.signer), ), ).xml())) result_rows.append( dict(cells=cells, delete=URL("delete_row", r.id, signer=self.signer))) has_more, result_rows = self._has_more(result_rows) return dict( page=req.page, has_search=True, has_delete=True, search_placeholder="", has_more=has_more, rows=[header] + result_rows, )
def index(): db.user.update_or_insert( db.user.user_id == session['uuid'], user_id=session['uuid'], ) return dict(post_guess_url=URL('check_guess'), get_cards_url=URL('deal_cards'), get_init_game_state_url=URL('get_init_game_state'), score_to_leaderboard_url=URL('score_to_leaderboard'), get_game_time_url=URL('get_game_time'))
def grid(self, table): name = 'vue%s' % str(uuid.uuid4())[:8] return DIV(self.mtable(table), TAG.SCRIPT(_src=URL('static/js/axios.min.js')), TAG.SCRIPT(_src=URL('static/js/vue.min.js')), TAG.SCRIPT(_src=URL('static/js/utils.js')), TAG.SCRIPT(_src=URL('static/components/mtable.js')), TAG.SCRIPT( XML('var app=utils.app("%s"); app.start()' % name)), _id=name)
def delete_product(product_id=None): """Note that in the above declaration, the product_id argument must match the <product_id> argument of the @action.""" # We read the product. p = db.product[product_id] if p is None: # Nothing to edit. This should happen only if you tamper manually with the URL. redirect(URL('index')) db(db.product.id == product_id).delete() redirect(URL('index'))
def new_event(eid=None): db.event.startdatetime.default = ( datetime.datetime.utcnow() + datetime.timedelta(days=10)).strftime("%Y-%m-%d %H:%M:00") db.event.enddatetime.default = ( datetime.datetime.utcnow() + datetime.timedelta(days=10)).strftime("%Y-%m-%d %H:%M:00") db.event.projid.requires = IS_IN_DB( db((db.project.proj_shared == True) | (db.project.proj_owner == auth.user_id)), 'project.id', '%(proj_name)s') try: db.event.projid.default = session.get( 'projid', db(db.project.name == 'Unspecified').select( db.project.id).first().id) except AttributeError: pass eid = int(eid) if eid and eid.isnumeric() else None if eid: islocked = db(db.event.id == eid).select('locked', 'prev_event').first() if islocked.locked: flash.set("Locked Event cannot be edited", sanitize=True) redirect(URL('eventgrid')) form = Form(db.event, record=eid, formazstyle=FormStyleBulma) db.event.prev_event.requires = IS_EMPTY_OR( IS_IN_DB(db, 'event.id', '%(event_name)s')) if eid: proj = db(db.project.id == form.vars['projid']).select().first() if (not proj.proj_shared) and proj.proj_owner != auth.user_id: flash.set("Not Editable by You", sanitize=True) form.deletable = False form.readonly = True if form.vars.get('event_name', '') == 'Unspecified': form.deletable = False if form.accepted: session['eventid'] = form.vars['id'] # Now want to establish if prev_event has been set and if it has we need to select it and link it's next # event to this one in order for archiving to work # so either eid and changed prev_event or created new record with an event id then we need the prev_event # and created event and update accordingly # TODO decide if need to remove if we blank - probably less urgent but should be done if not eid and form.vars['prev_event'] or ( eid and form.vars['prev_event'] != islocked['prev_event']): orig_rec = db( db.event.id == form.vars['prev_event']).select().first() orig_rec.update_record(next_event=form.vars['id']) db.commit() redirect(URL('eventgrid')) return dict(form=form)
def users(): user = db(db.users.user == Helper.get_user()).select().first() if user == None: redirect(URL('create_profile')) return dict(get_users_url=URL('users/get_users', signer=signed_url), get_icons_url=URL('users/get_icons', signer=signed_url), edit_user_url=URL('edit_user', signer=signed_url), user_email=Helper.get_user_email(), username=Helper.get_user_title(), user=auth.get_user())
def __call__(self, id=None): """This method returns the element that can be included in the page. @param id: id of the file uploaded. This can be useful if there are multiple instances of this form on the page.""" return XML( ThumbRater.THUMBRATER.format(url=URL(self.url, id, signer=self.signer), callback_url=URL(self.callback_url, id, signer=self.signer)))
def edit_contact(contact_id=None): # We read the contact. c = db.contact[contact_id] if c is None or c.user_email!=auth.current_user.get('email'): # Nothing to edit. This should happen only if you tamper manually with the URL. redirect(URL('index')) form = Form(db.contact, record=c, deletable=False, csrf_session=session, formstyle=FormStyleBulma) if form.accepted: # We always want POST requests to be redirected as GETs. redirect(URL('index')) return dict(form=form)
def new_location(lid=None): lid = int(lid) if lid and lid.isnumeric() else None if lid: islocked = db(db.locn.id == lid).select('locked').first() if islocked.locked: flash.set("Locked records cannot be edited") redirect(URL('locationgrid')) form = Form(db.locn, lid, formstyle=FormStyleBulma) if form.accepted: redirect(URL('locationgrid')) return dict(form=form)
def delete_person(contact_id=None): # We delete the contact. p = db.person[contact_id] if p is None: # Nothing to edit. This should happen only if you tamper manually with the URL. redirect(URL('index')) db(db.person.id == contact_id).delete() deleted = db.person[contact_id] if deleted is None: # We always want POST requests to be redirected as GETs. redirect(URL('index')) return dict(deleted=deleted)
def index(): return dict( # This is an example of a signed URL for the callback. get_posts_url=URL('get_posts', signer=url_signer), add_post_url=URL('add_post', signer=url_signer), delete_post_url=URL('delete_post', signer=url_signer), thumb_post_url=URL('thumb_post', signer=url_signer), # Add other callbacks here. user_email=get_user_email(), user=auth.user, username=auth.current_user.get('first_name') + " " + auth.current_user.get("last_name"))
def create_user(): user = db(db.users.user == Helper.get_user()).select().first() if user != None: redirect(URL('index')) return dict( add_user_url=URL('add_user', signer=signed_url), user=auth.get_user(), username=Helper.get_user_title(), admin=db(db.users).isempty(), tags=Helper.get_tags_list_approved(), )
def grid(self, table): name = "vue%s" % str(uuid.uuid4())[:8] return DIV( self.mtable(table), TAG.SCRIPT(_src=URL("static/js/axios.min.js")), TAG.SCRIPT(_src=URL("static/js/vue.min.js")), TAG.SCRIPT(_src=URL("static/js/utils.js")), TAG.SCRIPT(_src=URL("static/components/mtable.js")), TAG.SCRIPT(XML('var app={}; app.vue = new Vue({el:"#%s"});' % name)), _id=name, )
def edit(contact_id=None): if contact_id is None: redirect(URL('index')) p = db.contact[contact_id] if p is None: redirect(URL('index')) form = Form(db.contact, record=p, csrf_session=session, deletable=False, formstyle=FormStyleBulma) if form.accepted: redirect(URL('index')) return dict(form=form)
def delete_phone(contact_id=None, row_id=None): curr_user = auth.current_user.get('email') p = db.person[contact_id] if p is None: redirect(URL('index')) elif row_id is None: redirect(URL('index')) else: if (p.user_email == curr_user): db(db.contact.id == row_id).delete() redirect(URL('phone_index', contact_id))