def post(self): #logging.error('QQQ: templatecreate POST') n = Templates(Name=self.request.get('Name') , TemplateType=self.request.get('TemplateType') , FolderName=self.request.get('FolderName') , FileName=self.request.get('FileName') , Description=self.request.get('Description') , Status=self.request.get('Status') ) n.put() return webapp2.redirect('/templates?extyp=all')
def post(self): #logging.error('QQQ: templatecreate POST') n = Templates(Name=self.request.get('Name') , TemplateType=self.request.get('TemplateType') , FileName=self.request.get('FileName') , Description=self.request.get('Description') , Status=self.request.get('Status') #, CreatedBy=users.get_current_user() #, StatusBy=users.get_current_user() #, StatusDate=datetime.now() # datetime.datetime.utcnow() - datetime.timedelta(hours = 5) for East Coast United States ) #logging.error('QQQ: templatecreate before put') n.put() #logging.error('QQQ: templatecreate after put') return webapp2.redirect('/templates')
def get(self): Dup = False if self.request.get('msg') == 'dup': Dup = True tknID = self.request.get('tknID') templateName = self.request.get('tName') languages = memcache.get("languages") if languages is not None: logging.info("get languages from memcache.") else: q = Languages.query().order(Languages.langName) languages = q.fetch(99) logging.info("Can not get languages from memcache.") if not memcache.add("languages", languages, 10): logging.info("Memcache set failed.") if self.request.get('langCode'): langCode=self.request.get('langCode') self.session['langCode'] = langCode else: langCode = self.session.get('langCode') if not langCode: self.session['langCode'] = 'en' langName = 'no language' for language in languages: if language.langCode == langCode: langName = language.langName q = Languages.query().order(Languages.langCode, Languages.langName) languages = q.fetch(999) langName = 'no language' for language in languages: if language.langCode == langCode: langName = language.langName q = Templates.query().order(Templates.Name) templates = q.fetch(99) if self.request.get('extyp'): extyp=self.request.get('extyp') self.session['extyp'] = extyp else: extyp = self.session.get('extyp') if not extyp: self.session['extyp'] = 'exercise' logout = None login = None currentuser = users.get_current_user() if currentuser: logout = users.create_logout_url('/tokens' ) else: login = users.create_login_url('/tokens/create') Src = 'template' StatusList = ['Pending Translation', 'Pending Review', 'Published']; self.render_template('TokenCreate.html', {'templates': templates, 'Src': Src, 'extyp':extyp, 'templateName': templateName, 'Dup': Dup, 'tknID': tknID, 'StatusList': StatusList, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
def get(self): templates = Templates.all() logout = None login = None currentuser = users.get_current_user() if currentuser: logout = users.create_logout_url('/templates' ) else: login = users.create_login_url('/templates/create') self.render_template('TemplateList.html', {'templates': templates,'currentuser':currentuser, 'login':login, 'logout': logout})
def load_templates(theme_path: str) -> Templates: jinja_env = Environment(loader=FileSystemLoader(theme_path)) jinja_env.filters['datetimeformat'] = __datetimeformat index_template = jinja_env.get_template('index.html') tag_template = jinja_env.get_template('tag.html') page_template = jinja_env.get_template('page.html') return Templates(index_template, page_template, tag_template)
def insert_template(name, description, markup): template_id = create_template_id(name) template = Templates(template_id, name, description, markup) conn = sqlite3.connect('template_data.db') # establish connection to the database c = conn.cursor() c.execute("""INSERT OR REPLACE INTO templates VALUES( :template_id, :name, :description, :markup ); """, {'template_id': template_id, 'name': name, 'description': description, 'markup': markup}) # exectute the query result = c.fetchall() conn.commit() # commit changes conn.close() # close connection print("Added template")
def get(self): # TemplateClone() # TemplateValSave() templates = Templates.query().order(Templates.Name) if self.request.get('extyp'): extyp=self.request.get('extyp') self.session['extyp'] = extyp else: extyp = self.session.get('extyp') if not extyp: self.session['extyp'] = 'exercise' logout = None login = None currentuser = users.get_current_user() if currentuser: logout = users.create_logout_url('/templates' ) else: login = users.create_login_url('/templates/create') self.render_template('TemplateList.html', {'templates': templates,'currentuser':currentuser, 'login':login, 'logout': logout})
def get(self): templateName=self.request.get('templateName') langCode=self.request.get('langCode') if self.request.get('extyp'): extyp=self.request.get('extyp') self.session['extyp'] = extyp else: extyp = self.session.get('extyp') if not extyp: self.session['extyp'] = 'exercise' q = Templates.query(Templates.Name == templateName) template = q.get() # template = ndb.Key('Templates', iden).get() FolderName = template.FolderName FileName = template.FileName logging.info('RRR: template.TemplateType: %s' % template.TemplateType) logging.info('RRR: template.Name: %s' % template.Name) logging.info('RRR: template.FileName: %s' % template.FileName) logging.info('RRR: template.FolderName: %s' % template.FolderName) SearchName = '' if template.TemplateType == 'exercise': logging.info('RRR: INSIDE IF - template.TemplateType: %s' % template.TemplateType) SearchName = FileName elif template.TemplateType == 'none': logging.info('RRR: INSIDE IF / elif - template.TemplateType: %s' % template.TemplateType) SearchName = FileName else: logging.info('RRR: INSIDE FAILED IF - template.TemplateType: %s' % template.TemplateType) SearchName = template.FolderName + '/' + template.FileName logging.info('RRR: template.SearchName: %s' % SearchName) fName = template.FileName FileGenPath = template.FileGenPath q = TokenValues.query(TokenValues.langCode == langCode, TokenValues.templateName == templateName).order(TokenValues.langCode, TokenValues.templateName, TokenValues.tknID) tokenvals = q.fetch(999) tokendict = {} for tokenval in tokenvals: tokendict[tokenval.tknID] = tokenval.tknValue logging.info('QQQ: TknID: %s' % tokenval.tknID) logging.info('QQQ: tknValue: %s' % tokenval.tknValue) #tokenvals = tokendict() currentuser = users.get_current_user() q = GeneratedFiles.query(GeneratedFiles.LangCode == langCode, GeneratedFiles.TemplateName == templateName) genfiles = q.fetch(9) if genfiles: for genfile in genfiles: genfile.key.delete() TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'tokenizedtemplates') jinja_environment = \ jinja2.Environment(autoescape=False, loader=jinja2.FileSystemLoader(TEMPLATE_DIR)) logging.info('QQQ: FileName: %s' % FileName) template = jinja_environment.get_template(FileName) # self.response.out.write(template.render(tokenvals = tokendict)) blobtext = template.render(tokenvals = tokendict) bloboutput = (blobtext.encode('utf-8')) # Create the file file_name = files.blobstore.create(mime_type='application/octet-stream') # Open the file and write to it with files.open(file_name, 'a') as fl: fl.write(blobtext) # Finalize the file. Do this before attempting to read it. files.finalize(file_name) # Get the file's blob key blob_key = files.blobstore.get_blob_key(file_name) logging.info('QQQ: blob_key: %s' % blob_key) f = GeneratedFiles( TemplateName = templateName , FolderName = FolderName , SearchName = SearchName , LangCode = langCode , FileName = fName , FileGenPath = FileGenPath , FileTxt = bloboutput , FileTxt2 = bloboutput , Status = 'Published' , blob = blob_key ) f.put() TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'templates') jinja_environment = \ jinja2.Environment(autoescape=False, loader=jinja2.FileSystemLoader(TEMPLATE_DIR)) return self.redirect('/tokens?templateName=' + templateName + '&langCode=' + langCode)
def get(self): #langCode='en' if self.request.get('langCode'): langCode=self.request.get('langCode') self.session['langCode'] = langCode else: langCode = self.session.get('langCode') if self.request.get('templateName'): templateName=self.request.get('templateName') self.session['templateName'] = templateName else: templateName = self.session.get('templateName') if self.request.get('extyp'): extyp=self.request.get('extyp') self.session['extyp'] = extyp else: extyp = self.session.get('extyp') if not extyp: self.session['extyp'] = 'exercise' if self.request.get('StatusFilter'): StatusFilter=self.request.get('StatusFilter') self.session['StatusFilter'] = StatusFilter else: StatusFilter = self.session.get('StatusFilter') if not StatusFilter: self.session['StatusFilter'] = 'all' StatusFilter = 'all' if self.request.get('TopGrpFilter'): TopGrpFilter=self.request.get('TopGrpFilter') self.session['TopGrpFilter'] = TopGrpFilter else: TopGrpFilter = self.session.get('TopGrpFilter') if not TopGrpFilter: self.session['TopGrpFilter'] = 'all' TopGrpFilter = 'all' countmap_en=0 langCode_en = 'en' q = TokenValues.query(TokenValues.langCode == langCode_en, TokenValues.templateName == templateName).order(TokenValues.langCode, TokenValues.tknID) tokens = q.fetch(999, keys_only=True) # tokens = TokenValues.all().filter('langCode =', langCode_en) for token in tokens: # logging.info('QQQ: token_en: %s' % token.langCode) countmap_en=countmap_en+1 countmap_other_language=0 if langCode != 'en': q = TokenValues.query(TokenValues.langCode == langCode, TokenValues.templateName == templateName).order(TokenValues.langCode, TokenValues.tknID) tokens = q.fetch(999, keys_only=True) # tokens = TokenValues().all().filter('langCode =', langCode) for token in tokens: # logging.info('QQQ: token_non-EN: %s' % token.langCode) countmap_other_language=countmap_other_language+1 # languages = Languages.all().filter('langCode =', langCode) q = Languages.query().order(Languages.langName) languages = q.fetch(999) langName = 'no language' for language in languages: if language.langCode == langCode: langName = language.langName q = TokenValues.query(TokenValues.langCode == langCode, TokenValues.templateName == templateName, TokenValues.Status != 'Published') TokensNotReady = q.get() if TokensNotReady: TemplateGenReady = False else: TemplateGenReady = True q = GeneratedFiles.query(GeneratedFiles.LangCode == langCode, GeneratedFiles.TemplateName == templateName).order(-GeneratedFiles.CreatedDate) GenFile = q.get() if GenFile: GenFileReady = GenFile.key.id() SearchName = GenFile.SearchName else: GenFileReady = None SearchName = None logging.info('GGG: StatusFilter in TokenList: %s' % StatusFilter) if StatusFilter == 'all': q = TokenValues.query(TokenValues.langCode == langCode, TokenValues.templateName == templateName).order(TokenValues.langCode, TokenValues.templateName, TokenValues.tknID) else: q = TokenValues.query(TokenValues.langCode == langCode, TokenValues.templateName == templateName, TokenValues.Status == StatusFilter).order(TokenValues.langCode, TokenValues.templateName, TokenValues.tknID) tokens = q.fetch(999) if StatusFilter == 'all': f = TokenValues.query(TokenValues.langCode == 'en', TokenValues.templateName == templateName) else: f = TokenValues.query(Subjects.LangCode == 'en', TokenValues.templateName == templateName, TokenValues.Status == StatusFilter) units_en = f.fetch(999) dict_units_en = {} dict_units_en['DummyTemplate'] = 'no content' dict_Context_en = {} dict_Context_en['DummyTemplate'] = 'no content' for unit_en in units_en: # logging.info('GGG: Subjects.py/LearningUnitID: %s' % unit_en.LearningUnitID) # logging.info('GGG: Subjects.py/Description: %s' % unit_en.Description) # if unit_en.Context: # dict_units_en[unit_en.tknID] = unit_en.tknValue + ' in (' + unit_en.Context + ')' # else: # dict_units_en[unit_en.tknID] = unit_en.tknValue dict_units_en[unit_en.tknID] = unit_en.tknValue dict_Context_en[unit_en.tknID] = unit_en.Context TryReady = False if GenFile: GenFileReady = GenFile.key.id() SearchName = GenFile.SearchName q2 = Templates.query(Templates.Name == GenFile.TemplateName) GenFileTemplate = q2.get() if GenFileTemplate.TemplateType == 'exercise': TryReady = True else: TryReady = False else: GenFileReady = None SearchName = None TryReady = False logging.info('GGG: Token.py/TryReady: %s' % TryReady) logout = None login = None currentuser = users.get_current_user() if currentuser: logout = users.create_logout_url('/tokens' ) else: login = users.create_login_url('/tokens') StatusList = ['Pending Translation', 'Pending Review', 'Published']; self.render_template('TokenListEdit.html', {'tokens': tokens, 'langName':langName, 'extyp':extyp, 'count_en':countmap_en, 'count_other_language':countmap_other_language, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'TopGrpFilter':TopGrpFilter, 'templateName':templateName, 'dict_units_en':dict_units_en, 'dict_Context_en':dict_Context_en, 'languages':languages, 'langCode':langCode, 'SearchName':SearchName, 'TryReady':TryReady, 'GenFileReady':GenFileReady, 'TemplateGenReady':TemplateGenReady, 'currentuser':currentuser, 'login':login, 'logout': logout})
def get(self): #languages = Languages.all() languages = memcache.get("languages") if languages is not None: logging.info("get languages from memcache.") else: q = Languages.query().order(Languages.langName) languages = q.fetch(99) logging.info("Can not get languages from memcache.") if not memcache.add("languages", languages, 10): logging.info("Memcache set failed.") if self.request.get('extyp'): extyp=self.request.get('extyp') self.session['extyp'] = extyp else: extyp = self.session.get('extyp') if not extyp: self.session['extyp'] = 'exercise' if self.request.get('langCode'): langCode=self.request.get('langCode') self.session['langCode'] = langCode else: langCode = self.session.get('langCode') if not langCode: self.session['langCode'] = 'en' langName = 'no language' for language in languages: if language.langCode == langCode: langName = language.langName PageCnt = self.session.get('PageCnt', 0) self.session['PageCnt'] = PageCnt + 1 countmap_en={} langCode_en = 'en' q = TokenValues.query(TokenValues.langCode == langCode_en).order(TokenValues.langCode, TokenValues.tknID) tokens = q.fetch(999) # tokens = TokenValues.all().filter('langCode =', langCode_en) for token in tokens: # logging.info('QQQ: token_en: %s' % token.langCode) if token.templateName in countmap_en: countmap_en[token.templateName]=countmap_en[token.templateName]+1 else: countmap_en[token.templateName]=1 countmap_other_language={} if langCode != 'en': q = TokenValues.query(TokenValues.langCode == langCode).order(TokenValues.langCode, TokenValues.tknID) tokens = q.fetch(999) # tokens = TokenValues().all().filter('langCode =', langCode) for token in tokens: # logging.info('QQQ: token_non-EN: %s' % token.langCode) if token.templateName in countmap_other_language: countmap_other_language[token.templateName]=countmap_other_language[token.templateName]+1 else: countmap_other_language[token.templateName]=1 ExerciseList=[] q = Templates.query(Templates.TemplateType != 'exercise') templates = q.fetch(99) for template in templates: logging.info('QQQ: TokenListStep1Page: %s' % template.Name) ExerciseList.append(template.Name) logout = None login = None currentuser = users.get_current_user() if currentuser: logout = users.create_logout_url('/tokens' ) else: login = users.create_login_url('/tokens') self.render_template('TokenStep1.html', {'PageCnt':PageCnt, 'extyp':extyp, 'languages':languages, 'langCode':langCode, 'langName':langName, 'countmap_en':countmap_en, 'countmap_other_language':countmap_other_language, 'ExerciseList': ExerciseList, 'tokens': tokens,'currentuser':currentuser, 'login':login, 'logout': logout})