def add_anagram(self, anagram_word, user_id): try: anagram_list = list() for word in itertools.permutations(anagram_word): anagram_list.append("".join(word)) sorted_word = "".join(sorted(anagram_word)) sorted_key = str(user_id) + "/" + sorted_word anagram_details = Anagram(word=anagram_word, user_key = sorted_key, sorted_word=sorted_word, user_id=user_id, word_count=1, letter_count=len(sorted_word)) anagram_details.put() except Exception as ex: return False
def post(self): user = users.get_current_user() anagram_list = list() present = False template_values = dict() if users.get_current_user(): user_id = users.get_current_user().user_id() if self.request.POST.has_key('button'): a_word = sorted(self.request.POST['word']) anagram_word = ''.join([i for i in a_word if not i.isdigit()and i.isalnum()]) anagram_data = Anagram.query(Anagram.user_id==user_id and Anagram.sorted_word==anagram_word).fetch() if len(anagram_data) == 0: present = False else: present = True for word in itertools.permutations(anagram_word): anagram_list.append("".join(word)) template_values = { 'word' : self.request.POST['word'], 'anagram_word' : len(self.request.POST['word']), 'anagram_count' : len(anagram_list), 'anagram_list': anagram_list, 'present' : present, 'user': user, 'anagram_data' : anagram_data } else: template_values = {'error' : "Please login first", 'user': user } template = JINJA_ENVIRONMENT.get_template('templates/search.html') self.response.write(template.render(template_values))
def post(self): anagram_list = list() user = users.get_current_user() if users.get_current_user(): user_id = users.get_current_user().user_id() user_anagram_data = Anagram.query(Anagram.user_id == user_id).fetch() if self.request.POST.has_key('button'): if self.request.POST.has_key('word'): a_word = self.request.POST['word'] anagram_word = ''.join([i for i in a_word if not i.isdigit() and i.isalnum()]) anagram_word = anagram_word.lower() anagram_data = Anagram.query(Anagram.user_id == user_id, Anagram.sorted_word == "".join(sorted(anagram_word))).fetch() if len(anagram_data) == 0: self.add_anagram(anagram_word, user_id) else: self.increment_anagram_count(anagram_data, anagram_word) elif self.request.POST.has_key('afile'): file_storage = self.request.POST.get('afile') file_data = file_storage.file.read() words = file_data.split('\n') for a_word in words: word = ''.join([i for i in a_word if not i.isdigit() and i.isalnum()]) word = word.lower() if len(word) > 0: anagram_data = Anagram.query(Anagram.user_id == user_id, Anagram.sorted_word == "".join(sorted(word))).fetch() if len(anagram_data) == 0: self.add_anagram(word, user_id) else: self.increment_anagram_count(anagram_data, word) template_values = { 'user': user, 'anagram_data': user_anagram_data } else: template_values = { 'error' : "Please login first", 'user': user } template = JINJA_ENVIRONMENT.get_template('templates/main.html') self.response.write(template.render(template_values))
def get(self): user = users.get_current_user() # template_values= dict() # import pdb;pdb.set_trace() if self.request.GET.has_key('add'): user_id = users.get_current_user().user_id() user_anagram_data = Anagram.query(Anagram.user_id == user_id).fetch() template_values = { 'user': user, 'anagram_data': user_anagram_data } template = JINJA_ENVIRONMENT.get_template('templates/add.html') self.response.write(template.render(template_values))
def post(self): if users.get_current_user(): user = users.get_current_user() user_id = users.get_current_user().user_id() anagram_data = Anagram.query(Anagram.user_id==user_id).fetch() template_values = { 'user': user, 'anagram_data': anagram_data } else: template_values ={ 'error': "please login first" } template = JINJA_ENVIRONMENT.get_template('templates/show.html') self.response.write(template.render(template_values))