Best Python code snippet using autotest_python
views.py
Source:views.py
1from Products.Five.browser import BrowserView2from collections import defaultdict3from eea.climateadapt._importer.utils import get_template_for_layout4from eea.climateadapt._importer.utils import create_folder_at5from eea.climateadapt._importer.utils import parse_settings6from eea.climateadapt._importer.utils import strip_xml7from eea.climateadapt._importer import import_aceitems as base_import_aceitems8from sqlalchemy import create_engine9from sqlalchemy.orm import scoped_session, sessionmaker10from zope.component.hooks import getSite11from zope.sqlalchemy import register12import eea.climateadapt._importer13import os14class SingleImporterView(BrowserView):15 """ Registered as /@@layout_importer16 Call with one of17 * ?uuid=<uuid>18 * layout=<layoutid>19 * type=casestudy[&id=<measureid>]20 * type=aceitems21 """22 def _make_session(self):23 engine = create_engine(os.environ.get("DB"))24 Session = scoped_session(sessionmaker(bind=engine))25 register(Session, keep_session=True)26 session = Session()27 return session28 def import_layout(self):29 from eea.climateadapt._importer import import_layout30 from eea.climateadapt._importer import sql31 session = self._make_session()32 eea.climateadapt._importer.session = session33 site = self.context34 uuid = self.request.form.get('uuid')35 if uuid:36 layout = session.query(sql.Layout).filter_by(privatelayout=False,37 uuid_=uuid).one()38 else:39 id = self.request.form.get('layout')40 layout = session.query(sql.Layout).filter_by(privatelayout=False,41 layoutid=id).one()42 cover = import_layout(layout, site)43 if cover:44 return self.request.response.redirect(cover.absolute_url())45 return "no cover?"46 def import_layout_type(self):47 """ Allows importing a batch of layouts by their template name48 """49 from eea.climateadapt._importer import import_layout50 from eea.climateadapt._importer import sql51 session = self._make_session()52 eea.climateadapt._importer.session = session53 site = self.context54 template = self.request.form.get('template', '').strip()55 if not template:56 raise ValueError("Please provide a template")57 for layout in session.query(sql.Layout).filter_by(privatelayout=False):58 if layout.type_ in [u'control-panel']:59 # we skip control panel pages60 continue61 settings = parse_settings(layout.typesettings)62 if layout.type_ == u'link_to_layout':63 llid = int(settings['linkToLayoutId'][0])64 try:65 ll = session.query(sql.Layout).filter_by(layoutid=llid).one()66 except:67 print "Got error on layout", layout.friendlyurl68 continue69 import pdb; pdb.set_trace()70 this_url = layout.friendlyurl71 child_url = ll.friendlyurl72 folder = create_folder_at(site, this_url)73 folder.setLayout(child_url.split('/')[-1])74 folder.title = strip_xml(ll.name)75 continue76 try:77 layout_template = settings['layout-template-id'][0]78 except:79 import pdb; pdb.set_trace()80 if not layout_template == template:81 continue82 try:83 cover = import_layout(layout, site)84 except:85 print "Couldn't import layout %s", layout.friendlyurl86 if cover:87 cover._imported_comment = \88 "Imported from layout {0}".format(layout.layoutid)89 print "Created cover at %s" % cover.absolute_url()90 def import_dlentries(self):91 from eea.climateadapt._importer import import_dlfileentry92 from eea.climateadapt._importer import sql93 session = self._make_session()94 eea.climateadapt._importer.session = session95 site = self.context96 imported = []97 #import pdb; pdb.set_trace()98 to_import = session.query(sql.Dlfileentry)99 id = self.request.form.get('id')100 if id:101 to_import = to_import.filter_by(fileentryid=int(id))102 for dlfileentry in to_import:103 f = import_dlfileentry(dlfileentry, site['repository'])104 if f is None:105 continue106 link = "<a href='{0}'>{1}</a>".format(f.absolute_url(), f.getId())107 imported.append(link)108 return "<br/>".join(imported)109 def import_aceitems(self):110 from eea.climateadapt._importer import import_aceitem111 from eea.climateadapt._importer import sql112 from eea.climateadapt._importer.tweak_sql import fix_relations113 session = self._make_session()114 eea.climateadapt._importer.session = session115 fix_relations(session)116 site = self.context117 id = self.request.form.get('id')118 if id:119 aceitem = session.query(sql.AceAceitem).\120 filter_by(aceitemid=int(id)).one()121 obj = import_aceitem(aceitem, site)122 return self.request.response.redirect(obj.absolute_url())123 base_import_aceitems(session, site)124 return 'done'125 def import_casestudy(self):126 from eea.climateadapt._importer import import_casestudy127 from eea.climateadapt._importer import import_adaptationoption128 from eea.climateadapt._importer import sql129 session = self._make_session()130 eea.climateadapt._importer.session = session131 site = self.context132 if 'casestudy' not in site.contentIds():133 site.invokeFactory("Folder", 'casestudy')134 site['casestudy'].edit(title='Case Studies')135 to_import = session.query(sql.AceMeasure)136 id = self.request.form.get('id')137 if id:138 to_import = to_import.filter_by(measureid=int(id))139 # TODO: fix this code140 imported = []141 for acemeasure in to_import:142 if acemeasure.mao_type == 'A':143 obj = import_casestudy(acemeasure, site['casestudy'])144 imported.append(obj)145 print "Imported Case Study {0} from id {1}".format(146 obj.absolute_url(), acemeasure.measureid)147 else:148 obj = import_adaptationoption(acemeasure,149 site['metadata']['adaptation-options'])150 imported.append(obj)151 print "Imported Adaptation Option {0} from id {1}".format(152 obj.absolute_url(), acemeasure.measureid)153 if imported:154 return self.request.response.redirect(imported[0].absolute_url())155 else:156 return "Nothing to import"157 def import_fix_casestudies(self):158 from eea.climateadapt._importer import fix_casestudy_images159 fix_casestudy_images(self.context)160 def import_projects(self):161 from eea.climateadapt._importer import import_aceproject162 from eea.climateadapt._importer import sql163 session = self._make_session()164 eea.climateadapt._importer.session = session165 site = self.context166 if 'aceprojects' not in site.contentIds():167 site.invokeFactory("Folder", 'aceprojects')168 site['aceprojects'].edit(title='Projects')169 to_import = session.query(sql.AceProject)170 id = self.request.form.get('id')171 if id:172 to_import = to_import.filter_by(projectid=int(id))173 imported = []174 for project in to_import:175 obj = import_aceproject(project, site['aceprojects'])176 imported.append(obj)177 print "Imported Project {0} from id {1}".format(178 obj.absolute_url(), project.projectid)179 if imported:180 return self.request.response.redirect(imported[0].absolute_url())181 else:182 return "Nothing to import"183 def import_journal_articles(self):184 from eea.climateadapt._importer import import_journal_articles185 session = self._make_session()186 eea.climateadapt._importer.session = session187 site = self.context188 import_journal_articles(site)189 return "Done"190 def import_city_profile(self):191 from eea.climateadapt._importer import import_city_profiles192 session = self._make_session()193 eea.climateadapt._importer.session = session194 site = self.context195 cities = import_city_profiles(site)196 return "Imported {0} cities".format(len(cities))197 def import_detect_richtext(self):198 from eea.climateadapt._importer.utils import detect_richtext_fields199 session = self._make_session()200 eea.climateadapt._importer.session = session201 #site = self.context202 detect_richtext_fields(session)203 return "done"204 def import_portlet_preferences(self):205 from eea.climateadapt._importer import sql206 import lxml.etree207 import lxml.html208 session = self._make_session()209 eea.climateadapt._importer.session = session210 saportlets = session.query(sql.Portletpreference)211 for portlet in saportlets:212 if portlet.preferences is not None:213 e = lxml.etree.fromstring(portlet.preferences)214 prefs = {}215 for pref in e.xpath('//preference'):216 name = str(pref.find('name').text)217 values = pref.findall('value')218 if len(values) > 1:219 print len(values), name, portlet.portletid220 res = []221 for node in values:222 try:223 value = node.text224 except Exception:225 continue226 if value is not None:227 res.append(unicode(value))228 if len(res) == 0:229 prefs[name] = None230 elif len(res) == 1:231 prefs[name] = res[0]232 else:233 prefs[name] = res234 def __call__(self):235 _type = self.request.form.get('type', 'layout')236 debug = self.request.form.get('debug')237 if debug:238 import pdb; pdb.set_trace()239 importer = getattr(self, 'import_' + _type)240 return importer() or "done"241class GoToPDB(BrowserView):242 def __call__(self):243 import pdb; pdb.set_trace()244 return "done"245class MapOfLayouts(SingleImporterView):246 def __call__(self):247 from eea.climateadapt._importer import sql248 session = self._make_session()249 eea.climateadapt._importer.session = session250 self.options = defaultdict(list)251 for layout in session.query(sql.Layout).filter_by(privatelayout=False):252 template = get_template_for_layout(layout)253 self.options[template].append((layout.friendlyurl, layout.uuid_))254 return self.index()255 def site_url(self):256 return getSite().absolute_url()257class FacetedImporter(BrowserView):258 def __call__(self):259 from eea.climateadapt._importer.utils import make_faceted260 if 'submit' in self.request.form:261 site = self.context262 form = self.request.form263 location = form['location']264 xmlfilename = form['xmlfilename']265 layout = form['layout']266 faceted = make_faceted(site, location, xmlfilename, layout)267 return self.request.response.redirect(faceted.absolute_url())268 else:...
qt_abstraction.py
Source:qt_abstraction.py
1# Copyright (c) 2015 Shotgun Software Inc.2#3# CONFIDENTIAL AND PROPRIETARY4#5# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit6# Source Code License included in this distribution package. See LICENSE.7# By accessing, using, copying or modifying this work you indicate your8# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights9# not expressly granted therein are reserved by Shotgun Software Inc.10"""11Imports Qt without having to worry which version of Qt we are using.12"""13from ...util.qt_importer import QtImporter14_importer = QtImporter()15QtCore = _importer.QtCore16QtGui = _importer.QtGui17QtWebKit = _importer.QtWebKit18QtNetwork = _importer.QtNetwork19qt_version_tuple = _importer.qt_version_tuple...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!