def POST_resend_link(self, user): key = "account/%s/verify"%user.username activation_link = web.ctx.site.store.get(key) del activation_link user.send_verification_email() add_flash_message("info", "Activation mail has been resent.") raise web.seeother(web.ctx.path)
def POST(self, path): i = web.input(_method='post') i = web.storage(helpers.unflatten(i)) i.key = path _ = web.storage((k, i.pop(k)) for k in i.keys() if k.startswith('_')) action = self.get_action(_) comment = _.get('_comment', None) for k, v in i.items(): i[k] = self.trim(v) p = web.ctx.site.get(path) or web.ctx.site.new(path, {}) p.update(i) if action == 'preview': p['comment_'] = comment return render.editpage(p, preview=True) elif action == 'save': try: p._save(comment) path = web.input(_method='GET', redirect=None).redirect or web.changequery(query={}) raise web.seeother(path) except (ClientException, db.ValidationException), e: add_flash_message('error', str(e)) p['comment_'] = comment return render.editpage(p)
def POST(self): i = web.input() f = form_talk() if not f.validates(i): return render_template("talks/submit", form=f) key = new_talk(i) if config.get('from_address') and config.get('talk_submission_contact'): email = render_template("talks/email", i) web.sendmail( from_address=config.from_address, to_address=config.talk_submission_contact, subject=web.safestr(email.subject.strip()), message=web.safestr(email) ) dir = config.get("talks_dir", "/tmp/talks") write("%s/%s.txt" % (dir, time.time()), simplejson.dumps(i)) tweet.tweet("talk_template", title=i.title, author=i.authors, url=web.ctx.home + "/" + key) add_flash_message("info", "Thanks for submitting your talk. The selection committee will review your talk and get in touch with you shortly.") raise web.seeother("/" + key)
def POST(self, key): i = web.input(_method="POST") if "_delete" in i: doc = web.ctx.site.store.get(key) if doc: doc['current_status'] = "deleted" web.ctx.site.store[doc['_key']] = doc add_flash_message("info", "The requested library has been deleted.") raise web.seeother("/libraries/dashboard") i._key = web.rstrips(i.key, "/").replace(" ", "_") page = libraries_dashboard()._create_pending_library(i) if web.ctx.site.get(page.key): raise web.notfound("error", "URL %s is already used. Please choose a different one." % page.key) elif not i.key.startswith("/libraries/"): raise web.notfound( "The key must start with /libraries/." ) doc = web.ctx.site.store.get(key) if doc and "registered_on" in doc: page.registered_on = {"type": "/type/datetime", "value": doc['registered_on']} page._save() if doc: doc['current_status'] = "approved" doc['page_key'] = page.key web.ctx.site.store[doc['_key']] = doc raise web.seeother(page.key)
def POST_block_account_and_revert(self, account): account.block() changes = account.get_recentchanges(limit=1000) changeset_ids = [c.id for c in changes] ipaddress_view().revert(changeset_ids, "Reverted Spam") add_flash_message("info", "Blocked the account and reverted all edits.") raise web.seeother(web.ctx.path)
def POST(self, key): i = web.input(v=None, _method="GET") recap_plugin_active = 'recaptcha' in config.get('plugins') if recap_plugin_active: public_key = config.plugin_recaptcha.public_key private_key = config.plugin_recaptcha.private_key recap = recaptcha.Recaptcha(public_key, private_key) if not recap.validate(): return 'Recaptcha solution was incorrect. Please <a href="javascript:history.back()">go back</a> and try again.' v = i.v and safeint(i.v, None) work = web.ctx.site.get(key, v) if work is None: raise web.notfound() try: helper = SaveBookHelper(work, None) helper.save(web.input()) add_flash_message("info", utils.get_message("flash_work_updated")) raise web.seeother(work.url()) except (ClientException, ValidationException), e: add_flash_message('error', str(e)) return self.GET(key)
def POST(self, path): p = db.get_version(path) if not p: raise web.seeother(path) i = web.input('permission.key', 'child_permission.key') q = { 'key': path, 'permission': { 'connect': 'update', 'key': i['permission.key'] or None, }, 'child_permission': { 'connect': 'update', 'key': i['child_permission.key'] or None, } } try: web.ctx.site.write(q) except Exception, e: import traceback traceback.print_exc(e) add_flash_message('error', str(e)) return render.permission(p)
def POST(self, key): i = web.input(v=None, _method="GET") if spamcheck.is_spam(): return render_template("message.html", "Oops", 'Something went wrong. Please try again later.') recap = get_recaptcha() if recap and not recap.validate(): return render_template("message.html", 'Recaptcha solution was incorrect', 'Please <a href="javascript:history.back()">go back</a> and try again.' ) v = i.v and safeint(i.v, None) work = web.ctx.site.get(key, v) if work is None: raise web.notfound() try: helper = SaveBookHelper(work, None) helper.save(web.input()) add_flash_message("info", utils.get_message("flash_work_updated")) raise web.seeother(work.url()) except (ClientException, ValidationException) as e: add_flash_message('error', str(e)) return self.GET(key)
def POST_reopencase(self, form, case): user = accounts.get_current_user() by = user.get_email() text = "Case reopened" case.add_worklog_entry(by = by, text = text) case.change_status("new", by) add_flash_message("info", "Case reopened")
def POST(self): i = web.input("identifiers") identifiers = [line.strip() for line in i.identifiers.splitlines() if line.strip()] batch_name = "admin" batch = imports.Batch.find(batch_name, create=True) batch.add_items(identifiers) add_flash_message("info", "Added the specified identifiers to import queue.") raise web.seeother("/admin/imports")
def POST(self): i = web.input() page = web.ctx.get("/admin/block") or web.ctx.site.new("/admin/block", {"key": "/admin/block", "type": "/type/object"}) ips = [{'ip': d} for d in (d.strip() for d in i.ips.split('\r\n')) if d] page.ips = ips page._save("update blocked IPs") add_flash_message("info", "Saved!") raise web.seeother("/admin/block")
def POST(self, id): if not features.is_enabled("undo"): return render_template("permission_denied", web.ctx.path, "Permission denied to undo.") id = int(id) change = web.ctx.site.get_change(id) change._undo() add_flash_message("info", "Changes are successfully undone.") raise web.seeother(change.url())
def POST_closecase(self, form, case): user = accounts.get_current_user() by = user.get_email() text = "Case closed" case.add_worklog_entry(by = by, text = text) case.change_status("closed", by) add_flash_message("info", "Case closed") raise web.redirect("/admin/support")
def POST(self): i = web.input(spamwords="", domains="", action="") if i.action == "save-spamwords": spamcheck.set_spam_words(i.spamwords.strip().split("\n")) add_flash_message("info", "Updated spam words successfully.") elif i.action == "save-domains": spamcheck.set_spam_domains(i.domains.strip().split("\n")) add_flash_message("info", "Updated domains successfully.") raise web.redirect("/admin/spamwords")
def POST_update_password(self, account, i): user = account.get_user() if not forms.vpass.valid(i.password): return render_template("admin/people/view", user, i, {"password": forms.vpass.msg}) account.update_password(i.password) logger.info("updated password of %s", user.key) add_flash_message("info", "Password updated successfully!") raise web.seeother(web.ctx.path)
def POST(self): from openlibrary.plugins.upstream.utils import unflatten i = unflatten(web.input()) page = web.ctx.get("/admin/block") or web.ctx.site.new("/admin/block", {"key": "/admin/block", "type": "/type/object"}) ips = [d for d in i.ips if d.get('ip')] page.ips = ips page._save("update blocked IPs") add_flash_message("info", "Saved!") raise web.seeother("/admin/block")
def POST(self): i = web.input(perm_pages="/permission/loggedinusers", perm_records="/permission/loggedinusers") root = self.set_permission("/", i.perm_pages) works = self.set_permission("/works", i.perm_records) books = self.set_permission("/books", i.perm_records) authors = self.set_permission("/authors", i.perm_records) web.ctx.site.save_many([root, works, books, authors], comment="Updated edit policy.") add_flash_message("info", "Edit policy has been updated!") return self.GET()
def POST(self): i = web.input("identifiers") identifiers = [ line.strip() for line in i.identifiers.splitlines() if line.strip() ] batch_name = "admin" batch = imports.Batch.find(batch_name, create=True) batch.add_items(identifiers) add_flash_message("info", "Added the specified identifiers to import queue.") raise web.seeother("/admin/imports")
def POST_update_email(self, account, i): user = account.get_user() if not forms.vemail.valid(i.email): return render_template("admin/people/view", user, i, {"email": forms.vemail.msg}) if not forms.email_not_already_used.valid(i.email): return render_template("admin/people/view", user, i, {"email": forms.email_not_already_used.msg}) account.update_email(i.email) add_flash_message("info", "Email updated successfully!") raise web.seeother(web.ctx.path)
def POST(self): key = context.user.key + '/preferences' prefs = web.ctx.site.get(key) d = (prefs and prefs.dict()) or {'key': key, 'type': {'key': '/type/object'}} d['notifications'] = web.input() web.ctx.site.save(d, 'save notifications') add_flash_message('note', _("Notification preferences have been updated successfully.")) web.seeother("/account")
def POST(self): key = context.user.key + "/preferences" prefs = web.ctx.site.get(key) d = (prefs and prefs.dict()) or {"key": key, "type": {"key": "/type/object"}} d["notifications"] = web.input() web.ctx.site.save(d, "save notifications") add_flash_message("note", _("Notification preferences have been updated successfully.")) web.seeother("/account")
def POST(self): i = web.input("oldpassword", "password", "password2") f = forms.login_preferences() if not f.validates(i): return render.login_preferences(f) else: try: user = web.ctx.site.update_user(i.oldpassword, i.password, None) except ClientException, e: f.note = str(e) return render.login_preferences(f) add_flash_message('info', 'Password updated successfully.') raise web.seeother("/account/preferences")
def POST(self, key): work = web.ctx.site.get(key) if work is None: raise web.notfound() try: helper = SaveBookHelper(work, None) helper.save(web.input()) add_flash_message("info", _("Thank you very much for improving that record!")) raise web.seeother(work.url()) except (ClientException, ValidationException), e: add_flash_message('error', str(e)) return self.GET(key)
def POST_closecase(self, form, case): # Next/Prev links should be computed before the case is updated prev_url, next_url = self._get_prevnext(case.caseid) user = accounts.get_current_user() by = user.get_email() text = "Case closed" case.add_worklog_entry(by = by, text = text) case.change_status("closed", by) add_flash_message("info", "Case closed") raise web.redirect(next_url or "/admin/support")
def POST(self): import ptvsd i = web.input() # Allow other computers to attach to ptvsd at this IP address and port. logger.info("Enabling debugger attachment") ptvsd.enable_attach(address=('0.0.0.0', 3000)) logger.info("Waiting for debugger to attach...") ptvsd.wait_for_attach() logger.info("Debugger attached to port 3000") add_flash_message("info", "Debugger attached!") return self.GET()
def POST(self): user = accounts.get_current_user() key = user.key + '/preferences' prefs = web.ctx.site.get(key) d = (prefs and prefs.dict()) or {'key': key, 'type': {'key': '/type/object'}} d['notifications'] = web.input() web.ctx.site.save(d, 'save notifications') add_flash_message('note', _("Notification preferences have been updated successfully.")) web.seeother("/account")
def POST_update_email(self, user, i): @as_admin def f(): web.ctx.site.update_user_details(user.get_username(), email=i.email) if not forms.vemail.valid(i.email): return render_template("admin/people/view", user, i, {"email": forms.vemail.msg}) if not forms.email_not_already_used.valid(i.email): return render_template("admin/people/view", user, i, {"email": forms.email_not_already_used.msg}) f() add_flash_message("info", "Email updated successfully!") raise web.seeother(web.ctx.path)
def GET_memcache(self): i = web.input(action="read") i.setdefault("keys", "") mc = cache.get_memcache() keys = [k.strip() for k in i["keys"].split() if k.strip()] if i.action == "delete": mc.delete_multi(keys) add_flash_message("info", "Deleted %s keys from memcache" % len(keys)) return render_template("admin/inspect/memcache", [], {}) else: mapping = keys and mc.get_multi(keys) return render_template("admin/inspect/memcache", keys, mapping)
def POST(self, key): i = web.input(v=None, _method="GET") v = i.v and safeint(i.v, None) work = web.ctx.site.get(key, v) if work is None: raise web.notfound() try: helper = SaveBookHelper(work, None) helper.save(web.input()) add_flash_message("info", utils.get_message("flash_work_updated")) raise web.seeother(work.url()) except (ClientException, ValidationException), e: add_flash_message('error', str(e)) return self.GET(key)
def GET(self): user = accounts.get_current_user() if user: account = OpenLibraryAccount.get_by_email(user.email) ia_itemname = account.itemname if account else None if not user or not ia_itemname: web.setcookie(config.login_cookie_name, "", expires=-1) raise web.seeother("/account/login?redirect=/sponsorship/join") try: with accounts.RunAs('archive_support'): models.UserGroup.from_key('sponsors-waitlist').add_user(user.key) except KeyError as e: add_flash_message('error', 'Unable to join waitlist: %s' % e.message) raise web.seeother('/sponsorship')
def POST(self, key): # only allow admin users to edit yaml if not self.is_admin(): return render.permission_denied(key, 'Permission Denied') i = web.input(body='', _comment=None) if '_save' in i: d = self.load(i.body) p = web.ctx.site.new(key, d) try: p._save(i._comment) except (client.ClientException, ValidationException), e: add_flash_message('error', str(e)) return render.edit_yaml(key, i.body) raise web.seeother(key + '.yml')
def POST_update_password(self, user, i): @as_admin def f(): # Infobase API doesn't provide any easier way to reset password. It must be fixed. site = web.ctx.site email = user.get_email() code = site.get_reset_code(email)['code'] site.reset_password(username=user.get_username(), code=code, password=i.password) if not forms.vpass.valid(i.password): return render_template("admin/people/view", user, i, {"password": forms.vpass.msg}) f() logger.info("updated password of %s", user.key) add_flash_message("info", "Password updated successfully!") raise web.seeother(web.ctx.path)
def POST(self): i = web.input(key=[], master=None, merge_key=[]) keys = uniq(i.key) selected = set(i.merge_key) formdata = web.storage( master=i.master, selected=selected ) if not i.master or len(selected) < 2: return render_template("merge/authors", keys, top_books_from_author=top_books_from_author, formdata=formdata) else: self.do_merge('/authors/' + i.master, ['/authors/' + k for k in selected]) add_flash_message("info", 'authors merged, search should be updated within 5 minutes') raise web.seeother('/authors/' + i.master)
def POST(self): f = forms.ChangePassword() i = web.input() if not f.validates(i): return render['account/password'](f) user = accounts.get_current_user() username = user.key.split("/")[-1] if self.try_login(username, i.password): accounts.update_account(username, password=i.new_password) add_flash_message('note', _('Your password has been updated successfully.')) raise web.seeother('/account') else: f.note = "Invalid password" return render['account/password'](f)
def POST_update(self, form, case): casenote = form.get("casenote2", False) assignee = form.get("assignee", False) user = accounts.get_current_user() by = user.get_email() text = casenote or "" if case.status == "closed": case.change_status("new", by) if assignee != case.assignee: case.reassign(assignee, by, text) subject = "Case #%s has been assigned to you"%case.caseno message = render_template("admin/email_reassign", case, text) web.sendmail(config.get("support_case_control_address","*****@*****.**"), assignee, subject, message) else: case.add_worklog_entry(by = by, text = text) add_flash_message("info", "Case updated")
def POST_edit(self, path): i = web.input(_method="POST", text="") i.text = i.text.replace("\r\n", "\n").replace("\r", "\n").encode("utf-8") f = open(path, 'w') f.write(i.text) f.close() logger.info("Saved %s", path) # run make after editing js or css files if not path.endswith(".html"): logger.info("Running make") cmd = Git().system("make") logger.info(cmd.stdout) add_flash_message("info", "Page has been saved successfully.") raise web.seeother(web.ctx.path)
def GET(self, path): i = web.input(v=None, t=None) if not web.ctx.site.can_write(path): return render.permission_denied(web.ctx.fullpath, "Permission denied to edit " + path + ".") if i.v is not None and safeint(i.v, None) is None: raise web.seeother(web.changequery(v=None)) p = db.get_version(path, i.v) or db.new_version(path, types.guess_type(path)) if i.t: type = db.get_type(i.t) if type is None: add_flash_message('error', 'Unknown type: ' + i.t) else: p.type = type return render.editpage(p)
def POST(self, path): i = web.input(_method='post') i = web.storage(helpers.unflatten(i)) i.key = path _ = web.storage((k, i.pop(k)) for k in i.keys() if k.startswith('_')) action = self.get_action(_) comment = _.get('_comment', None) for k, v in i.items(): i[k] = self.trim(v) p = web.ctx.site.get(path) or web.ctx.site.new(path, {}) p.update(i) if action == 'preview': p['comment_'] = comment return render.editpage(p, preview=True) elif action == 'save': try: p._save(comment) path = web.input( _method='GET', redirect=None).redirect or web.changequery(query={}) raise web.seeother(path) except (ClientException, db.ValidationException) as e: add_flash_message('error', str(e)) p['comment_'] = comment return render.editpage(p) elif action == 'delete': q = dict(key=i['key'], type=dict(key='/type/delete')) try: web.ctx.site.save(q, comment) except (ClientException, db.ValidationException) as e: add_flash_message('error', str(e)) p['comment_'] = comment return render.editpage(p) raise web.seeother(web.changequery(query={}))
def POST(self, key): i = web.input(v=None, _method="GET") v = i.v and safeint(i.v, None) edition = web.ctx.site.get(key, v) if edition is None: raise web.notfound() if edition.works: work = edition.works[0] else: work = None add = (edition.revision == 1 and work and work.revision == 1 and work.edition_count == 1) try: helper = SaveBookHelper(work, edition) helper.save(web.input()) if add: add_flash_message("info", utils.get_message("flash_book_added")) else: add_flash_message("info", utils.get_message("flash_book_updated")) raise web.seeother(edition.url()) except (ClientException, ValidationException), e: raise add_flash_message('error', str(e)) return self.GET(key)
def POST(self, key): i = web.input(_method="POST") if "_delete" in i: doc = web.ctx.site.store.get(key) if doc: doc['current_status'] = "deleted" web.ctx.site.store[doc['_key']] = doc add_flash_message("info", "The requested library has been deleted.") raise web.seeother("/libraries/dashboard") i._key = web.rstrips(i.key, "/").replace(" ", "_") page = libraries_dashboard()._create_pending_library(i) if web.ctx.site.get(page.key): add_flash_message("error", "URL %s is already used. Please choose a different one." % page.key) return render_template("type/library/edit", page) elif not i.key.startswith("/libraries/"): add_flash_message("error", "The key must start with /libraries/.") return render_template("type/library/edit", page) doc = web.ctx.site.store.get(key) if doc and "registered_on" in doc: page.registered_on = {"type": "/type/datetime", "value": doc['registered_on']} page._save() if doc: doc['current_status'] = "approved" doc['page_key'] = page.key web.ctx.site.store[doc['_key']] = doc raise web.seeother(page.key)
def POST(self, key): i = web.input(v=None, _method="GET") if spamcheck.is_spam(): return render_template( "message.html", "Oops", 'Something went wrong. Please try again later.' ) recap = get_recaptcha() if recap and not recap.validate(): return render_template( "message.html", 'Recaptcha solution was incorrect', 'Please <a href="javascript:history.back()">go back</a> and try again.', ) v = i.v and safeint(i.v, None) edition = web.ctx.site.get(key, v) if edition is None: raise web.notfound() if edition.works: work = edition.works[0] else: work = None add = ( edition.revision == 1 and work and work.revision == 1 and work.edition_count == 1 ) try: helper = SaveBookHelper(work, edition) helper.save(web.input()) if add: add_flash_message("info", utils.get_message("flash_book_added")) else: add_flash_message("info", utils.get_message("flash_book_updated")) raise safe_seeother(edition.url()) except ClientException as e: add_flash_message('error', e.args[-1] or e.json) return self.GET(key) except ValidationException as e: add_flash_message('error', str(e)) return self.GET(key)
def POST(self, key): author = web.ctx.site.get(key) if author is None: raise web.notfound() i = web.input(_comment=None) formdata = self.process_input(i) try: if not formdata: raise web.badrequest() elif "_save" in i: author.update(formdata) author._save(comment=i._comment) raise web.seeother(key) elif "_delete" in i: author = web.ctx.site.new(key, {"key": key, "type": {"key": "/type/delete"}}) author._save(comment=i._comment) raise web.seeother(key) except (ClientException, ValidationException) as e: add_flash_message('error', str(e)) author.update(formdata) author['comment_'] = i._comment return render_template("type/author/edit", author)
def POST(self, edition): saveutil = DocSaveHelper() i = web.input(isbn = "") isbn = i.get("isbn") # Need to do some simple validation here. Perhaps just check if it's a number? if len(isbn) == 10: typ = "ISBN 10" data = [{'name': u'isbn_10', 'value': isbn}] elif len(isbn) == 13: typ = "ISBN 13" data = [{'name': u'isbn_13', 'value': isbn}] else: add_flash_message("error", "The ISBN number you entered was not valid") raise web.redirect(web.ctx.path) if edition.works: work = edition.works[0] else: work = None edition.set_identifiers(data) saveutil.save(edition) saveutil.commit(comment="Added an %s identifier."%typ, action="edit-book") add_flash_message("info", "Thank you very much for improving that record!") raise web.redirect(web.ctx.path)
def POST(self, taskid): try: db = connect_to_taskdb() try: task = db[taskid] except couchdb.http.ResourceNotFound: return "No such task" except Exception: logger.warning("Problem while obtaining task information '%s'", taskid, exc_info=True) return "Error in obtaining task information" function = getattr(openlibrary.tasks, task['command']) largs = json.loads(task['largs']) kargs = json.loads(task['kargs']) kargs["celery_parent_task"] = taskid add_flash_message("info", "%s (%s) refired!" % (taskid, task['command'])) function.delay(*largs, **kargs) return render_template("admin/tasks/task", process_task_row(task))
def POST(self, key): i = web.input(v=None, _method="GET") if spamcheck.is_spam(): return render_template( "message.html", "Oops", 'Something went wrong. Please try again later.') recap_plugin_active = is_plugin_enabled('recaptcha') #check to see if account is more than two years old old_user = False user = web.ctx.site.get_user() account = user and user.get_account() if account: create_dt = account.creation_time() now_dt = datetime.datetime.utcnow() delta = now_dt - create_dt if delta.days > 365 * 2: old_user = True if recap_plugin_active and not old_user: public_key = config.plugin_recaptcha.public_key private_key = config.plugin_recaptcha.private_key recap = recaptcha.Recaptcha(public_key, private_key) if not recap.validate(): return 'Recaptcha solution was incorrect. Please <a href="javascript:history.back()">go back</a> and try again.' v = i.v and safeint(i.v, None) edition = web.ctx.site.get(key, v) if edition is None: raise web.notfound() if edition.works: work = edition.works[0] else: work = None add = (edition.revision == 1 and work and work.revision == 1 and work.edition_count == 1) try: helper = SaveBookHelper(work, edition) helper.save(web.input()) if add: add_flash_message("info", utils.get_message("flash_book_added")) else: add_flash_message("info", utils.get_message("flash_book_updated")) raise web.seeother(edition.url()) except (ClientException, ValidationException), e: add_flash_message('error', str(e)) return self.GET(key)
def POST(self): i = web.input(keys="") keys = i['keys'].strip().split() web.ctx.site.store['solr-force-update'] = dict(type="solr-force-update", keys=keys, _rev=None) add_flash_message("info", "Added the specified keys to solr update queue.!") return self.GET()
class edit (delegate.mode): def GET(self, path): i = web.input(v=None, t=None) if not web.ctx.site.can_write(path): return render.permission_denied(web.ctx.fullpath, "Permission denied to edit " + path + ".") if i.v is not None and safeint(i.v, None) is None: raise web.seeother(web.changequery(v=None)) p = db.get_version(path, i.v) or db.new_version(path, types.guess_type(path)) if i.t: type = db.get_type(i.t) if type is None: add_flash_message('error', 'Unknown type: ' + i.t) else: p.type = type return render.editpage(p) def trim(self, d): """Trims empty value from d. >>> trim = edit().trim >>> trim("hello ") 'hello' >>> trim(['hello ', '', ' foo']) ['hello', 'foo'] >>> trim({'x': '', 'y': 'foo'}) {'y': 'foo'} >>> trim({'x': '', 'unique': 'foo'}) >>> trim([{'x': '', 'y': 'foo'}, {'x': ''}]) [{'y': 'foo'}] """ if d is None: return d elif isinstance(d, list): d = [self.trim(x) for x in d] d = [x for x in d if x] return d elif isinstance(d, dict): for k, v in d.items(): d[k] = self.trim(v) if d[k] is None or d[k] == '' or d[k] == []: del d[k] # hack to stop saving empty properties if d.keys() == [] or d.keys() == ['unique']: return None else: return d else: return d.strip() def POST(self, path): i = web.input(_method='post') i = web.storage(helpers.unflatten(i)) i.key = path _ = web.storage((k, i.pop(k)) for k in i.keys() if k.startswith('_')) action = self.get_action(_) comment = _.get('_comment', None) for k, v in i.items(): i[k] = self.trim(v) p = web.ctx.site.get(path) or web.ctx.site.new(path, {}) p.update(i) if action == 'preview': p['comment_'] = comment return render.editpage(p, preview=True) elif action == 'save': try: p._save(comment) path = web.input(_method='GET', redirect=None).redirect or web.changequery(query={}) raise web.seeother(path) except (ClientException, db.ValidationException), e: add_flash_message('error', str(e)) p['comment_'] = comment return render.editpage(p) elif action == 'delete': q = dict(key=i['key'], type=dict(key='/type/delete')) try: web.ctx.site.save(q, comment) except (ClientException, db.ValidationException), e: add_flash_message('error', str(e)) p['comment_'] = comment return render.editpage(p)
if not self.is_admin(): return render.permission_denied(key, 'Permission Denied') i = web.input(body='', _comment=None) if '_save' in i: d = self.load(i.body) p = web.ctx.site.new(key, d) try: p._save(i._comment) except (client.ClientException, ValidationException), e: add_flash_message('error', str(e)) return render.edit_yaml(key, i.body) raise web.seeother(key + '.yml') elif '_preview' in i: add_flash_message('Preview not supported') return render.edit_yaml(key, i.body) else: add_flash_message('unknown action') return render.edit_yaml(key, i.body) def _get_user_root(): user_root = infogami.config.get("infobase", {}).get("user_root", "/user") return web.rstrips(user_root, "/") def _get_bots(): bots = web.ctx.site.store.values(type="account", name="bot", value="true") user_root = _get_user_root() return [user_root + "/" + account['username'] for account in bots]
def POST(self): user = accounts.get_current_user() user.save_preferences(web.input()) add_flash_message('note', _("Notification preferences have been updated successfully.")) web.seeother("/account")
i = web.input(username='', code='') try: web.ctx.site.check_reset_code(i.username, i.code) except ClientException, e: title = _("Password reset failed.") message = web.safestr(e) return render.message(title, message) f = forms.ResetPassword() if not f.validates(i): return render['account/password/reset'](f) web.ctx.site.update_account(i.username, password=i.password) add_flash_message('info', _("Your password has been updated successfully.")) raise web.seeother('/account/login') class account_notifications(delegate.page): path = "/account/notifications" @require_login def GET(self): prefs = web.ctx.site.get(context.user.key + "/preferences") d = (prefs and prefs.get('notifications')) or {} email = context.user.email return render['account/notifications'](d, email) @require_login def POST(self):
assignee = case.assignee casenote = form.get("casenote1", "") casenote = "%s replied:\n\n%s" % (user.get_name(), casenote) case.add_worklog_entry(by=user.get_email(), text=casenote) case.change_status("replied", user.get_email()) email_to = form.get("email", False) subject = "Case #%s: %s" % (case.caseno, case.subject) if assignee != user.get_email(): case.reassign(user.get_email(), user.get_name(), "") if email_to: message = render_template("admin/email", case, casenote) web.sendmail( config.get("support_case_control_address", "*****@*****.**"), email_to, subject, message) add_flash_message("info", "Reply sent") raise web.redirect(next_url or "/admin/support") def POST_update(self, form, case): casenote = form.get("casenote2", False) assignee = form.get("assignee", False) user = accounts.get_current_user() by = user.get_email() text = casenote or "" if case.status == "closed": case.change_status("new", by) if assignee != case.assignee: case.reassign(assignee, by, text) subject = "Case #%s has been assigned to you" % case.caseno message = render_template("admin/email_reassign", case, text)
def POST(self): i = web.input() ips = [ip.strip() for ip in i.ips.splitlines()] self.block_ips(ips) add_flash_message("info", "Saved!") raise web.seeother("/admin/block")