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 add(): form = Form(db.bird, csrf_session=session, formstyle=FormStyleBulma) if form.accepted: redirect(URL('index')) # else: # db.bird.insert(bird_name=request.params.get("bird_name")) # db.bird.insert(bird_weight=request.params.get("bird_weight")) # db.bird.insert(bird_diet=request.params.get("bird_diet")) # db.bird.insert(bird_habitat=request.params.get("bird_habitat")) # redirect(URL('index')) return dict(form=form)
def popualate_database(): groups = get_groups() users = get_users() filters = get_filters() smpp_cons = get_smppcons() http_cons = get_httpcons() mt_routes = get_mtroutes() mo_routes = get_moroutes() mo_interceptors = get_imos() mt_interceptors = get_imts() flash.set('Database populated with existing Jasmin data') redirect(URL('index'))
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 imt_remove(order): script = '' filters = '' order = order resp= jasmin.interceptor(['mt','remove', order, script,filters[:-1]]) if resp: flash.set(resp) else: flash.set("Removed MO Interceptor with order %s" % order) query = (db.j_imt.mtorder == order)&(db.j_imt.gw == session.g_id) db(query).delete() redirect(URL('manage_imt'))
def register(self): self.auth.db.auth_user.password.writable = True fields = [field for field in self.auth.db.auth_user if field.writable] for k, field in enumerate(fields): if field.type == "password": fields.insert( k + 1, Field( "password_again", "password", requires=IS_EQUAL_TO(request.forms.get("password")), label=self.auth.param.messages["labels"].get("password_again"), ), ) break button_name = self.auth.param.messages["buttons"]["sign-up"] # if the form is submitted, before any validation # delete any unverified account with the same email if request.method == "POST": email = request.forms.get("email") if email: self.auth.get_or_delete_existing_unverified_account(email) form = Form(fields, submit_value=button_name, formstyle=self.formstyle) user = None if form.accepted: # notice that here the form is alrealdy validated res = self.auth.register(form.vars, validate=False) form.errors.update(**res.get("errors", {})) form.accepted = not form.errors if form.accepted: self._set_flash("user-registered") self._postprocessing("register", form, user) if self.auth.param.login_after_registration: redirect("login") form.param.sidecar.append( A( self.auth.param.messages["buttons"]["sign-in"], _href="../auth/login", _class=self.auth.param.button_classes["sign-in"], _role="button", ) ) if self.auth.allows("request_reset_password"): form.param.sidecar.append( A( self.auth.param.messages["buttons"]["lost-password"], _href="../auth/request_reset_password", _class=self.auth.param.button_classes["lost-password"], _role="button", ) ) return form
def edit_profile(): user = auth.get_user() db.profile.update_or_insert(user_id=user["id"]) profile = db.profile[user["id"]] form = Form([Field('avatar', type='upload'), Field('bio', type='text')], csrf_session=session, formstyle=FormStyleBulma) if form.accepted: db(db.profile.user_id == user["id"]).validate_and_update( avatar=form.vars['avatar'], bio=form.vars['bio']) redirect(URL('profile')) return dict(profile=profile, form=form)
def add_contact(): form = Form([ Field('first_name', requires=IS_NOT_EMPTY()), Field('last_name', requires=IS_NOT_EMPTY()) ], csrf_session=session, formstyle=FormStyleBulma) if form.accepted: db.person.insert(first_name=form.vars.get('first_name'), last_name=form.vars.get('last_name'), phone_numbers="") redirect(URL('index')) return dict(form=form)
def add_contact(): # Form displayed to user form = Form(db.contacts, csrf_session=session, formstyle=FormStyleBulma, validation=validate_contact) # Form inputs were accepted redirect to home page if form.accepted: redirect(URL('index')) return dict(form=form)
def edit_username(): user = db(db.friend_code.user_email == get_user_email()).select() user = user[0] if user is None: redirect(URL('index')) form = Form(db.friend_code, record=user, deletable=False, csrf_session=session, formstyle=FormStyleBulma) if form.accepted: updateDrawingUsernames(user) redirect(URL('index')) return dict(form=form)
def list_phone(person_id=None): logged_in_user = auth.current_user.get('email') person = db.person[person_id] name = person['first_name'] + " " + person['last_name'] if person is None: redirect(URL('index')) elif(person.user_email == logged_in_user): row = db(db.phone.person_id == person_id).select() return dict(rows=row, url_signer=url_signer, person_id=person_id, name=name) else: redirect(URL('index'))
def phone_index(contact_id=None): curr_user = auth.current_user.get('email') p = db.person[contact_id] first_name = db.person[contact_id].first_name last_name = db.person[contact_id].last_name if p is None: redirect(URL('index')) elif p.user_email != curr_user: redirect(URL('index')) else: rows = db(db.contact.contact_id == contact_id).select() return dict(rows=rows, contact_id=contact_id, name=first_name + " " + last_name, url_signer=url_signer)
def delete_product(person_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.person[person_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 == person_id).delete() deleted = db.person[person_id] if deleted is None: redirect(URL('index')) return dict(deleted=deleted)
def edit(bird_id=None): assert bird_id is not None p = db.bird[bird_id] if p is None: # nothing found to be edited redirect(URL('index')) form = Form(db.bird, record=p, deletable=False, csrf_session=session, formstyle=FormStyleBulma) if form.accepted: redirect(URL('index')) return dict(form=form)
def matches(userID=None): assert userID is not None user = db.dbuser[userID] if user is None: redirect(URL('index')) return dict( get_matches_id_url=URL('get_matches_id',signer=url_signer), get_curr_matches_url=URL('get_curr_matches', signer=url_signer), delete_match_url=URL('delete_match', signer=url_signer), url_signer=url_signer, user=user, auth = get_user(), )
def edit(contact_id=None): assert contact_id is not None p = db.contact[contact_id] print('hi edit contact') if p is None: # nothing found to be edited redirect(URL('index')) form = Form(db.contact, record=p, deletable=False, csrf_session=session, formstyle=FormStyleBulma) if form.accepted: redirect(URL('index')) return dict( form = form )
def clean(): user = db(db.users.user == Helper.get_user()).select().first() if user == None or user['role'] != "admin": redirect(URL('index')) db(db.users).delete() db(db.tickets).delete() db(db.global_tag).delete() db(db.sub_tickets).delete() db(db.ticket_tag).delete() db(db.user_tag).delete() db(db.user_pins).delete() db(db.comment).delete() return "ok"
def edit(bird_id=None): assert bird_id is not None bird = db(db.bird.id == bird_id).select().first() if bird is None: #Nothing to edit redirect(URL('index')) form = Form(db.bird, record=bird, deletable=False, csrf_session=session, formstyle=FormStyleBulma) if form.accepted: #Edit already happened redirect(URL('index')) return dict(form=form)
def edit_phones(person_id=None): p = db.person[person_id] contact_person = p.first_name + " " + p.last_name user_email = p.user_email if p is None: redirect(URL('index')) if (p.user_email != auth.current_user.get('email')): redirect(URL('index')) else: rows = db(db.phone.person_id == p.id).select() return dict(rows=rows, url_signer=url_signer, contact_person=contact_person, person_id=person_id, user_email=user_email)
def abort_or_redirect(self, page, message=''): """ return HTTP 403 if 'application/json' in HTTP_ACCEPT else redirects to page""" if REX_APPJSON.search(request.headers.get("accept", "")): abort(403) redirect_next = request.fullpath if request.query_string: redirect_next = redirect_next + "?{}".format(request.query_string) redirect( URL( self.auth.route, page, vars=dict(next=redirect_next, flash=message), use_appname=self.auth.use_appname_in_redirects, ))
def add_post(): user = auth.get_user() or redirect(URL('auth/login')) first_name = user.get('first_name') last_name = user.get('last_name') email = user.get('email') username = user.get('username') thumbs_up = [] thumbs_down = [] now = datetime.datetime.now() id = db.post.insert( content=request.json.get('content'), first_name=first_name, last_name=last_name, author_email=email, username=username, thumbs_up=thumbs_up, thumbs_down=thumbs_down, datetime=now, ) return dict( id=id, first_name=first_name, last_name=last_name, email=email, username=username, thumbs_up=thumbs_up, thumbs_down=thumbs_down, datetime=now, )
def load_post(post_id): user = auth.get_user() or redirect(URL('auth/login')) return dict( post=db(db.post.id == post_id).select().as_list()[0], email=user.get("email"), rows=db(db.comment.parent_post == post_id).select().as_list(), )
def add_comment(): user = auth.get_user() or redirect(URL('auth/login')) email = user.get('email') username = user.get('username') thumbs_up = [] thumbs_down = [] now = datetime.datetime.now() id = db.comment.insert( parent_post=request.json.get('post_id'), content=request.json.get('content'), author_email=email, username=username, thumbs_up=thumbs_up, thumbs_down=thumbs_down, datetime=now, ) return dict( id=id, email=email, username=username, thumbs_up=thumbs_up, thumbs_down=thumbs_down, datetime=now, )
def phone_numbers(contact_id=None): """Note that in the above declaration, the contact_id argument must match the <contact_id> argument of the @action.""" # We read the contact. c = db.contact[contact_id] user_email = auth.current_user.get('email') if c is None or c.user_email != user_email: # No contact or wrong user redirect(URL('index')) phones = db(db.phone.contact_id == contact_id).select() contact = f'{c.first_name} {c.last_name}' return dict(contact_id=contact_id, contact=contact, phones=phones, url_signer=url_signer)
def add_song(band_id=None, album_id=None): assert band_id is not None assert album_id is not None form = Form([ Field('name', requires=IS_NOT_EMPTY()), Field('lyrics', type='text', requires=IS_NOT_EMPTY()) ], csrf_session=session, formstyle=FormStyleBulma) if form.accepted: db.song.insert(band_id=band_id, album_id=album_id, name=form.vars['name'], lines=form.vars['lyrics'].split('\r\n')) redirect(URL('album/', db.album[album_id].name)) return dict(form=form)
def add_album(band_id=None): assert band_id is not None form = Form([ Field('name', requires=IS_NOT_EMPTY()), Field('image', type='upload'), Field('date', type='date', requires=IS_DATE()) ], csrf_session=session, formstyle=FormStyleBulma) if form.accepted: db.album.insert(band_id=band_id, name=form.vars['name'], image=form.vars['image'], date=form.vars['date']) redirect(URL('band/', db.band[band_id].name)) return dict(form=form)
def edit_smpp_connector(cid): if not cid: flash.set('No connector selected you need to select a connector') redirect(URL('manage_smpp_connecors')) con = cid back = '' title = "Edit SMPP connector %s" % con query = db.connector.name == con cc = db(query).select().first() db.connector.id.readable = db.connector.id.writable = False db.connector.name.readable = db.connector.name.writable = False db.connector.name.default = con db.connector.c_logfile.default = '/var/log/jasmin/default-%s.log' % con back = '' if cc: # we already have a record print('Inside have one') form = Form(db.connector, cc, deletable=False, formstyle=FormStyleBulma) else: print('inside new one') form = Form(db.connector, deletable=False, formstyle=FormStyleBulma) if form.accepted: ret = jasmin.connector(['update',con,\ form.vars['c_ripf'],form.vars['c_con_fail_delay'],form.vars['c_dlr_expiry'],\ form.vars['c_coding'],form.vars['c_logrotate'],form.vars['c_submit_throughput'],\ form.vars['c_elink_interval'],form.vars['c_bind_to'],form.vars['c_port'],form.vars['c_con_fail_retry'],\ form.vars['c_password'],form.vars['c_src_addr'],form.vars['c_bind_npi'],form.vars['c_addr_range'],\ form.vars['c_dst_ton'],form.vars['c_res_to'],form.vars['c_def_msg_id'],form.vars['c_priority'],\ form.vars['c_con_loss_retry'],form.vars['c_username'],form.vars['c_dst_npi'],form.vars['c_validity'],\ form.vars['c_requeue_delay'],form.vars['c_host'],form.vars['c_src_npi'],form.vars['c_trx_to'],form.vars['c_logfile'],\ form.vars['c_ssl'],form.vars['c_loglevel'],form.vars['c_bind'],form.vars['c_proto_id'],form.vars['c_dlr_msgid'],\ form.vars['c_con_loss_delay'],form.vars['c_bind_ton'],form.vars['c_pdu_red_to'],form.vars['c_src_ton'],]) if not ret: flash.set("Successfully updated connector %s" % con) redirect(URL('manage_smpp_connectors')) else: flash.set(ret) elif form.errors: flash.set('Form has errors') else: flash.set('Please refer to the Jasmin User Guide when updating values') return dict(content=form, back=back, title=title, caller='../manage_smpp_connectors')
def mt_default(route_type=None): if not route_type: flash.set('You need to select a route type') redirect(URL('manage_mt_routes')) t = route_type title = 'New Default Route' form = Form([ Field('mt_connectors', 'reference connector', requires=IS_IN_DB(db, 'connector.id', 'connector.name'), label='SMPP Connector', comment='SMPP connector needs to be available'), Field( 'mt_rate', 'string', length=10, label='Rate', comment= 'Decimal rate value for the connector. All messages going over this connector will be charged at the rate specified' ), ], dbio=False, formstyle=FormStyleBulma) if form.accepted: con = db.connector[form.vars['mt_connectors']].name cons = 'smppc(' + con + ')' order = '0' rate = form.vars['mt_rate'] connectors = [form.vars['mt_connectors']] print('Connectors', connectors) resp = jasmin.mtrouter(['DefaultRoute', cons, rate]) print('resp', resp) if not resp: id = db.mtroute.update_or_insert(db.mtroute.mt_order == 0, mt_order=0, mt_type=t, mt_connectors=connectors, mt_rate=form.vars['mt_rate']) if id: flash.set('Added new %s with order %s' % (t, '0')) else: flash.set('Updated %s with order %s' % (t, '0')) else: flash.set('Problems adding route %s' % resp) redirect(URL('manage_mt_routes')) return dict(content=form, title=title, caller='../manage_mt_routes')
def edit_contact(contact_id=None): """Note that in the above declaration, the contact_id argument must match the <contact_id> argument of the @action.""" # We read the contact. p = db.contact[contact_id] if p is None or p.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=p, 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 admin_save_slides(): if random.random() < 0.5: raise HTTP(500) insert_slides = [ i for i in request.json.get('slides') if i.get('id') == None ] update_slides = [ i for i in request.json.get('slides') if i.get('id') != None ] a = db.slides.bulk_insert(insert_slides) for s in update_slides: db.slides[s.get('id')] = s #db.slides.bulk_update(update_slides) redirect(URL('admin_getslides')) return