How to use set_namespace method in fMBT

Best Python code snippet using fMBT_python

config.py

Source:config.py Github

copy

Full Screen

...142 u.pleb.extend(new_email)143 return u144class CreateStaffFile(Handler):145 def get(self):146 namespace_manager.set_namespace('')147 if users.is_current_user_admin():148 self.render('admin/setup.html', form=AdminStandardCreate())149 def post(self):150 if not users.is_current_user_admin():151 self.redirect('/ouch')152 else:153 namespace_manager.set_namespace('')154 form = AdminStandardCreate(self.request.POST)155 namespace_manager.set_namespace(form.school.data[-4:])156 if form.validate():157 school = form.school.data[-4:]158 year = form.year.data159 staff = p.open_file(school,year,form.filename.data)160 q = m.MetaSchool.get_key(school)161 create_staff(staff,year,q)162 self.render('admin/ouch.html')163 else:164 self.render('admin/setup.html', form=form)165class CreateStaffGCS(Handler):166 def get(self):167 namespace_manager.set_namespace('')168 if users.is_current_user_admin():169 self.render('admin/setup.html', form=AdminStandardCreate())170 def post(self):171 if not users.is_current_user_admin():172 self.redirect('/ouch')173 else:174 namespace_manager.set_namespace('')175 form = AdminStandardCreate(self.request.POST)176 namespace_manager.set_namespace(form.school.data[-4:])177 if form.validate():178 school = form.school.data[-4:]179 year = form.year.data180 staff = p.open_file_gcs(open_cloudstorage_file(form.filename.data))181 q = m.MetaSchool.get_key(school)182 create_staff(staff,year,q)183 self.render('admin/ouch.html')184 else:185 self.render('admin/setup.html', form=form)186class StaffToUsers(Handler):187 def get(self):188 namespace_manager.set_namespace('')189 if users.is_current_user_admin():190 self.render('admin/stafftousers.html', form=StaffToUsersForm())191 def post(self):192 if not users.is_current_user_admin():193 self.redirect('/ouch')194 else:195 namespace_manager.set_namespace('')196 form = StaffToUsersForm(self.request.POST)197 namespace_manager.set_namespace(form.school.data[-4:])198 if form.validate():199 school = form.school.data[-4:]200 year = form.year.data201 q = m.MetaSchool.get_key(school)202 u = all_staff_users(self.check_u(),year,q)203 u.put()204 self.redirect('/schooladmin/user')205 else:206 self.render('admin/stafftousers.html', form=form)207class StaffGCS(Handler):208 """CHECK209 Seems to be some old code from standards may need to write up the staff code210 FROM First Round211 """212 def get(self):213 namespace_manager.set_namespace('')214 if users.is_current_user_admin():215 self.render('admin/setup.html', form=AdminStandardCreate())216 def post(self):217 if not users.is_current_user_admin():218 self.redirect('/ouch')219 else:220 namespace_manager.set_namespace('')221 form = AdminStandardCreate(self.request.POST)222 namespace_manager.set_namespace(form.school.data[-4:])223 if form.validate():224 school = form.school.data[-4:]225 year = form.year.data226 standardsfile = p.open_file_gcs(open_cloudstorage_file(form.filename.data))227 standards = create_standards_model(standardsfile)228 q = m.MetaSchool.get_key(school)229 standards = update_standards_model(standards,q,year) 230 self.render('admin/ouch.html')231 else:232 self.render('admin/setup.html', form=form)233class StandardsGCS(Handler):234 def get(self):235 namespace_manager.set_namespace('')236 if users.is_current_user_admin():237 self.render('admin/setup.html', form=AdminStandardCreate())238 def post(self):239 if not users.is_current_user_admin():240 self.redirect('/ouch')241 else:242 namespace_manager.set_namespace('')243 form = AdminStandardCreate(self.request.POST)244 namespace_manager.set_namespace(form.school.data[-4:])245 if form.validate():246 school = form.school.data[-4:]247 year = form.year.data248 standardsfile = p.open_file_gcs(open_cloudstorage_file(form.filename.data))249 standards = create_standards_model(standardsfile)250 q = m.MetaSchool.get_key(school)251 standards = update_standards_model(standards,q,year) 252 self.render('admin/ouch.html')253 else:254 self.render('admin/setup.html', form=form)255class StandardsFile(Handler):256 def get(self):257 namespace_manager.set_namespace('')258 if users.is_current_user_admin():259 self.render('admin/setup.html', form=AdminStandardCreate())260 def post(self):261 if not users.is_current_user_admin():262 self.redirect('/ouch')263 else:264 namespace_manager.set_namespace('')265 form = AdminStandardCreate(self.request.POST)266 namespace_manager.set_namespace(form.school.data[-4:])267 if form.validate():268 school = form.school.data[-4:]269 year = form.year.data270 standardsfile = p.open_file(school,year,form.filename.data)271 standards = create_standards_model(standardsfile)272 q = m.MetaSchool.get_key(school)273 standards = update_standards_model(standards,q,year) 274 self.render('admin/ouch.html')275 else:276 self.render('admin/setup.html', form=form)277 278 279class StandardsOld(Handler):280 def get(self):281 namespace_manager.set_namespace('')282 if users.is_current_user_admin():283 self.render('admin/setup.html', form=AdminStandardCreate())284 def post(self):285 """286 Need to sort out students not needed287 """288 if not users.is_current_user_admin():289 self.redirect('/ouch')290 else:291 namespace_manager.set_namespace('')292 form = AdminStandardCreate(self.request.POST)293 namespace_manager.set_namespace(form.school.data[-4:])294 if form.validate():295 school = form.school.data[-4:]296 year = form.year.data297 standardsfile = p.open_file(open_cloudstorage_file(form.filename.data))298 standards = create_standards_model(standardsfile)299 q = m.MetaSchool.get_key(school)300 301 for child in standards:302 standard = m.Standard(parent=q,303 year=year,304 standard_type = child[0],305 subject_id = child[1],306 subject_title=child[2],307 standard_no = child[3],...

Full Screen

Full Screen

db.py

Source:db.py Github

copy

Full Screen

...14 def new(cls):15 user = users.get_current_user()16 previous_namespace = namespace_manager.get_namespace()17 try:18 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))19 word = Word()20 finally:21 namespace_manager.set_namespace(previous_namespace)22 word.name = ''23 word.content = ''24 return word25 @classmethod26 def get_all_with_namespace(cls):27 user = users.get_current_user()28 previous_namespace = namespace_manager.get_namespace()29 try:30 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))31 qry = Word.query().order(Word.name)32 words = qry.fetch()33 finally:34 namespace_manager.set_namespace(previous_namespace)35 return words36 @classmethod37 def get_with_namespace(cls, id):38 user = users.get_current_user()39 previous_namespace = namespace_manager.get_namespace()40 try:41 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))42 word = Word.get_by_id(id)43 finally:44 namespace_manager.set_namespace(previous_namespace)45 return word46 @classmethod47 def get_by_name_or_new_with_namespace(cls, name):48 user = users.get_current_user()49 previous_namespace = namespace_manager.get_namespace()50 try:51 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))52 qry = Word.query(Word.name == name)53 word = qry.get()54 if word is None:55 word = Word()56 word.name = name57 word.content = ''58 finally:59 namespace_manager.set_namespace(previous_namespace)60 return word61 @classmethod62 def put_with_namespace(cls, word):63 user = users.get_current_user()64 previous_namespace = namespace_manager.get_namespace()65 try:66 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))67 word.put()68 finally:69 namespace_manager.set_namespace(previous_namespace)70 @classmethod71 def put_multi_with_namespace(cls, words):72 user = users.get_current_user()73 previous_namespace = namespace_manager.get_namespace()74 try:75 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))76 ndb.put_multi(words)77 finally:78 namespace_manager.set_namespace(previous_namespace)79 @classmethod80 def get_all_words(cls):81 user = users.get_current_user()82 previous_namespace = namespace_manager.get_namespace()83 try:84 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))85 qry = Word.query()86 words = qry.fetch()87 finally:88 namespace_manager.set_namespace(previous_namespace)89 return words90 @classmethod91 def get_all_known_words(cls):92 user = users.get_current_user()93 previous_namespace = namespace_manager.get_namespace()94 try:95 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))96 qry = Word.query(Word.known == True)97 words = {}98 for word in qry.fetch():99 words[word.name] = word.name100 if word.conjugative is not None:101 for conj in word.conjugative:102 words[conj] = word.name103 finally:104 namespace_manager.set_namespace(previous_namespace)105 return words106 @classmethod107 def get_all_unknown_words(cls):108 user = users.get_current_user()109 previous_namespace = namespace_manager.get_namespace()110 try:111 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))112 qry = Word.query(Word.known == False)113 words = {}114 for word in qry.fetch():115 words[word.name] = word.name116 if word.conjugative is not None:117 for conj in word.conjugative:118 words[conj] = word.name119 finally:120 namespace_manager.set_namespace(previous_namespace)121 return words122class Document(ndb.Model):123 """A main model for representing an individual Note entry."""124 title = ndb.StringProperty(indexed=False)125 content = ndb.TextProperty(indexed=False)126 date = ndb.DateTimeProperty(auto_now_add=True)127 @classmethod128 def new(cls):129 user = users.get_current_user()130 previous_namespace = namespace_manager.get_namespace()131 try:132 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))133 document = Document()134 finally:135 namespace_manager.set_namespace(previous_namespace)136 document.title = ''137 document.content = ''138 return document139 @classmethod140 def get_all_with_namespace(cls):141 user = users.get_current_user()142 previous_namespace = namespace_manager.get_namespace()143 try:144 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))145 documents_query = Document.query().order(-Document.date)146 documents = documents_query.fetch()147 finally:148 namespace_manager.set_namespace(previous_namespace)149 return documents150 @classmethod151 def get_with_namespace(cls, id):152 user = users.get_current_user()153 previous_namespace = namespace_manager.get_namespace()154 try:155 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))156 document = Document.get_by_id(id)157 finally:158 namespace_manager.set_namespace(previous_namespace)159 return document160 @classmethod161 def put_with_namespace(cls, document):162 user = users.get_current_user()163 previous_namespace = namespace_manager.get_namespace()164 try:165 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))166 document.put()167 finally:168 namespace_manager.set_namespace(previous_namespace)169class Collocation(ndb.Model):170 """A model for representing a collocation."""171 name = ndb.StringProperty()172 collocation = ndb.TextProperty()173 @classmethod174 def get_with_namespace(cls, id):175 user = users.get_current_user()176 previous_namespace = namespace_manager.get_namespace()177 try:178 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))179 coll = Collocation.get_by_id(id)180 finally:181 namespace_manager.set_namespace(previous_namespace)182 return coll183 @classmethod184 def get_by_name_with_namespace(cls, name):185 user = users.get_current_user()186 previous_namespace = namespace_manager.get_namespace()187 try:188 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))189 qry = Collocation.query(Collocation.name == name)190 coll = qry.get()191 finally:192 namespace_manager.set_namespace(previous_namespace)193 return coll194 @classmethod195 def get_by_name_or_new_with_namespace(cls, name):196 coll = cls.get_by_name_with_namespace(name)197 if coll is None:198 coll = Collocation()199 coll.name = name200 coll.content = ''201 return coll202 @classmethod203 def put_with_namespace(cls, coll):204 user = users.get_current_user()205 previous_namespace = namespace_manager.get_namespace()206 try:207 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))208 coll.put()209 finally:210 namespace_manager.set_namespace(previous_namespace)211 @classmethod212 def put_multi_with_namespace(cls, colls):213 user = users.get_current_user()214 previous_namespace = namespace_manager.get_namespace()215 try:216 namespace_manager.set_namespace(user.email().translate(NAMESPACE_TRANS))217 ndb.put_multi(colls)218 finally:...

Full Screen

Full Screen

dashboard_data.py

Source:dashboard_data.py Github

copy

Full Screen

1import pydcatchu2NS = pydcatchu.BaseNamespace("https://mgds.oeg.fi.upm.es/")3A1 = pydcatchu.Agent("MGDS")4A1.set_namespace(NS)5C1 = pydcatchu.Catalogue("Raw data", "Raw input data", A1)6C1.set_namespace(NS)7Da1 = pydcatchu.Dataset("Carto", "Cartographic data for MGDS visualizer")8Da1.set_namespace(NS)9Di1 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/raw/Carto.tar.xz")10Di1.set_namespace(NS)11Di1.set_title("Compressed folder")12Da1.add_distribution(Di1)13Da2 = pydcatchu.Dataset("Sentinel-2 observation", "Satelite data for MGDS visualizer")14Da2.set_namespace(NS)15Di2 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/raw/sentinel/T30TVK_20201219T110451_B04.jp2")16Di2.set_namespace(NS)17Di2.set_title("B04 band")18Da2.add_distribution(Di2)19Di3 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/raw/sentinel/T30TVK_20201219T110451_B08.jp2")20Di3.set_namespace(NS)21Di3.set_title("B08 band")22Da2.add_distribution(Di3)23Da3 = pydcatchu.Dataset("Censal", "Census data for MGDS visualizer")24Da3.set_namespace(NS)25Di4 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/raw/Censal.tar.xz")26Di4.set_namespace(NS)27Di4.set_title("Compressed folder")28Da3.add_distribution(Di4)29# JSON30Da4 = pydcatchu.Dataset("Processed data", "Processed data for MGDS visualizer in JSON format")31Da4.set_namespace(NS)32Di5 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/json/barrios_shape.json")33Di5.set_namespace(NS)34Da4.add_distribution(Di5)35Di6 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/json/distritos_shape.json")36Di6.set_namespace(NS)37Da4.add_distribution(Di6)38Di7 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/json/indexesBarrios.json")39Di7.set_namespace(NS)40Da4.add_distribution(Di7)41Di8 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/json/indexesCensal.json")42Di8.set_namespace(NS)43Da4.add_distribution(Di8)44Di9 = pydcatchu.Distribution("https://mgds.oeg.fi.upm.es/static-data/json/indexesDistritos.json")45Di9.set_namespace(NS)46Da4.add_distribution(Di9)47C1.add_dataset(Da1)48C1.add_dataset(Da2)49C1.add_dataset(Da3)50C1.add_dataset(Da4)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful