Exemplo n.º 1
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        action = self.request.get('button')
        user = users.get_current_user()

        user_key = ndb.Key('MyUser', user.user_id())
        user_info = user_key.get()

        if action == 'Add':
            original_word = (self.request.get('Word')).lower()

            if not re.match("^[a-z]*$", original_word.lower()):
                message = "Please enter alphabets only"

            else:

                Word = lexi(self.request.get('Word'))
                anagram_key = ndb.Key('Anagram', user.email() + Word)
                anagram = anagram_key.get()
                # & anagram.User != user
                if anagram == None:
                    new_anagram = Anagram(id=user.email() + Word,
                                          AnagramKey=Word)
                    new_anagram.User = user.email()
                    new_anagram.WordList.append(original_word)
                    new_anagram.WordCount = 1
                    new_anagram.LetterCount = len(original_word)
                    new_anagram.put()

                    user_info.myAnagram = user_info.myAnagram + 1
                    user_info.myWordCount = user_info.myWordCount + 1
                    user_info.put()

                    message = "Word added"

                else:
                    flag = False
                    for word in anagram.WordList:
                        if word == original_word:
                            flag = True
                            break
                        else:
                            flag = False

                    if flag:
                        message = "Word already exists"
                    else:
                        # anagram.User=user.email()
                        anagram.WordList.append(original_word)
                        anagram.WordCount = anagram.WordCount + 1
                        anagram.put()
                        message = "Word added"

                        user_info.myWordCount = user_info.myWordCount + 1
                        user_info.put()

            template_values = {'message': message}
            template = JINJA_ENVIRONMENT.get_template('add.html')
            self.response.write(template.render(template_values))
Exemplo n.º 2
0
    def post(self):
        self.response.headers['Content-Type'] = 'text/html'
        action = self.request.get('button')

        user = users.get_current_user()
        myuser_key = ndb.Key('MyUser', user.user_id())
        myuser = myuser_key.get()
        file = self.request.get('myFile')

        if action == 'UPLOAD':

            f = open(file)
            line = f.readline()
            # count = 1
            while line:
                original_word = (line.strip('\n\r')).lower()
                lexi_word = lexi(original_word)

                anagram_key = ndb.Key('Anagram',user.email()+lexi_word)
                anagram = anagram_key.get()
                if anagram == None:
                    new_anagram = Anagram(id=user.email()+lexi_word,AnagramKey=lexi_word)
                    new_anagram.User=user.email()
                    new_anagram.WordList.append(original_word)
                    new_anagram.WordCount = 1
                    new_anagram.LetterCount =  len(original_word)
                    new_anagram.put()

                    myuser.myAnagram = myuser.myAnagram + 1
                    myuser.myWordCount = myuser.myWordCount + 1
                    myuser.put()
                else:
                    flag = False
                    for word in anagram.WordList:
                        if word == original_word:
                            flag = True
                            break
                        else:
                            flag = False

                    if flag:
                        message = "Word already exists"
                    else:
                        # anagram.User=user.email()
                        anagram.WordList.append(original_word)
                        anagram.WordCount = anagram.WordCount + 1
                        anagram.put()
                        # message = "Word added"


                        myuser.myWordCount = myuser.myWordCount + 1
                        myuser.put()

                # count = count + 1
                line = f.readline()

            f.close()

        template_values={
                'message':"File Uploaded"
                }
        template = JINJA_ENVIRONMENT.get_template('upload.html')
        self.response.write(template.render(template_values))