def post(self): """Deploy action""" json = {} for language in Language.all().filter('enabled_on_site =', True): logging.info("Buiding translation snapshot for " + language.code) translations = {} for key in language.translations: translation = db.get(key) translations[translation.phrase.text] = translation.text json[language.code] = translations logging.info("Encoding snapshot JSON") json = simplejson.dumps(json) logging.info("Switching active snapshot") active_snapshot = SnapshotMetadata.all().filter('active =', True).get() if active_snapshot: active_snapshot.active = False active_snapshot.save() metadata = SnapshotMetadata(active=True) metadata.put() content = SnapshotContent(metadata=metadata, json=json) content.put() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('success')
def post(self): """Deploy action""" json = {} for language in Language.all(): translations = {} for key in language.translations: translation = db.get(key) translations[translation.phrase.text] = translation.text json[language.code] = translations json = simplejson.dumps(json) active_snapshot = SnapshotMetadata.all().filter('active =', True).get() if active_snapshot: active_snapshot.active = False active_snapshot.save() metadata = SnapshotMetadata(active=True) metadata.put() content = SnapshotContent(metadata=metadata, json=json) content.put() init_cached_translations() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('success')
def init_cached_translations(): """This method initializes the app cached translations""" global deployed_translations logging.info("Initializing cached translations") metadata = SnapshotMetadata.all().filter('active =', True).get() if metadata: snapshot = SnapshotContent.all().filter('metadata =', metadata).get() deployed_translations = simplejson.loads(snapshot.json)
def get(self): json = []; for snapshot in SnapshotMetadata.all().order('-date'): json.append({ 'id': snapshot.key().id(), 'date': snapshot.date.strftime('%Y-%m-%d %H:%m'), 'active': snapshot.active, }) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json))
def get(self): json = [] for snapshot in SnapshotMetadata.all().order('-date'): json.append({ 'id': snapshot.key().id(), 'date': snapshot.date.strftime('%Y-%m-%d %H:%m'), 'active': snapshot.active, }) self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(json))