コード例 #1
0
ファイル: Language.py プロジェクト: wmgraham1/NewDemo
 def post(self):
     n = Languages(langName=self.request.get('langName'),
               langCode=self.request.get('langCode'),
               langCode3=self.request.get('langCode3')
               )
     n.put()
     return webapp2.redirect('/langs')
コード例 #2
0
ファイル: Token.py プロジェクト: wmgraham1/edutrynew
    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})
コード例 #3
0
ファイル: Language.py プロジェクト: alfonsodev/edutrynew
 def post(self):
     n = Languages(
         langName=self.request.get("langName"),
         langCode=self.request.get("langCode"),
         langCode3=self.request.get("langCode3"),
     )
     n.put()
     return webapp2.redirect("/langs")
コード例 #4
0
ファイル: Test1.py プロジェクト: alfonsodev/edutrynew
    def get(self):
        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, 99):
                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' 
            langCode = 'en'

        y = 'hi there'
        TestVal1 = '' + Test1(y)
        logging.info('GGG: Test if function calls: %s' % TestVal1)

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/subjs' )
        else:
              login = users.create_login_url('/subjs')
		  
        self.render_template('Test1.html', {'TestVal1':TestVal1, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #5
0
ファイル: Language.py プロジェクト: wmgraham1/NewDemo
 def get(self):
     languages = Languages.all()
     logout = None
     login = None
     currentuser = users.get_current_user()
     if currentuser:
           logout = users.create_logout_url('/langs' )
     else:
           login = users.create_login_url('/langs/create')
     self.render_template('LangList.html', {'languages': languages,'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #6
0
ファイル: Language.py プロジェクト: alfonsodev/edutrynew
 def get(self):
     languages = Languages.query().order(Languages.langName)
     logout = None
     login = None
     currentuser = users.get_current_user()
     if currentuser:
         logout = users.create_logout_url("/langs")
     else:
         login = users.create_login_url("/langs/create")
     self.render_template(
         "LangList.html", {"languages": languages, "currentuser": currentuser, "login": login, "logout": logout}
     )
コード例 #7
0
ファイル: build.py プロジェクト: m4rc1e/iso639corpora
def main():
    db.connect()
    db.create_tables([Languages])

    for language in languages.languages:

        if language.part1 != '':
            try:
                wp_page = wptools.page(lang=language.part1).get_query()
                wp_text = wp_page.extext
            except pycurl.error:  # No wikipedia articles for this language
                wp_text = None
        else:
            wp_text = None

        Languages.create(
            name=language.name,
            part1=language.part1,
            part2=language.part2b,
            part3=language.part3,
            text=wp_text,
        )

    db.commit()
コード例 #8
0
ファイル: Token.py プロジェクト: wmgraham1/NewDemo
    def get(self):
        # langCode='en'
        langCode = self.request.get("langCode")

        languages = Languages.all().filter("langCode =", langCode)
        langName = "no language"
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName
        # if not langName:
        # langName = 'no language'

        # templateName='khan-exercise'
        templateName = self.request.get("templateName")

        q = db.GqlQuery(
            "SELECT * FROM TokenValues " + "WHERE langCode = :1 AND templateName = :2 " + "ORDER BY tknID ASC",
            langCode,
            templateName,
        )
        tokens = q.fetch(999)
        #        tokens = TokenValues.all()
        # tokens = TokenValues.query()
        # 	    langCode='en'
        #        if self.request.get('langCode'):
        #            langCode=self.request.get('langCode')
        # tokens = TokenValues.query(TokenValues.langCode == langCode)
        #            tokens = tokens.filter('langCode =', langCode)
        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")
        self.render_template(
            "TokenList.html",
            {
                "tokens": tokens,
                "langName": langName,
                "templateName": templateName,
                "currentuser": currentuser,
                "login": login,
                "logout": logout,
            },
        )
コード例 #9
0
ファイル: PageContent.py プロジェクト: wmgraham1/NewDemo
    def get(self):
        languages = memcache.get("languages")
        if languages is not None:
           logging.info("get languages from memcache.")
        else:
           languages = Languages.all()
           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 = db.GqlQuery("SELECT * FROM PageContents " + 
#                "WHERE langCode = :1 " +
#                "ORDER BY TemplateName ASC",
#                "en")
#        pagecontents = q.fetch(999)
		pagecontents = PageContents.all()
        logging.info('QQQ: PageContents.all(): %s' % PageContents.all())
        #logging.info('QQQ: pagecontents: %s' % pagecontents)
        if not pagecontents:
		    pagecontents = 'xxx'
 
        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/pagecontents' )
        else:
              login = users.create_login_url('/pagecontents/create')
#        self.render_template('PageContentList.html', {'pagecontents': pagecontents, 'LangName':LangName, 'currentuser':currentuser, 'login':login, 'logout': logout})
        self.render_template('PageContentList.html', {'pagecontents': pagecontents, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #10
0
ファイル: Subjects.py プロジェクト: alfonsodev/edutrynew
    def get(self):
        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' 
            langCode = 'en'

        SubjAreaFilter = self.session.get('SubjAreaFilter')
        if not SubjAreaFilter:
            self.session['SubjAreaFilter'] = 'Math'
            SubjAreaFilter = 'Math'

        SubjAreaList = []
        q = SubjectAreas.query(SubjectAreas.LangCode == langCode).order(SubjectAreas.Seq)
        SubjAreaResponseSet = q.fetch(999)
        for SubjArea in SubjAreaResponseSet:
            SubjAreaList.append(SubjArea.Name)

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/subjs' )
        else:
              login = users.create_login_url('/subjs')

#        SubjectList = ['Math', 'Biology', 'Chemistry'];		  
        self.render_template('LearnSubjCreate.html', {'SubjectList': SubjAreaList, 'SubjAreaFilter': SubjAreaFilter, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #11
0
ファイル: PageContent.py プロジェクト: alfonsodev/edutrynew
    def get(self):
        languages = memcache.get("languages")
        if languages is not None:
           logging.info("get languages from memcache.")
        else:
           languages = Languages.query()
           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

        pagecontents = PageContents.query()

        NoContent = True
        if pagecontents:
		    NoContent = False
 
        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/pagecontents' )
        else:
              login = users.create_login_url('/pagecontents/create')
        self.render_template('PageContentList.html', {'pagecontents': pagecontents, 'NoContent': NoContent, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #12
0
ファイル: Subjects.py プロジェクト: alfonsodev/edutrynew
    def get(self):
#        TopicSeqRecalc()
        
        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, 99):
                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' 
            langCode = 'en'

        langName = 'no language'
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        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('SubjAreaFilter'):
            SubjAreaFilter=self.request.get('SubjAreaFilter')
            self.session['SubjAreaFilter'] = SubjAreaFilter
        else:
            SubjAreaFilter = self.session.get('SubjAreaFilter')
        if not SubjAreaFilter:
            self.session['SubjAreaFilter'] = 'Math'
            SubjAreaFilter = 'Math'

        if self.request.get('Typ'):
            Typ=self.request.get('Typ')
            self.session['Typ'] = Typ
        else:
            Typ = self.session.get('Typ')
        if not Typ:
            self.session['Typ'] = 'ex'
            Typ = 'ex'

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/units' )
        else:
              login = users.create_login_url('/units')

        SubjAreaList = []
        q = SubjectAreas.query(SubjectAreas.LangCode == langCode)
        SubjAreaResponseSet = q.fetch(999)
        for SubjArea in SubjAreaResponseSet:
            SubjAreaList.append(SubjArea.Name)
        StatusList = ['Pending Translation', 'Pending Review', 'Published'];
#        SubjAreaList = ['Math', 'Science'];	
        logging.info('QQQ: rq rq rq: %s' % self.request.get('rq'))
#        if self.request.get('rq') == '2':

        Cnt = memcache.get("Subj_EnCnt")
        if Cnt is not None:
            logging.info("PPP - got Subj_EnCnt from memcache.")
            count_en = Cnt
        else:
            logging.info("PPP - Could not get Subjs_EnCnt from memcache.")
            count_en = 0
            langCode_en = 'en'
            units = memcache.get("Subjs_En")
            if units is not None:
                logging.info("PPP - got Subjs_En_units from memcache.")
            else:
                # logging.info("PPP - Can not get SubjAreas_units from memcache.")
                q = Subjects.query(Subjects.LangCode == langCode_en)
                units = q.fetch(999, keys_only=True)
                if not memcache.add("Subjs_En", units, 999):
                    logging.info("PPP - Subjs_EnCnt_Memcache set failed.")
            for unit in units:
#                logging.info('QQQ: count_en: %d' % count_en)
                count_en = count_en + 1
            if not memcache.add("Subj_EnCnt", count_en, 999):
                    logging.info("PPP - Subj_EnCnt_Memcache set failed.")
        logging.info('QQQ: Total count_en: %d' % count_en)

        # count_en = 0
        # langCode_en = 'en'
        # q = Subjects.query(Subjects.LangCode == langCode_en)
        # units = q.fetch(999)
        # for unit in units:
            # logging.info('QQQ: count_en: %d' % count_en)
            # count_en = count_en + 1
        # logging.info('QQQ: Total count_en: %d' % count_en)

        logging.info('QQQ: langCode: %s' % langCode)
        count_other_language = 0
        q2 = Subjects.query(Subjects.LangCode == langCode)
        unitsx = q2.fetch(999, keys_only=True)
        for unit in unitsx:
            logging.info('QQQ: count_other_language: %d' % count_other_language)
            count_other_language = count_other_language + 1
        logging.info('QQQ: Total count_other_language: %d' % count_other_language)

        logging.info('GGG: StatusFilter in LearnUnitList: %s' % StatusFilter)
        logging.info('GGG: SubjAreaFilter in LearnUnitList: %s' % SubjAreaFilter)
        if SubjAreaFilter == 'all':
            if StatusFilter == 'all':
                logging.info('GGG: Which Query in LearnUnitList: %s' % 'all and all')
                logging.info('GGG: LangCode in LearnUnitList: %s' % langCode)
                q = Subjects.query(Subjects.LangCode == langCode).order(Subjects.Seq, Subjects.LearningUnitID)
            else:
                logging.info('GGG: Which Query in LearnUnitList: %s' % 'all and StatusFilter')
                logging.info('GGG: LangCode in LearnUnitList: %s' % langCode)
                logging.info('GGG: StatusFilter in LearnUnitList: %s' % StatusFilter)
                q = Subjects.query(Subjects.LangCode == langCode, Subjects.Status == StatusFilter).order(Subjects.Seq, Subjects.LearningUnitID)
        else:
            if StatusFilter == 'all':
                logging.info('GGG: Which Query in LearnUnitList: %s' % 'SubjAreaFilter and all')
                logging.info('GGG: LangCode in LearnUnitList: %s' % langCode)
                logging.info('GGG: SubjAreaFilter in LearnUnitList: %s' % SubjAreaFilter)
                q = Subjects.query(Subjects.LangCode == langCode, Subjects.Subject == SubjAreaFilter).order(Subjects.Seq, Subjects.LearningUnitID)
            else:
                logging.info('GGG: Which Query in LearnUnitList: %s' % 'SubjAreaFilter and StatusFilter')
                logging.info('GGG: LangCode in LearnUnitList: %s' % langCode)
                logging.info('GGG: SubjAreaFilter in LearnUnitList: %s' % SubjAreaFilter)
                logging.info('GGG: StatusFilter in LearnUnitList: %s' % StatusFilter)
                q = Subjects.query(Subjects.LangCode == langCode, Subjects.Subject == SubjAreaFilter, Subjects.Status == StatusFilter).order(Subjects.Seq, Subjects.LearningUnitID)

        units = q.fetch(999)
    #    self.render_template('LearnSubjList.html', {'units': units, 'count_en': count_en, 'count_other_language': count_other_language, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'SubjAreaFilter':SubjAreaFilter, 'SubjAreaList':SubjAreaList, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})

#        else:
#            units = []
#            count_en = 0
#            count_other_language = 0
        self.render_template('LearnSubjList.html', {'units': units, 'count_en': count_en, 'count_other_language': count_other_language, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'SubjAreaFilter':SubjAreaFilter, 'Typ':Typ, 'SubjAreaList':SubjAreaList, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #13
0
ファイル: Aids.py プロジェクト: alfonsodev/edutrynew
    def get(self):
#        AidSubjRecalc()
        AidSeqPop()
#        AidSeqRecalc()
        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' 
            langCode = 'en'

        langName = 'no language'
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        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('SubjFilter'):
            SubjFilter=self.request.get('SubjFilter')
            self.session['SubjFilter'] = SubjFilter
        else:
            SubjFilter = self.session.get('SubjFilter')
        if not SubjFilter:
            self.session['SubjFilter'] = 'all'
            SubjFilter = 'all'

        if self.request.get('TopAreaFilter'):
            TopAreaFilter=self.request.get('TopAreaFilter')
            self.session['TopAreaFilter'] = TopAreaFilter
        else:
            TopAreaFilter = self.session.get('TopAreaFilter')
        if not TopAreaFilter:
            self.session['TopAreaFilter'] = 'all'
            TopAreaFilter = 'all'

        count_en = 0
        langCode_en = 'en'
        q = LearnAids.query(LearnAids.LangCode == langCode_en)
        aids = q.fetch(999)
        for aid in aids:
            logging.info('QQQ: count_en: %d' % count_en)
            count_en = count_en + 1
        logging.info('QQQ: Total count_en: %d' % count_en)

        logging.info('QQQ: langCode: %s' % langCode)
        count_other_language = 0
        q2 = LearnAids.query(LearnAids.LangCode == langCode)
        aidsx = q2.fetch(999)
        for aid in aidsx:
            logging.info('QQQ: count_other_language: %d' % count_other_language)
            count_other_language = count_other_language + 1
        logging.info('QQQ: Total count_other_language: %d' % count_other_language)

        logging.info('GGG: StatusFilter in LearnAidList: %s' % StatusFilter)
        if StatusFilter == 'all':
            if TopAreaFilter == 'all':
                q = LearnAids.query(LearnAids.LangCode == langCode).order(LearnAids.Seq, LearnAids.LearnAidID)
            else:
                q = LearnAids.query(LearnAids.LangCode == langCode, LearnAids.Subject == TopAreaFilter).order(LearnAids.Seq, LearnAids.LearnAidID)
        else:
            if TopAreaFilter == 'all':
                q = LearnAids.query(LearnAids.LangCode == langCode, LearnAids.Status == StatusFilter).order(LearnAids.Seq, LearnAids.LearnAidID)
            else:
                q = LearnAids.query(LearnAids.LangCode == langCode, LearnAids.Status == StatusFilter, LearnAids.Subject == TopAreaFilter).order(LearnAids.Seq, LearnAids.LearnAidID)

        aids = q.fetch(999)

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/aids' )
        else:
              login = users.create_login_url('/aids')

        StatusList = ['Pending Translation', 'Pending Review', 'Published'];

        self.render_template('LearnAidList.html', {'aids': aids, 'count_en': count_en, 'count_other_language': count_other_language, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'SubjFilter':SubjFilter, 'TopAreaFilter':TopAreaFilter, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #14
0
ファイル: Token.py プロジェクト: wmgraham1/edutrynew
    def get(self):
        languages = Languages.query()

        countmap_other_language={}
#		templateName2 = 'khan-exercise'	 and 'templateName', templateName2
        langCode2 = ''
        if self.request.get('langCode'):
            langCode2=self.request.get('langCode')
        if langCode2 == 'en':
            langCode2 = 'xx'
        if self.request.get('templateName'):
            templateName2=self.request.get('templateName')
        else:
            templateName2='none'
        if langCode2 != 'en': 
            logging.info('GGG: langCode_just_B4_Query1_NotEN: %s' % langCode2)
            logging.info('GGG: templateName_just_B4_Query1_NotEN: %s' % templateName2)
            q = TokenValues.query(TokenValues.langCode == langCode2, TokenValues.templateName == templateName2).order(TokenValues.langCode, TokenValues.templateName)
#		q = db.GqlQuery("SELECT * FROM TokenValues " + 
#                "WHERE langCode = :1 AND templateName = :2 " +
#                "ORDER BY tknID ASC",
#                langCode2, templateName2)
            tokens = q.fetch(999)		
#            tokens = TokenValues().all().filter('langCode =', langCode2)
            for token in tokens:
                logging.info('QQQ: token: %s' % token.langCode)
                if token.tknID not in countmap_other_language:
                        countmap_other_language[token.tknID]=1

        langCode='en'
        logging.info('GGG: langCode_just_B4_Query2_EN: %s' % langCode)
        logging.info('GGG: templateName_just_B4_Query2_EN: %s' % templateName2)
        q = TokenValues.query(TokenValues.langCode == langCode, TokenValues.templateName == templateName2).order(TokenValues.langCode, TokenValues.templateName)
#        q = db.GqlQuery("SELECT * FROM TokenValues " + 
#            "WHERE langCode = :1 AND templateName = :2 " +
#            "ORDER BY tknID ASC",
#            langCode, templateName2)
        tokens = q.fetch(999)
#        tokens = TokenValues.all().filter('langCode =', 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'

        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')

        if langCode2 == 'xx':
            if extyp == 'exercise':
                return self.redirect('/tokens')
            else:
                return self.redirect('/tokens-step1')

#        self.render_template('TokenStep1.html', {'languages':languages, 'langCode':langCode, 'countmap_other_language':countmap_other_language, 'tokens': tokens,'currentuser':currentuser, 'login':login, 'logout': logout})
        else:		
            for token in tokens:
                if token.tknID not in countmap_other_language:
                    n = TokenValues(templateName=token.templateName
                        , langCode=self.request.get('langCode')
                        , tknID=token.tknID
                        , tknValue=token.tknValue
                        , tknValue2=token.tknValue2
                        )
                    n.put()
            if extyp == 'exercise':
                return self.redirect('/tokens')
            else:
                return self.redirect('/tokens-step1')
コード例 #15
0
ファイル: SubjAreas.py プロジェクト: alfonsodev/edutrynew
    def get(self):
        languages = memcache.get("languages")
        if languages is not None:
            logging.info("PPP - got languages from memcache.")
        else:
            logging.info("PPP - Can not get languages from memcache.")
            q = Languages.query().order(Languages.langName)
            languages = q.fetch(99)
            if not memcache.add("languages", languages, 99):
                logging.info("PPP - Memcache set failed.")
            # languages = memcache.get("languages")
            # if languages is not None:
                # logging.info("PPP2 - got languages from memcache.")
            # else:
                # logging.info("PPP - Can not get languages from memcache.")
                # q = Languages.query().order(Languages.langName)
                # languages = q.fetch(99)
                # if not memcache.add("languages", languages, 99):
                    # logging.info("PPP - Memcache set failed.")
            
        langCode = 'en'
        if self.request.get('langCode'):
#            logging.info('GGG: SubjAreasList-Where: %s' % 'LangCode passed as param')
            langCode=self.request.get('langCode')
            self.session['langCode'] = langCode
        else:
#            logging.info('GGG: SubjAreasList-Where: %s' % 'LangCode NOT passed as param - prep get from session')
#            logging.info('GGG: SubjAreasList-LangCode before session.get = : %s' % langCode)
            langCode = self.session.get('langCode')
#            logging.info('GGG: SubjAreasList-LangCode after session.get = : %s' % langCode)
        if not langCode:
#            logging.info('GGG: SubjAreasList-Where: %s' % 'LangCode still blank')
            langCode = 'en'

        langName = 'no language'
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        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('Typ'):
            Typ=self.request.get('Typ')
            self.session['Typ'] = Typ
        else:
            Typ = self.session.get('Typ')
        if not Typ:
            self.session['Typ'] = 'ex'
            Typ = 'ex'

        # count_en = 0
        # langCode_en = 'en'
        # units = memcache.get("SubjAreas")
        # if units is not None:
            # logging.info("PPP - got SubjAreas_units from memcache.")
        # else:
            # logging.info("PPP - Can not get SubjAreas_units from memcache.")
            # q = SubjectAreas.query(SubjectAreas.LangCode == langCode_en)
            # units = q.fetch(999)
            # if not memcache.add("SubjAreas", units, 999):
                # logging.info("PPP - SubjAreas_Memcache set failed.")
        # for unit in units:
            # logging.info('QQQ: count_en: %d' % count_en)
            # count_en = count_en + 1
        # logging.info('QQQ: Total count_en: %d' % count_en)

        Cnt = memcache.get("SubjAreas_EnCnt")
        if Cnt is not None:
            logging.info("PPP - got SubjAreas_EnCnt from memcache.")
            count_en = Cnt
        else:
            logging.info("PPP - Could not get SubjAreas_EnCnt from memcache.")
            count_en = 0
            langCode_en = 'en'
            units = memcache.get("SubjAreas")
            if units is not None:
                logging.info("PPP - got SubjAreas_units from memcache.")
            else:
                # logging.info("PPP - Can not get SubjAreas_units from memcache.")
                q = SubjectAreas.query(SubjectAreas.LangCode == langCode_en)
                units = q.fetch(999, keys_only=True)
                if not memcache.add("SubjAreas", units, 999):
                    logging.info("PPP - SubjAreas_Memcache set failed.")
            for unit in units:
#                logging.info('QQQ: count_en: %d' % count_en)
                count_en = count_en + 1
            if not memcache.add("SubjAreas_EnCnt", count_en, 999):
                    logging.info("PPP - SubjAreas_EnCnt_Memcache set failed.")
        logging.info('QQQ: Total count_en: %d' % count_en)

        logging.info('QQQ: langCode: %s' % langCode)
        count_other_language = 0
        q2 = SubjectAreas.query(SubjectAreas.LangCode == langCode)
        unitsx = q2.fetch(999, keys_only=True)
        for unit in unitsx:
#            logging.info('QQQ: count_other_language: %d' % count_other_language)
            count_other_language = count_other_language + 1
        logging.info('QQQ: Total count_other_language: %d' % count_other_language)

        logging.info('GGG: StatusFilter in SubjAreasList: %s' % StatusFilter)
        if StatusFilter == 'all':
            q = SubjectAreas.query(SubjectAreas.LangCode == langCode).order(SubjectAreas.Seq, SubjectAreas.LearningUnitID)
        else:
            q = SubjectAreas.query(SubjectAreas.LangCode == langCode, SubjectAreas.Status == StatusFilter).order(SubjectAreas.Seq, SubjectAreas.LearningUnitID)
        units = q.fetch(999)

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/subjareas' )
        else:
              login = users.create_login_url('/subjareas')

        StatusList = ['Pending Translation', 'Pending Review', 'Published'];

        self.render_template('LearnSubjAreaList.html', {'units': units, 'Typ': Typ, 'count_en': count_en, 'count_other_language': count_other_language, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #16
0
ファイル: TopicGrps.py プロジェクト: alfonsodev/edutrynew
    def get(self):
        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"
            langCode = "en"

        langName = "no language"
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        if self.request.get("Typ"):
            Typ = self.request.get("Typ")
            self.session["Typ"] = Typ
        else:
            Typ = self.session.get("Typ")
        if not Typ:
            self.session["Typ"] = "ex"
            Typ = "ex"

        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("SubjFilter"):
            SubjFilter = self.request.get("SubjFilter")
            self.session["SubjFilter"] = SubjFilter
        else:
            SubjFilter = self.session.get("SubjFilter")
        if not SubjFilter:
            self.session["SubjFilter"] = "all"
            SubjFilter = "all"

        Cnt = memcache.get("TopGrp_EnCnt")
        if Cnt is not None:
            logging.info("PPP - got TopGrp_EnCnt from memcache.")
            count_en = Cnt
        else:
            logging.info("PPP - Could not get TopGrp_EnCnt from memcache.")
            count_en = 0
            langCode_en = "en"
            units = memcache.get("TopGrps_En")
            if units is not None:
                logging.info("PPP - got TopGrps_En from memcache.")
            else:
                logging.info("PPP - Can not get TopGrps_En_units from memcache.")
                q = TopicGrps.query(TopicGrps.LangCode == langCode_en)
                units = q.fetch(999, keys_only=True)
                if not memcache.add("TopGrps_En", units, 999):
                    logging.info("PPP - TopGrps_En_Memcache set failed.")
            for unit in units:
                #                logging.info('QQQ: count_en: %d' % count_en)
                count_en = count_en + 1
            if not memcache.add("TopGrp_EnCnt", count_en, 999):
                logging.info("PPP - TopGrp_EnCnt_Memcache set failed.")
        logging.info("QQQ: Total count_en: %d" % count_en)

        # count_en = 0
        # langCode_en = 'en'
        # q = TopicGrps.query(TopicGrps.LangCode == langCode_en)
        # units = q.fetch(999)
        # for unit in units:
        # logging.info('QQQ: count_en: %d' % count_en)
        # count_en = count_en + 1
        # logging.info('QQQ: Total count_en: %d' % count_en)

        logging.info("QQQ: langCode: %s" % langCode)
        count_other_language = 0
        q2 = TopicGrps.query(TopicGrps.LangCode == langCode)
        unitsx = q2.fetch(999, keys_only=True)
        for unit in unitsx:
            logging.info("QQQ: count_other_language: %d" % count_other_language)
            count_other_language = count_other_language + 1
        logging.info("QQQ: Total count_other_language: %d" % count_other_language)

        logging.info("GGG: StatusFilter in LearnUnitList: %s" % StatusFilter)
        if StatusFilter == "all":
            if SubjFilter == "all":
                q = TopicGrps.query(TopicGrps.LangCode == langCode).order(TopicGrps.Seq, TopicGrps.LearningUnitID)
            else:
                q = TopicGrps.query(TopicGrps.LangCode == langCode, TopicGrps.Subject == SubjFilter).order(
                    TopicGrps.Seq, TopicGrps.LearningUnitID
                )
        else:
            if SubjFilter == "all":
                q = TopicGrps.query(TopicGrps.LangCode == langCode, TopicGrps.Status == StatusFilter).order(
                    TopicGrps.Seq, TopicGrps.LearningUnitID
                )
            else:
                q = TopicGrps.query(
                    TopicGrps.LangCode == langCode, TopicGrps.Status == StatusFilter, TopicGrps.Subject == SubjFilter
                ).order(TopicGrps.Seq, TopicGrps.LearningUnitID)

        units = q.fetch(999)

        q4 = Subjects.query(Subjects.LangCode == langCode, Subjects.Subject == SubjFilter).order(Subjects.Seq)
        subjects = q4.fetch(999)
        SubjectList = []
        if subjects:
            for subject in subjects:
                SubjectList.append(subject.Name)
        else:
            SubjectList.append("none")

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
            logout = users.create_logout_url("/topgrps")
        else:
            login = users.create_login_url("/topgrps")

        StatusList = ["Pending Translation", "Pending Review", "Published"]
        #        SubjectList = ['Math', 'Science'];
        self.render_template(
            "LearnTopicGrpList.html",
            {
                "units": units,
                "count_en": count_en,
                "count_other_language": count_other_language,
                "StatusList": StatusList,
                "SubjectList": SubjectList,
                "StatusFilter": StatusFilter,
                "Typ": Typ,
                "SubjFilter": SubjFilter,
                "languages": languages,
                "langCode": langCode,
                "langName": langName,
                "currentuser": currentuser,
                "login": login,
                "logout": logout,
            },
        )
コード例 #17
0
ファイル: Token.py プロジェクト: wmgraham1/edutrynew
    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('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

        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, 'languages':languages, 'langCode':langCode, 'langName':langName, 'countmap_en':countmap_en, 'countmap_other_language':countmap_other_language, 'tokens': tokens,'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #18
0
ファイル: TopicAreas.py プロジェクト: alfonsodev/edutrynew
    def get(self):
        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' 
            langCode = 'en'

        langName = 'no language'
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        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('SubjFilter'):
            SubjFilter=self.request.get('SubjFilter')
            self.session['SubjFilter'] = SubjFilter
        else:
            SubjFilter = self.session.get('SubjFilter')
        if not SubjFilter:
            self.session['SubjFilter'] = 'all'
            SubjFilter = 'all'

        count_en = 0
        langCode_en = 'en'
        q = TopicAreas.query(TopicAreas.LangCode == langCode_en)
        units = q.fetch(999)
        for unit in units:
            logging.info('QQQ: count_en: %d' % count_en)
            count_en = count_en + 1
        logging.info('QQQ: Total count_en: %d' % count_en)

        logging.info('QQQ: langCode: %s' % langCode)
        count_other_language = 0
        q2 = TopicAreas.query(TopicAreas.LangCode == langCode)
        unitsx = q2.fetch(999)
        for unit in unitsx:
            logging.info('QQQ: count_other_language: %d' % count_other_language)
            count_other_language = count_other_language + 1
        logging.info('QQQ: Total count_other_language: %d' % count_other_language)

        logging.info('GGG: StatusFilter in LearnUnitList: %s' % StatusFilter)
        if StatusFilter == 'all':
            if SubjFilter == 'all':
                q = TopicAreas.query(TopicAreas.LangCode == langCode).order(TopicAreas.Seq, TopicAreas.LearningUnitID)
            else:
                q = TopicAreas.query(TopicAreas.LangCode == langCode, TopicAreas.Subject == SubjFilter).order(TopicAreas.Seq, TopicAreas.LearningUnitID)
        else:
            if SubjFilter == 'all':
                q = TopicAreas.query(TopicAreas.LangCode == langCode, TopicAreas.Status == StatusFilter).order(TopicAreas.Seq, TopicAreas.LearningUnitID)
            else:
                q = TopicAreas.query(TopicAreas.LangCode == langCode, TopicAreas.Status == StatusFilter, TopicAreas.Subject == SubjFilter).order(TopicAreas.Seq, TopicAreas.LearningUnitID)
        units = q.fetch(999)

        if StatusFilter == 'all':
            if SubjFilter == 'all':
                f = TopicAreas.query(TopicAreas.LangCode == 'en')
            else:
                f = TopicAreas.query(TopicAreas.LangCode == 'en', TopicAreas.Subject == SubjFilter)
        else:
            if SubjFilter == 'all':
                f = TopicAreas.query(TopicAreas.LangCode == 'en', TopicAreas.Status == StatusFilter)
            else:
                f = TopicAreas.query(TopicAreas.LangCode == 'en', TopicAreas.Status == StatusFilter, TopicAreas.Subject == SubjFilter)
        units_en = f.fetch(999)

        dict_units_en = {}
        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)
            dict_units_en[unit_en.LearningUnitID] = unit_en.Description

        q4 = Subjects.query(Subjects.LangCode == langCode, Subjects.Subject == 'Math')
        subjects = q4.fetch(999)
        SubjectList = []
        if subjects:
            for subject in subjects:
                SubjectList.append(subject.Name)
        else:
            SubjectList.append('none')
            
        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/topareas' )
        else:
              login = users.create_login_url('/topareas')

        StatusList = ['Pending Translation', 'Pending Review', 'Published'];
#        SubjectList = ['Math', 'Science'];	
        self.render_template('LearnTopicAreaListEdit.html', {'units': units, 'count_en': count_en, 'count_other_language': count_other_language, 'StatusList':StatusList, 'SubjectList':SubjectList, 'StatusFilter':StatusFilter, 'SubjFilter':SubjFilter, 'dict_units_en':dict_units_en, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #19
0
ファイル: Token.py プロジェクト: wmgraham1/edutrynew
    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})
コード例 #20
0
ファイル: post.py プロジェクト: Danutu89/NewApp-V2
def new(*args, **kwargs):
    currentUser = User.get().filter_by(
        name=kwargs['token']['name']).first_or_404()

    if not currentUser.role.permissions.add_post:
        return make_response(
            jsonify({
                'operation': 'error',
                'error': 'Missing permissions'
            }), 401)

    if not request.form['data']:
        return make_response(
            jsonify({
                'operation': 'error',
                'error': 'Missing data'
            }), 401)

    data = json.loads(str(request.form['data']))

    if not data['title'] or not data['content'] or not data['tags']:
        return make_response(
            jsonify({
                'operation': 'error',
                'error': 'Missing data'
            }), 401)

    index = str(db.session.execute(Sequence('post_id_seq')))
    thumbnail_link = None
    if data['image']:
        thumbnail = SaveImage(index)
        thumbnail_link = url_for('static',
                                 filename='thumbail_post/{}'.format(thumbnail))
    else:
        thumbnail_link = 'none'

    lang = translate.getLanguageForText(
        str(cleanhtml(data['content'])).encode('utf-8-sig'))

    langQuery = Languages.get().filter_by(code=lang.iso_tag).first()

    if langQuery is None:
        new_lang = Languages(name=lang.language, code=lang.iso_tag)
        new_lang.add()
        langQuery = new_lang

    tags_ids = []
    tags = []

    for tag in data['tags']:
        check = Post_Tag.get().filter_by(name=tag).first()

        if check is None:
            new_tag = Post_Tag(name=tag, count=1)
            new_tag.add()
            check = new_tag
        else:
            setattr(check, 'count', Post_Tag.count + 1)
            check.save()

        tags_ids.append(check.id)

    for tag_id in tags_ids:
        tags.append({"post": index, "tag_id": tag_id})

    nPost = NewPostSchema().load({
        "id":
        int(index),
        "title":
        data['title'],
        "read_time":
        str(readtime.of_html(data['content'])),
        "author_id":
        currentUser.id,
        "language_id":
        langQuery.id,
        "info": {
            "thumbnail": thumbnail_link,
            "text": data['content'],
            "tags": tags
        },
        "link":
        '/post/' + (str(data['title']).replace(' ', '-')).replace('?', '') +
        '-' + str(index)
    })

    nPost.add()

    for user in currentUser.followed:
        not_id = str(db.session.execute(Sequence('notification_id_seq')))
        notification = Notification(
            id=int(not_id),
            author=currentUser.id,
            user=user.user,
            type=5,
            title=nPost.title,
            body='{} shared a new post'.format(currentUser.name),
            link=nPost.link + '?notification_id=' + str(not_id))
        send_notification(
            user.user, {
                'text': '{} shared a new post'.format(currentUser.name),
                'link': nPost.link + '?notification_id=' + str(not_id),
                'icon': currentUser.info.avatar_img,
                'id': int(not_id)
            })
        notification.add()

    return make_response(jsonify({
        'operation': 'success',
        'link': nPost.link
    }), 200)
コード例 #21
0
ファイル: Token.py プロジェクト: wmgraham1/NewDemo
    def get(self):
        # languages = Languages.all()
        languages = memcache.get("languages")
        if languages is not None:
            logging.info("get languages from memcache.")
        else:
            languages = Languages.all()
            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"

        # currLanguage = languages.filter('langCode =', langCode)
        langName = "no language"
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName
        # if not langName:
        # langName = 'no language'

        PageCnt = self.session.get("PageCnt", 0)
        # PageCnt = int(0 if PageCnt is None else PageCnt) + 1
        self.session["PageCnt"] = PageCnt + 1

        countmap_en = {}
        tokens = TokenValues.all().filter("langCode =", langCode)
        for token in tokens:
            logging.info("QQQ: token: %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":
            tokens = TokenValues().all().filter("langCode =", langCode)
            for token in tokens:
                logging.info("QQQ: token: %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

        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")

        self.render_template(
            "TokenStep1.html",
            {
                "PageCnt": PageCnt,
                "languages": languages,
                "langCode": langCode,
                "langName": langName,
                "countmap_en": countmap_en,
                "countmap_other_language": countmap_other_language,
                "tokens": tokens,
                "currentuser": currentuser,
                "login": login,
                "logout": logout,
            },
        )
コード例 #22
0
    def get(self):
        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' 
            langCode = 'en'

        langName = 'no language'
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        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('SubjFilter'):
            # SubjFilter=self.request.get('SubjFilter')
            # self.session['SubjFilter'] = SubjFilter
        # else:
            # SubjFilter = self.session.get('SubjFilter')
        # if not SubjFilter:
            # self.session['SubjFilter'] = 'all'
            # SubjFilter = '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'

        TopGrpList = []
        if langCode == 'en':
            q = TopicGrps.query(TopicGrps.LangCode == 'en').order(TopicGrps.Seq, TopicGrps.Name)
            SubjAreaResponseSet = q.fetch(999)
            for SubjArea in SubjAreaResponseSet:
                TopGrpList.append(SubjArea.Name)

        # count_en = 0
        # langCode_en = 'en'
        # q = LearningUnits.query(LearningUnits.LangCode == langCode_en)
        # units = q.fetch(999)
        # for unit in units:
# #            logging.info('QQQ: count_en: %d' % count_en)
            # count_en = count_en + 1
        # logging.info('QQQ: Total count_en: %d' % count_en)

        # logging.info('QQQ: langCode: %s' % langCode)
        # count_other_language = 0
        # q2 = LearningUnits.query(LearningUnits.LangCode == langCode)
        # unitsx = q2.fetch(999)
        # for unit in unitsx:
# #            logging.info('QQQ: count_other_language: %d' % count_other_language)
            # count_other_language = count_other_language + 1
        # logging.info('QQQ: Total count_other_language: %d' % count_other_language)

        # logging.info('LLL: StatusFilter in LearnUnitList: %s' % StatusFilter)
        # logging.info('LLL: TopGrpFilter in LearnUnitList: %s' % TopGrpFilter)
        # logging.info('LLL: langCode in LearnUnitList: %s' % langCode)
        #TopGrpFilter = 'all'
        #StatusFilter = 'all'
        if StatusFilter == 'all':
            if TopGrpFilter == 'all':
                logging.info('LLL: in LearnUnitList: now in all/all')
                q = LearningUnits.query(LearningUnits.LangCode == langCode).order(LearningUnits.Seq, LearningUnits.LearningUnitID) 
            else:
                logging.info('LLL: in LearnUnitList: now in all/TopGrpFilter')
                q = LearningUnits.query(LearningUnits.LangCode == langCode, LearningUnits.Subject == TopGrpFilter).order(LearningUnits.Seq, LearningUnits.LearningUnitID)
        else:
            if TopGrpFilter == 'all':
                logging.info('LLL: in LearnUnitList: now in StatusFilter/all')
                q = LearningUnits.query(LearningUnits.LangCode == langCode, LearningUnits.Status == StatusFilter).order(LearningUnits.Seq, LearningUnits.LearningUnitID)
            else:
                logging.info('LLL: in LearnUnitList: now in StatusFilter/TopGrpFilter')
                q = LearningUnits.query(LearningUnits.LangCode == langCode, LearningUnits.Status == StatusFilter, LearningUnits.Subject == TopGrpFilter).order(LearningUnits.Seq, LearningUnits.LearningUnitID)
#        q = LearningUnits.query(LearningUnits.LangCode == langCode_en, LearningUnits.Subject == 'Math').order(LearningUnits.LearningUnitID)
        logging.info('LLL: q in LearnUnitList: %s' % q)
        units = q.fetch(999)

        dict_units_en = self.session.get('listEditUnits_en')
        if not dict_units_en:
            f = LearningUnits.query(LearningUnits.LangCode == 'en') 
            units_en = f.fetch(999)
            dict_units_en = {}
            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)
                dict_units_en[unit_en.LearningUnitID] = unit_en.Description
            self.session['listEditUnits_en'] = dict_units_en

            # if StatusFilter == 'all':
                # if TopGrpFilter == 'all':
                    # f = LearningUnits.query(LearningUnits.LangCode == 'en') 
                # else:
                    # f = LearningUnits.query(LearningUnits.LangCode == 'en', LearningUnits.Subject == TopGrpFilter)
            # else:
                # if TopGrpFilter == 'all':
                    # f = LearningUnits.query(LearningUnits.LangCode == 'en', LearningUnits.Status == StatusFilter)
                # else:
                    # f = LearningUnits.query(LearningUnits.LangCode == 'en', LearningUnits.Status == StatusFilter, LearningUnits.Subject == TopGrpFilter)
            # units_en = f.fetch(999)
            
            # dict_units_en = {}
            # 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)
                # dict_units_en[unit_en.LearningUnitID] = unit_en.Description

        # unitcnt = 0
        # for uni in units:
            # logging.info('QQQ: uni.LearningUnitID in LearnUnitList: %s' % uni.LearningUnitID)
            # unitcnt = unitcnt + 1
        # logging.info('QQQ: unitcnt in LearnUnitList: %d' % unitcnt)    

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/units' )
        else:
              login = users.create_login_url('/units')

        StatusList = ['Pending Translation', 'Pending Review', 'Published'];

        self.render_template('LearnUnitListEdit.html', {'units': units, 'TopGrpList':TopGrpList, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'TopGrpFilter':TopGrpFilter, 'dict_units_en':dict_units_en, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #23
0
ファイル: Token.py プロジェクト: wmgraham1/NewDemo
    def get(self):
        languages = Languages.all()

        countmap_other_language = {}
        # 		templateName2 = 'khan-exercise'	 and 'templateName', templateName2
        langCode2 = ""
        if self.request.get("langCode"):
            langCode2 = self.request.get("langCode")
        if langCode2 == "en":
            langCode2 = "xx"
        if self.request.get("templateName"):
            templateName2 = self.request.get("templateName")
        if langCode2 != "en":
            q = db.GqlQuery(
                "SELECT * FROM TokenValues " + "WHERE langCode = :1 AND templateName = :2 " + "ORDER BY tknID ASC",
                langCode2,
                templateName2,
            )
            tokens = q.fetch(999)
            #            tokens = TokenValues().all().filter('langCode =', langCode2)
            for token in tokens:
                logging.info("QQQ: token: %s" % token.langCode)
                if token.tknID not in countmap_other_language:
                    countmap_other_language[token.tknID] = 1

        langCode = "en"

        q = db.GqlQuery(
            "SELECT * FROM TokenValues " + "WHERE langCode = :1 AND templateName = :2 " + "ORDER BY tknID ASC",
            langCode,
            templateName2,
        )
        tokens = q.fetch(999)
        #        tokens = TokenValues.all().filter('langCode =', langCode)

        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")

        if langCode2 == "xx":
            self.render_template(
                "TokenStep1.html",
                {
                    "languages": languages,
                    "langCode": langCode,
                    "countmap_other_language": countmap_other_language,
                    "tokens": tokens,
                    "currentuser": currentuser,
                    "login": login,
                    "logout": logout,
                },
            )
        else:
            for token in tokens:
                if token.tknID not in countmap_other_language:
                    n = TokenValues(
                        templateName=token.templateName,
                        langCode=self.request.get("langCode"),
                        tknID=token.tknID,
                        tknValue=token.tknValue,
                        whichuser=users.get_current_user(),
                    )
                    n.put()
            self.render_template(
                "TokenStep1.html",
                {
                    "languages": languages,
                    "langCode": langCode,
                    "countmap_other_language": countmap_other_language,
                    "tokens": tokens,
                    "currentuser": currentuser,
                    "login": login,
                    "logout": logout,
                },
            )
コード例 #24
0
ファイル: LearnUnits.py プロジェクト: alfonsodev/edutrynew
      def get(self):  
        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' 
            langCode = 'en'

        langName = 'no language'
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        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'

        count_en = 0
        langCode_en = 'en'
        q = SubjectAreas.query(SubjectAreas.LangCode == langCode_en)
        units = q.fetch(999)
        for unit in units:
            logging.info('QQQ: count_en: %d' % count_en)
            count_en = count_en + 1
        logging.info('QQQ: Total count_en: %d' % count_en)

        logging.info('QQQ: langCode: %s' % langCode)
        count_other_language = 0
        q2 = SubjectAreas.query(SubjectAreas.LangCode == langCode)
        unitsx = q2.fetch(999)
        for unit in unitsx:
            logging.info('QQQ: count_other_language: %d' % count_other_language)
            count_other_language = count_other_language + 1
        logging.info('QQQ: Total count_other_language: %d' % count_other_language)

        logging.info('GGG: StatusFilter in SubjAreasList: %s' % StatusFilter)
        if StatusFilter == 'all':
            q = SubjectAreas.query(SubjectAreas.LangCode == langCode).order(SubjectAreas.LearningUnitID)
        else:
            q = SubjectAreas.query(SubjectAreas.LangCode == langCode, SubjectAreas.Status == StatusFilter).order(SubjectAreas.LearningUnitID)
        units = q.fetch(999)

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/subjareas' )
        else:
              login = users.create_login_url('/subjareas')

        StatusList = ['Pending Translation', 'Pending Review', 'Published'];

        self.render_template('LearnSubjAreaList.html', {'units': units, 'count_en': count_en, 'count_other_language': count_other_language, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #25
0
    def get(self):
#        UnitSeqRecalc()
#        UnitSubjRecalc()
#        UnitTemplateSync()
        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' 
            langCode = 'en'

        langName = 'no language'
        for language in languages:
            if language.langCode == langCode:
                langName = language.langName

        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('SubjFilter'):
           # SubjFilter=self.request.get('SubjFilter')
           # self.session['SubjFilter'] = SubjFilter
       # else:
           # SubjFilter = self.session.get('SubjFilter')
       # if not SubjFilter:
           # self.session['SubjFilter'] = 'all'
           # SubjFilter = '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'

        count_en = 0
        logging.info('QQQ: Total-Outside-1 unitCount_en: %d' % count_en)
        count_en = self.session.get('unitCount_en')
        logging.info('QQQ: Total-Outside-2 unitCount_en: %d' % count_en)
        if count_en < 1:
            count_en = 0
            langCode_en = 'en'
            q = LearningUnits.query(LearningUnits.LangCode == 'en')
            units = q.fetch(999)
            for unit in units:
    #            logging.info('QQQ: count_en: %d' % count_en)
                count_en = count_en + 1
            logging.info('QQQ: Total unitCount_en: %d' % count_en)
            self.session['unitCount_en'] = 'count_en'
        logging.info('QQQ: Total-Outside-3 unitCount_en: %d' % count_en)

        count_other_language = self.session.get('unitCount_other_language')
        if not count_other_language:
            logging.info('QQQ: unitCount_other_language-langCode: %s' % langCode)
            count_other_language = 0
            q2 = LearningUnits.query(LearningUnits.LangCode == langCode)
            unitsx = q2.fetch(999)
            for unit in unitsx:
    #            logging.info('QQQ: count_other_language: %d' % count_other_language)
                count_other_language = count_other_language + 1
            logging.info('QQQ: Total count_other_language: %d' % count_other_language)
            self.session['unitCount_other_language'] = 'count_other_language'
        logging.info('QQQ: Total-Outside count_other_language: %d' % count_other_language)

        logging.info('LLL: StatusFilter in LearnUnitList: %s' % StatusFilter)
        logging.info('LLL: TopGrpFilter in LearnUnitList: %s' % TopGrpFilter)
        logging.info('LLL: langCode in LearnUnitList: %s' % langCode)
        #TopGrpFilter = 'all'
        #StatusFilter = 'all'
        if StatusFilter == 'all':
            if TopGrpFilter == 'all':
                logging.info('LLL: in LearnUnitList: now in all/all')
                q = LearningUnits.query(LearningUnits.LangCode == 'en').order(LearningUnits.Seq, LearningUnits.LearningUnitID)
            else:
                logging.info('LLL: in LearnUnitList: now in all/TopGrpFilter')
                q = LearningUnits.query(LearningUnits.LangCode == langCode, LearningUnits.Subject == TopGrpFilter).order(LearningUnits.Seq, LearningUnits.LearningUnitID)
        else:
            if TopGrpFilter == 'all':
                logging.info('LLL: in LearnUnitList: now in StatusFilter/all')
                q = LearningUnits.query(LearningUnits.LangCode == langCode, LearningUnits.Status == StatusFilter).order(LearningUnits.Seq, LearningUnits.LearningUnitID)
            else:
                logging.info('LLL: in LearnUnitList: now in StatusFilter/TopGrpFilter')
                q = LearningUnits.query(LearningUnits.LangCode == langCode, LearningUnits.Status == StatusFilter, LearningUnits.Subject == TopGrpFilter).order(LearningUnits.Seq, LearningUnits.LearningUnitID)
#        q = LearningUnits.query(LearningUnits.LangCode == langCode_en, LearningUnits.Subject == 'Math').order(LearningUnits.LearningUnitID)
        logging.info('LLL: q in LearnUnitList: %s' % q)

        units = q.fetch(999)
        # unitcnt = 0
        # for uni in units:
            # logging.info('QQQ: uni.LearningUnitID in LearnUnitList: %s' % uni.LearningUnitID)
            # unitcnt = unitcnt + 1
        # logging.info('QQQ: unitcnt in LearnUnitList: %d' % unitcnt)

        dictTryReadyFiles = {}
        logging.info('GGG: UnitList/dictTryReadyFiles.langCode: %s' % langCode)
        gf = GeneratedFiles.query(GeneratedFiles.LangCode == langCode)
        GenFiles = gf.fetch(999)
        if GenFiles:
            for GenFile in GenFiles:
                if GenFile.TemplateName:
                    logging.info('GGG: UnitList/dictTryReadyFiles.TemplateName: %s' % GenFile.TemplateName)
#                    logging.info('GGG: UnitList/dictTryReadyFiles.FolderName: %s' % GenFile.FolderName)
                    logging.info('GGG: UnitList/dictTryReadyFiles.SearchName: %s' % GenFile.SearchName)
                    dictTryReadyFiles[GenFile.TemplateName] = GenFile.SearchName

        logout = None
        login = None
        currentuser = users.get_current_user()
        if currentuser:
              logout = users.create_logout_url('/units' )
        else:
              login = users.create_login_url('/units')

        StatusList = ['Pending Translation', 'Pending Review', 'Published'];

        self.render_template('LearnUnitList.html', {'units': units, 'count_en': count_en, 'count_other_language': count_other_language, 'StatusList':StatusList, 'StatusFilter':StatusFilter, 'TopGrpFilter':TopGrpFilter, 'dictTryReadyFiles':dictTryReadyFiles, 'languages':languages, 'langCode':langCode, 'langName':langName, 'currentuser':currentuser, 'login':login, 'logout': logout})
コード例 #26
0
    def main(self):

        print("Scraping data for all films...")
        all_films = self.session.query(Films)

        for film in all_films:
            try:
                film_page = self.redirect_to_film_page(film.wiki_href)
                film_data = self.scrape_film_infobox(film_page)
            except Exception as e:
                print(e)
                continue
                
            try:
                # 1. load films_wiki
                film_obj = FilmsWiki(

                    film = film,
                    title = film_data["Title"],
                    released = self.extract_date(film_data["Released"]),
                    running_time = self.extract_runtime(film_data["Running Time"]),
                    budget = self.extract_money(film_data["Budget"]),
                    box_office = self.extract_money(film_data["Box Office"]),
                    )
                
                self.session.add(film_obj)

                # 2. load persons and film_persons

                for role in self.person_roles:
                    if film_data[role]:
                        persons = film_data[role]
                        
                        # if single person, make list
                        if type(persons) != list: 
                            persons = [persons] 

                        for name in persons:
                            try:
                                existing_person = self.session.query(Persons).\
                                                filter_by(full_name=name).one()
                                person_obj = existing_person

                            except Exception:
                                try:
                                    person_obj = Persons(
                                        full_name = name
                                        )
                                    self.session.add(person_obj)
                                    self.session.flush()
                                
                                except Exception:
                                    self.session.rollback()
                                
                            try:
                                film_person_obj = FilmPersons(
                                    film = film_obj,
                                    person = person_obj,
                                    role = role
                                    )
                                self.session.add(film_person_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()


                # 3. load countries and film_counries
                if film_data["Country"]:
                    countries = film_data["Country"]
                    
                    # if single country, make list
                    if type(countries) != list:
                        countries = [countries]

                    for country in countries:
                        try:
                            existing_country = self.session.query(Countries).\
                                            filter_by(country=country).one()
                            country_obj = existing_country

                        except Exception:
                            try:
                                country_obj = Countries(
                                    country = country
                                    )
                                self.session.add(country_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()

                        try:       
                            film_country_obj = FilmCountries(
                                film = film_obj,
                                country = country_obj
                                )
                            self.session.add(film_country_obj)
                            self.session.flush()
                        except Exception:
                            self.session.rollback()

                # 4. load companies and film_companies
                for role in self.company_roles:
                    if film_data[role]:
                        companies = film_data[role]

                        # if single company, make list
                        if type(companies) != list:
                            companies = [companies]

                        for company in companies:
                            try:
                                existing_company = self.session.query(Companies).\
                                                filter_by(company=company).one()
                                company_obj = existing_company
                            
                            except Exception:
                                try:
                                    company_obj = Companies(
                                        company = company
                                        )
                                    self.session.add(company_obj)
                                    self.session.flush()

                                except Exception:
                                    self.session.rollback()
                            try:
                                film_company_obj = FilmCompanies(
                                    film = film_obj,
                                    company = company_obj,
                                    role = role
                                    )
                                self.session.add(film_company_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()

                # 5. load languages and film_languages
                if film_data["Language"]:
                    languages = film_data["Language"]
                    
                    # if single language, make list
                    if type(languages) != list:
                        languages = [languages]

                    for language in languages:
                        try:
                            existing_language = self.session.query(Languages).\
                                                filter_by(language=language).one()
                            language_obj = existing_language

                        except Exception:
                            try:
                                language_obj = Languages(
                                    language = language
                                    )
                                self.session.add(language_obj)
                                self.session.flush()
                            except Exception:
                                self.session.rollback()

                        try:
                            film_language_obj = FilmLanguages(
                                film = film_obj,
                                language = language_obj
                                )
                            self.session.add(film_language_obj)
                            self.session.flush()
                        except Exception:
                            self.session.rollback()

                    print("Collected data for {}".format(film.title))
                    self.session.commit()
            
            except Exception as e:
                print(e)
                continue
コード例 #27
0
from models import User, User_Pers, User_Info, User_Role, Role_Permissions, Status_Types, Languages, Like_Type, Notification_Type

offline = Status_Types(name='Offline', color='#e60b00')
online = Status_Types(name='Online', color='#29f500')

offline.add()
online.add()

language = Languages(name='English', code='en')

language.add()

heart = Like_Type(name="Heart", color="#ff2b2b", icon="heart")

heart.add()

notification_types = [
    Notification_Type(name="follow"),
    Notification_Type(name="like"),
    Notification_Type(name="comment"),
    Notification_Type(name="reply"),
    Notification_Type(name="share"),
    Notification_Type(name="mention")
]

for n in notification_types:
    n.add()

admin_role = User_Role(name="Admin")
admin_role.add()
コード例 #28
0
ファイル: auth.py プロジェクト: Danutu89/NewApp-V2
def register():
    data = request.json

    if data is None or data['username'] is None or data[
            'email'] is None or data['first_name'] is None or data[
                'last_name'] is None or data['password'] is None:
        return jsonify({'register': 'Error'}), 401

    check = User.get().filter_by(name=data['username']).first()

    if check is not None:
        return jsonify({'register': 'Username taken'}), 401

    check = User.get().filter_by(email=data['email']).first()

    if check is not None:
        return jsonify({'register': 'Email taken'}), 401

    token = serializer.dumps(data['email'], salt='register-confirm')

    if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
        userIP = request.environ['REMOTE_ADDR']
    else:
        userIP = request.environ['HTTP_X_FORWARDED_FOR']

    userIP = userIP.split(',')[0]

    if userIP == "127.0.0.1":
        userIP = "86.123.189.180"

    resp = requests.get(
        ('https://www.iplocate.io/api/lookup/{}').format(userIP))
    userLoc = resp.json()
    iso_code = userLoc['country_code']
    api_2 = requests.get(
        ("https://restcountries.eu/rest/v2/alpha/{}").format(iso_code))
    result_2 = api_2.json()

    index = str(db.session.execute(Sequence('users_id_seq')))

    msg = Message('Confirm Email Registration',
                  sender='*****@*****.**',
                  recipients=[data['email']])
    link = 'https://new-app.dev/?email={}&token={}'.format(
        data['email'], token)
    msg.html = render_template('email_register.html',
                               register=link,
                               email='*****@*****.**')
    mail.send(msg)

    check_loc = Ip_Location.get().filter_by(ip=userIP).first()
    check_lang = Languages.get().filter_by(
        code=result_2['languages'][0]['iso639_1']).first()

    os.umask(0)
    os.mkdir(config.get('ROOT_PATH') + '/static/users/' + index)

    if check_loc is None:
        ip_loc_index = str(db.session.execute(Sequence('ip_location_id_seq')))
        loc_index = str(db.session.execute(Sequence('location_id_seq')))

    new_user_json = {
        "id": index,
        "confirmed": False,
        "email": data['email'],
        "info": {
            "avatar_img":
            CreateAvatar({
                "id": index,
                "first_name": data['first_name'],
                "last_name": data['last_name']
            }),
            "user":
            index,
            "first_name":
            data['first_name'],
            "last_name":
            data['last_name']
        },
        "pers": {
            "user": index
        },
        "name": data['username'],
        "role_id": 2,
        "status_id": 2,
        "password": data["password"]
    }

    if check_lang is None:
        new_user_json["language"] = {
            "code": result_2['languages'][0]['iso639_1'],
            "name": result_2['languages'][0]['name'],
        }
    else:
        new_user_json["language"] = NewLanguageSchema().dump(check_lang)

    if check_loc is None:
        new_user_json["location"] = {
            "ip": userIP,
            "id": ip_loc_index,
            "location": {
                "id": loc_index,
                "city": userLoc['city'],
                "country": userLoc['country'],
                "flag": result_2['languages'][0]['iso639_1'],
                "iso": userLoc['country_code'],
                "latitude": str(userLoc['latitude']),
                "longitude": str(userLoc['longitude']),
            }
        }
    else:
        new_user_json["location"] = NewLocationSchema().dump(check_loc)

    new_user = NewUserSchema().load(new_user_json)
    new_user.add()

    return make_response(jsonify({'register': 'success'}), 200)