Ejemplo n.º 1
0
    def add_word(self, request):
        """Add word to list of words
        Args:
            The WordForm objects which include a 'word'

        Returns:
            StringMessage: confirming the 'word' has been added as an entity
            to the Word model

        Raises:
            endpoints.BadRequestException: if the word is not a single word or
            contains special characters and numbers.
        """
        if Word.query(Word.word == request.word).get():
            raise endpoints.ConflictException('That word is in the list!')
        else:
            word_list = []
            temp = request.word.upper()
            for i in temp:
                if i == " " or i < 'A' or i > 'Z':
                    raise endpoints.BadRequestException(
                        'Please Enter One Word!')
                else:
                    word_list.append(i)
            w = Word(word=request.word, word_list=word_list)
            w.put()
        return StringMessage(message='Added %s to the list!' % request.word)
Ejemplo n.º 2
0
 def new_game(self, request):
     """Creates new game"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     word = Word.query(Word.word_to_guess == request.word).get()
     if not word:
         word = Word(word_to_guess=request.word)
         word.put()
     try:
         game = Game.new_game(user.key, word.key.urlsafe())
         return game.to_form('Good luck playing Hangman!')
     except:
         raise
Ejemplo n.º 3
0
 def new_game(self, request):
     """Creates new game"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
                 'A User with that name does not exist!')
     word = Word.query(Word.word_to_guess == request.word).get()
     if not word:
         word = Word(word_to_guess=request.word)
         word.put()
     try:
         game = Game.new_game(user.key,
                              word.key.urlsafe())
         return game.to_form('Good luck playing Hangman!')
     except:
         raise
Ejemplo n.º 4
0
    def post(self):

        if request.form.get('add_index', None):
            list_title = request.form['list_name']
            order = (WordList.query().count() + 1) * 10

            lst = WordList(order=order, title=str(list_title))
            lst.put()

        elif request.form.get('add_word', None):
            key = ndb.Key(WordList, int(request.form['index_key']))
            word_name = str(request.form['word_name'])
            words_count = Word.query().filter(Word.list == key).count() + 1

            w = Word(list=key, word=word_name, order=words_count * 2)
            w.put()

        return self.get()