def detail(self, orgid): "Organization details" org = get_org(orgid) if not org: abort(404) c.org = org return self.render('/organizations/detail.html')
def edit(self, orgid): "Edit an organization" org = get_org(orgid) if not org: abort(404) c.id = org.id c.form = org_add_form(request.POST, session, org) if request.method == 'POST' and c.form.validate(): if update_if_changed(c.form, org): try: edit_org(org, c.user, request.host, request.remote_addr) msg = _('The organization has been updated') flash(msg) log.info(msg) except IntegrityError: Session.rollback() msg = _('The organization could not be updated') flash(msg) log.info(msg) else: msg = _('No changes made, Organization not updated') flash_info(msg) log.info(msg) redirect(url(controller='organizations')) return self.render('/organizations/edit.html')
def import_domains(self, orgid): "import domains from csv file" org = get_org(orgid) if not org: abort(404) c.form = ImportCSVForm(request.POST, csrf_context=session) if request.method == 'POST' and c.form.validate(): basedir = config['pylons.cache_dir'] csvdata = request.POST['csvfile'] if hasattr(csvdata, 'filename'): dstfile = os.path.join(basedir, 'uploads', csvdata.filename.lstrip(os.sep)) if not os.path.exists(dstfile) and iscsv(csvdata.file): csvfile = open(dstfile, 'w') shutil.copyfileobj(csvdata.file, csvfile) csvdata.file.close() csvfile.close() task = importdomains.apply_async(args=[orgid, dstfile, c.form.skipfirst.data]) if 'taskids' not in session: session['taskids'] = [] session['taskids'].append(task.task_id) session['dimport-counter'] = 1 session['dimport-file'] = dstfile session.save() msg = _('File uploaded, and is being processed, this page' ' will automatically refresh to show the status') flash(msg) log.info(msg) redirect(url('orgs-import-status', taskid=task.task_id)) else: filename = csvdata.filename.lstrip(os.sep) if not iscsv(csvdata.file): msg = _('The file: %s is not a CSV file') % filename flash_alert(msg) log.info(msg) else: msg = _('The file: %s already exists ' 'and is being processed.') % filename flash_alert(msg) log.info(msg) csvdata.file.close() else: msg = _('No CSV was file uploaded, try again') flash_alert(msg) log.info(msg) c.org = org return self.render('/organizations/importdomains.html')
def import_domains(self, orgid): "import domains from csv file" org = get_org(orgid) if not org: abort(404) c.form = ImportCSVForm(request.POST, csrf_context=session) if request.method == 'POST' and c.form.validate(): basedir = config['pylons.cache_dir'] csvdata = request.POST['csvfile'] if hasattr(csvdata, 'filename'): dstfile = os.path.join(basedir, 'uploads', csvdata.filename.lstrip(os.sep)) if not os.path.exists(dstfile) and iscsv(csvdata.file): csvfile = open(dstfile, 'w') shutil.copyfileobj(csvdata.file, csvfile) csvdata.file.close() csvfile.close() task = importdomains.apply_async( args=[orgid, dstfile, c.form.skipfirst.data]) if 'taskids' not in session: session['taskids'] = [] session['taskids'].append(task.task_id) session['dimport-counter'] = 1 session['dimport-file'] = dstfile session.save() msg = _('File uploaded, and is being processed, this page' ' will automatically refresh to show the status') flash(msg) log.info(msg) redirect(url('orgs-import-status', taskid=task.task_id)) else: filename = csvdata.filename.lstrip(os.sep) if not iscsv(csvdata.file): msg = _('The file: %s is not a CSV file') % filename flash_alert(msg) log.info(msg) else: msg = _('The file: %s already exists ' 'and is being processed.') % filename flash_alert(msg) log.info(msg) csvdata.file.close() else: msg = _('No CSV was file uploaded, try again') flash_alert(msg) log.info(msg) c.org = org return self.render('/organizations/importdomains.html')
def delete(self, orgid): "Delete an organization" org = get_org(orgid) if not org: abort(404) c.id = org.id c.form = org_delete_form(request.POST, session, org) if request.method == 'POST' and c.form.validate(): delete_org(c.form, org, c.user, request.host, request.remote_addr) msg = _('The organization has been deleted') flash(msg) log.info(msg) redirect(url(controller='organizations')) else: msg = _('The organization: %(s)s will be deleted,' ' This action is not reversible') % dict(s=org.name) flash(msg) log.info(msg) return self.render('/organizations/delete.html')
def add_relay(self, orgid): "Add a mail relay" org = get_org(orgid) if not org: abort(404) c.form = RelayForm(request.POST, csrf_context=session) if request.method == 'POST' and c.form.validate(): try: relay = add_relay(c.form, org, c.user, request.host, request.remote_addr) name = relay.address or relay.username msg = _('The outbound settings: %s have been created') % name flash(msg) log.info(msg) except IntegrityError: Session.rollback() msg = _('The outbound settings could not created, Try again') flash(msg) log.info(msg) redirect(url('org-detail', orgid=orgid)) c.orgid = org.id c.orgname = org.name return self.render('/organizations/addrelay.html')