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 put(self): """Mark a specific snapshot as active""" if not users.is_current_user_admin(): self.error(403) snapshot_id = self.request.path.split('/')[-1] metadata = SnapshotMetadata.get_by_id(int(snapshot_id)) if metadata is None: self.error(404) else: current = SnapshotMetadata().all().filter('active =', True).get() if current: current.active = False current.save() metadata.active = True metadata.save() init_cached_translations() self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('success')