def get(self): """Function is called by cron to build a contact index Call with a key to build index for this entity. """ if not users.is_current_user_admin(): logging.critical("UpdateIndex called by non-admin") self.error(500) return key = self.request.get("key", None) logging.info("Update index tables.") if key: con = Contact.get(Key(key)) if con: update_index(con) # update dependant take2 entries for t2 in Take2.all().filter("contact_ref =", con): update_index(t2) # update parent login_user user = LoginUser.all().filter("me =", con).get() if user: update_index(user) return else: t2 = Take2.get(Key(key)) if t2: update_index(t2) return logging.info("Could not find key: %s" % (key)) return # Go through the tables which contribute to the index for table in [LoginUser,Contact,Address]: batch = [] for obj in table.all(): res = update_index(obj, batch=True) if res: batch.extend(res) # bulk db operation db.put(batch) logging.info("%d updates." % (len(batch))) self.response.headers['Content-Type'] = "text/plain" self.response.out.write("/index done.")
def deattic_take2(self, login_user=None, template_values={}): instance = self.request.get("instance", "") key = self.request.get("key", "") t2 = Take2.get(key) # consistency checks assert t2.class_name() == instance.title(), "Edit class name %s does not fit with object %s" % (instance,key) contact = t2.contact_ref assert contact.class_name() in ['Person','Contact'], "Object %s key: %s is not a Contact" % (contact.class_name(),str(contact.key())) # access check if not write_access(contact, login_user): self.error(500) return logging.debug("De-attic: %s instance: %s key: %s" % (contact.name,instance,key)) t2.attic = False; t2.put(); if t2.class_name() == 'Address': update_index(t2) self.redirect('/editcontact?key=%s' % str(contact.key()))