Пример #1
0
    def get(self):

        template_values = {
            'user': users.get_current_user(),
            'admin': users.is_current_user_admin(),
            'date_string': datetime.now().ctime(),
            'url': users.create_logout_url(self.request.host_url),
            'link_text': 'logout',
        }

        if self.request.get("word"):
            word = vocabulary_word.all().filter(
                "word =", self.request.get("word")).get()
            template_values['word'] = word

            template_values['related_kanji_list'] = []
            for entry in kanji_entry.get(word.related_kanji):
                template_values['related_kanji_list'].append(entry.kanji)

            if not template_values['word']:
                template_values['message'] = 'no word found'

            next_page = 'template/vocab.html'

        else:
            search_string = self.request.get('search_string')

            # setup paged query
            if search_string:
                template_values['search_string'] = search_string
                vocab_query = PagedQuery(
                    vocabulary_word.all().order('modified').filter(
                        'word =', search_string), PAGESIZE)
            else:
                vocab_query = PagedQuery(
                    vocabulary_word.all().order('modified'), PAGESIZE)

            # retreive requested page number, defaulting to page 1
            bookmark = self.request.get('bookmark')
            if bookmark:
                bookmark = int(bookmark)
            else:
                bookmark = 1
            logging.info('bookmark=' + str(bookmark))

            template_values['bookmark'] = str(bookmark)
            template_values['vocab_list'] = vocab_query.fetch_page(bookmark)
            template_values['page_links'] = PageLinks(
                page=bookmark,
                page_count=vocab_query.page_count(),
                url_root="/vocab",
                page_field="bookmark",
                page_range=10).get_links()

            next_page = 'template/vocablist.html'

        path = os.path.join(os.path.dirname(__file__), next_page)
        self.response.out.write(template.render(path, template_values))
Пример #2
0
    def get(self):

        template_values = {
            "user": users.get_current_user(),
            "admin": users.is_current_user_admin(),
            "date_string": datetime.now().ctime(),
            "url": users.create_logout_url(self.request.host_url),
            "link_text": "logout",
        }

        if self.request.get("word"):
            word = vocabulary_word.all().filter("word =", self.request.get("word")).get()
            template_values["word"] = word

            template_values["related_kanji_list"] = []
            for entry in kanji_entry.get(word.related_kanji):
                template_values["related_kanji_list"].append(entry.kanji)

            if not template_values["word"]:
                template_values["message"] = "no word found"

            next_page = "template/vocab.html"

        else:
            search_string = self.request.get("search_string")

            # setup paged query
            if search_string:
                template_values["search_string"] = search_string
                vocab_query = PagedQuery(
                    vocabulary_word.all().order("modified").filter("word =", search_string), PAGESIZE
                )
            else:
                vocab_query = PagedQuery(vocabulary_word.all().order("modified"), PAGESIZE)

            # retreive requested page number, defaulting to page 1
            bookmark = self.request.get("bookmark")
            if bookmark:
                bookmark = int(bookmark)
            else:
                bookmark = 1
            logging.info("bookmark=" + str(bookmark))

            template_values["bookmark"] = str(bookmark)
            template_values["vocab_list"] = vocab_query.fetch_page(bookmark)
            template_values["page_links"] = PageLinks(
                page=bookmark,
                page_count=vocab_query.page_count(),
                url_root="/vocab",
                page_field="bookmark",
                page_range=10,
            ).get_links()

            next_page = "template/vocablist.html"

        path = os.path.join(os.path.dirname(__file__), next_page)
        self.response.out.write(template.render(path, template_values))
Пример #3
0
    def get( self ):
        # supported actions: get, getkanji, update, validate

        words = []

        template_values = {
            'timestamp': time.mktime( datetime.utcnow().timetuple() ),
            'count': 0,
        }

        word_query = vocabulary_word.all()
        for word in word_query:
            words.append( word )

        if words:
            template_values['words'] = words
            template_values['count'] = len( words )

        next_page = 'template/vocabfeed.xml'

        path = os.path.join( os.path.dirname( __file__ ), next_page )
        self.response.out.write( template.render( path, template_values ) )
Пример #4
0
    def get(self):
        # supported actions: get, getkanji, update, validate

        words = []

        template_values = {
            'timestamp': time.mktime(datetime.utcnow().timetuple()),
            'count': 0,
        }

        word_query = vocabulary_word.all()
        for word in word_query:
            words.append(word)

        if words:
            template_values['words'] = words
            template_values['count'] = len(words)

        next_page = 'template/vocabfeed.xml'

        path = os.path.join(os.path.dirname(__file__), next_page)
        self.response.out.write(template.render(path, template_values))
Пример #5
0
    def get(self):
        # supported actions: get, getkanji, update, validate
        
        action = self.request.get('action')
        logging.info('feed accessed, action: ' + action)

        words = []

        template_values = {
            'action': action,
            'timestamp': time.mktime(datetime.utcnow().timetuple()),
            'count': 0,
        }
       
        if not action:
            message = 'feed request missing parameter: \'action\''
            logging.error(message)
            template_values['message'] = message
            
        elif action == 'get':
                        
            try:
                kanji_index = int(self.request.get('kanji_index'))
            except:
                message = 'feed request missing or invalid parameter: kanji_index=%s' \
                    % (self.request.get('kanji_index'))
                logging.error(message)
                template_values['message'] = message
                kanji_index = None

            try:
                kanji_count = int(self.request.get('kanji_count'))
            except:
                message = 'feed request missing or invalid parameter: kanji_count=%s' \
                    % (self.request.get('kanji_count'))
                logging.error(message)
                template_values['message'] = message
                kanji_count = None
                    
            logging.info('action: %s, kanji_index: %s, kanji_count: %s' \
                % (action, kanji_index, kanji_count))
                    
            if kanji_index and kanji_count:
                word_query = vocabulary_word.all()
                word_query.order('kanji_index')
                word_query.filter('kanji_index >', kanji_index - 1)
                word_query.filter('kanji_index <', kanji_index + kanji_count)
                for word in word_query:
                    words.append(word)
                    
        elif action == 'update':

            try:
                kanji_index = int(self.request.get('kanji_index'))
            except:
                message = 'feed request missing or invalid parameter: kanji_index=%s' \
                    % (self.request.get('kanji_index'))
                logging.error(message)
                template_values['message'] = message
                kanji_index = None
            
            try:
                since = datetime.fromtimestamp(float(self.request.get('since')))
            except:
                message = 'feed request missing or invalid parameter: since=%s' \
                    % (self.request.get('since'))
                logging.error(message)
                template_values['message'] = message
                since = None

            logging.info('action: %s, id: %s, since: %s' % (action, kanji_index, since))

            if kanji_index and since:
                word_query = vocabulary_word.all()
                word_query.filter('modified >=', since)
                for word in word_query:
                    if word.kanji_index <= kanji_index:
                        words.append(word)

        elif action == 'validate':

            try:
                kanji_index = int(self.request.get('kanji_index'))
            except:
                message = 'feed request missing or invalid parameter: kanji_index=%s' \
                    % (self.request.get('kanji_index'))
                logging.error(message)
                template_values['message'] = message
                kanji_index = None

            logging.info('action: %s, id: %s' % (action, kanji_index))

            if kanji_index:
                word_query = vocabulary_word.all()
                word_query.order('kanji_index')
                word_query.filter('kanji_index <=', kanji_index)
                for word in word_query:
                    words.append(word)

        else:
            message = 'unsupported action request: ' + action
            logging.error(message)
            template_values['message'] = message

        if words:
            template_values['words'] = words
            template_values['count'] = len(words)
       
        next_page = 'template/feed.xml'
            
        path = os.path.join(os.path.dirname(__file__), next_page)
        self.response.out.write(template.render(path, template_values))
Пример #6
0
    def post( self ):

        new_words = []
        existing_words = []
        data = get_system_data()

        template_values = {
            'timestamp': time.mktime( datetime.utcnow().timetuple() ),
            'count': 0,
        }

        word_query = vocabulary_word.all()
        for word in word_query:
            existing_words.append( word )

        new_word = self.request.get( 'word' )

        if new_word:
            # retrieve existing record if any or create new record
            vocab_query = vocabulary_word.all()
            vocab_query.filter( "word =", new_word )
            vocab = vocab_query.get()

            is_new_word = False

            if not vocab:
                vocab = vocabulary_word( word = new_word )
                is_new_word = True

            # insert any new readings and meanings
            new_readings = self.request.get_all( 'reading' )
            for new_reading in new_readings:
                new_reading = new_reading.strip()
                if new_reading and not new_reading in vocab.readings:
                    vocab.readings.append( new_reading )

            new_meanings = self.request.get_all( 'meaning' )
            for new_meaning in new_meanings:
                new_meaning = new_meaning.strip()
                if new_meaning and not new_meaning in vocab.meanings:
                    vocab.meanings.append( new_meaning )

            # link related kanji
            for related_kanji in self.request.get_all( 'kanji' ):
                logging.info( "adding kanji '%s'" % related_kanji )
                try:
                    kanji_query = kanji_entry.all()
                    kanji_query.filter( "kanji =", related_kanji )
                    related_kanji_entry = kanji_query.get()
                    if related_kanji_entry:
                        vocab.related_kanji.append( related_kanji_entry.key() )

                    if related_kanji_entry.kanji_index > vocab.max_kanji_index:
                        vocab.max_kanji_index = related_kanji_entry.kanji_index

                except:
                    logging.error( "failed to add related kanji %s" % related_kanji )

            vocab = vocabulary_word.get( vocab.put() )

            if is_new_word:
                data.word_count = data.word_count + 1
                data.put()

            message = "new word '%s' created" % ( vocab.word )

            new_words.append( vocab )

        template_values['message'] = message

        if new_words:
            template_values['words'] = new_words
            template_values['count'] = len( new_words )

        next_page = 'template/vocabfeed.xml'

        path = os.path.join( os.path.dirname( __file__ ), next_page )
        self.response.out.write( template.render( path, template_values ) )
Пример #7
0
    def post(self):

        new_words = []
        existing_words = []
        data = get_system_data()

        template_values = {
            'timestamp': time.mktime(datetime.utcnow().timetuple()),
            'count': 0,
        }

        word_query = vocabulary_word.all()
        for word in word_query:
            existing_words.append(word)

        new_word = self.request.get('word')

        if new_word:
            # retrieve existing record if any or create new record
            vocab_query = vocabulary_word.all()
            vocab_query.filter("word =", new_word)
            vocab = vocab_query.get()

            is_new_word = False

            if not vocab:
                vocab = vocabulary_word(word=new_word)
                is_new_word = True

            # insert any new readings and meanings
            new_readings = self.request.get_all('reading')
            for new_reading in new_readings:
                new_reading = new_reading.strip()
                if new_reading and not new_reading in vocab.readings:
                    vocab.readings.append(new_reading)

            new_meanings = self.request.get_all('meaning')
            for new_meaning in new_meanings:
                new_meaning = new_meaning.strip()
                if new_meaning and not new_meaning in vocab.meanings:
                    vocab.meanings.append(new_meaning)

            # link related kanji
            for related_kanji in self.request.get_all('kanji'):
                logging.info("adding kanji '%s'" % related_kanji)
                try:
                    kanji_query = kanji_entry.all()
                    kanji_query.filter("kanji =", related_kanji)
                    related_kanji_entry = kanji_query.get()
                    if related_kanji_entry:
                        vocab.related_kanji.append(related_kanji_entry.key())

                    if related_kanji_entry.kanji_index > vocab.max_kanji_index:
                        vocab.max_kanji_index = related_kanji_entry.kanji_index

                except:
                    logging.error("failed to add related kanji %s" %
                                  related_kanji)

            vocab = vocabulary_word.get(vocab.put())

            if is_new_word:
                data.word_count = data.word_count + 1
                data.put()

            message = "new word '%s' created" % (vocab.word)

            new_words.append(vocab)

        template_values['message'] = message

        if new_words:
            template_values['words'] = new_words
            template_values['count'] = len(new_words)

        next_page = 'template/vocabfeed.xml'

        path = os.path.join(os.path.dirname(__file__), next_page)
        self.response.out.write(template.render(path, template_values))