Exemplo n.º 1
0
def home():
    form = WordForm()
    if form.validate_on_submit():
        word = form.word.data.lower()
        return redirect(url_for("meaning", word=word))

    return render_template("index.html", title="home", form=form)
Exemplo n.º 2
0
def profile_edit_action(request):
	if request.POST:
		form = WordForm(request.POST)
		if form.is_valid():
			messages.success(request, 'Your changes saved successfuly.')
			form.save()
		pass
	else:
		form = WordForm()
	
	return { 'form': form }
Exemplo n.º 3
0
def add_word():
    print(request.method, file=sys.stderr)
    if request.method == 'POST' and request.form:
        print(request.form, file=sys.stderr)
        word = request.form.get('word')
        category = request.form.get('category')
        message = add_single_word(word, category)
        flash(message)
        form = WordForm()
        return render_template('add_word.html', title='Add Word', form=form)
    else:
        form = WordForm()
        return render_template('add_word.html', title='Add Word', form=form)
Exemplo n.º 4
0
def add():
    # Receiving data
    form = WordForm()
    if form.validate_on_submit():
        word = Word(name=form.name.data,
                    explain=form.explain.data,
                    example=form.example.data,
                    created_at=datetime.datetime.utcnow(),
                    updated_at=datetime.datetime.utcnow(),
                    user_id=g.user.id)

        db.session.add(word)
        db.session.commit()
        flash('Word "%s" has been saved.' % form.name.data, 'info')
        return redirect(url_for('add'))

    return render_template('form.html', form=form, title='Add')
Exemplo n.º 5
0
def save_words(request):
	if request.method == 'POST':
		form = WordForm(request.POST)
		if(form.is_valid()) :
			wordsInput = []
			for i in range(1, 11):
				word = form.cleaned_data["word" + str(i)].split()
				if(len(word) > 0):
					wordsInput.append(' '.join(word))
			for wordInput in wordsInput:
				if len(Word.objects.filter(word = wordInput)) == 0:
					wordNew = Word(word = wordInput)
					wordNew.save()
				word = Word.objects.get(word = wordInput)
				if len(UserWord.objects.filter(user = request.user, word = word)) == 0:
					userWordNew = UserWord(user = request.user, word = word)
					userWordNew.save()				
	return HttpResponseRedirect('/words/')
Exemplo n.º 6
0
def add():
    # Receiving data
    form = WordForm()
    if form.validate_on_submit():
        word = Word(name=form.name.data,
                    explain=form.explain.data,
                    example=form.example.data,
                    created_at=datetime.datetime.utcnow(),
                    updated_at=datetime.datetime.utcnow(),
                    user_id=g.user.id)

        db.session.add(word)
        db.session.commit()
        flash('Word "%s" has been saved.' % form.name.data, 'info')
        return redirect(url_for('add'))

    return render_template('form.html',
                           form=form,
                           title='Add')
Exemplo n.º 7
0
def add_titles(request, gameID):
    gameID = int(gameID)
    form = WordForm()
    if request.method == 'POST':
        
        form = WordForm(request.POST)
            
        if form.is_valid() :
            if len(Titles.objects.filter(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92))) > 0 :
                Titles.objects.filter(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92)).delete()
            titlesInput = []
            for i in range(1, 11):
                titlesInput.append(form.cleaned_data["word" + str(i)])
            for title in titlesInput:
                if len(title.split()) == 0:
                    continue
                titleNew = Titles(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92), tourID = -1, title = title)
                titleNew.save()
        message = "Темы добавлены в количестве " + str(len(Titles.objects.filter(gameID = DataGame.objects.get(id = gameID), user = User.objects.get(id = 92))))
    return render_to_response('add_titles.html', locals(), context_instance=RequestContext(request))
Exemplo n.º 8
0
    def post(self):
        self._get_instance()
        form = WordForm(data=self.request.POST, instance=self.instance)
        if form.is_valid():
            entity = form.save(commit=False)
            entity.contributor = users.get_current_user()

            synonyms = self.request.POST.get('synonyms', None)
            if synonyms:
                entity.synonyms = [w.strip() for w in synonyms.split(',')]

            antonyms = self.request.POST.get('antonyms', None)
            if antonyms:
                entity.antonyms = [w.strip() for w in antonyms.split(',')]

            entity.put()
            self.redirect('/input')
        else:
            pass
        html = render('input.html', {'form': form})
        self.response.out.write(html)
Exemplo n.º 9
0
def LookupWord(request):
    template_name = 'form_for_details.html'
    form = WordForm()
    query_dict=request.POST    
    word_to_lookup=query_dict['word']
    if 'groupbysenses' in query_dict:
        group_by_senses=query_dict['groupbysenses']
    else :
        group_by_senses=False
        
    rel_to_look=query_dict.getlist('choices')
    details=words.GetDetails(word_to_lookup,rel_to_look,group_by_senses)
    return render(request, template_name, {'form': form,'details':details,'word':word_to_lookup})
Exemplo n.º 10
0
def edit(word_id):
    word = Word.query.filter_by(id=word_id).first()

    if word == None:
        flash('Word not found. Add a word!', 'info')
        return redirect(url_for('add'))
    elif word.user_id != g.user.id:
        flash('You can\'t edit this word!', 'warning')
        return redirect(url_for('add'))

    form = WordForm(obj=word)
    if form.validate_on_submit():
        word.name = form.name.data
        word.explain = form.explain.data
        word.example = form.example.data
        word.updated_at = datetime.datetime.utcnow()
        db.session.add(word)
        db.session.commit()

    flash('Word "%s" has been modified.' % form.name.data, 'info')
    return render_template('form.html',
                           form=form,
                           title='Edit',
                           word=word.name)
Exemplo n.º 11
0
def save_words(request, task):
	form = WordForm(request.POST)
	if(form.is_valid()) :
		wordsInput = []
		for i in range(1, 11):
			word = form.cleaned_data["word" + str(i)].split()
			if(len(word) > 0):
				wordsInput.append(' '.join(word))
				wordsInput[-1] = wordsInput[-1].lower()
				wordsInput[-1] = wordsInput[-1].replace(u"ё", u"е")
		if len(wordsInput) > 0:
			wordsInputUnique = []
			for i in range(len(wordsInput)):
				if wordsInput[i] not in wordsInput[0:i]:
					wordsInputUnique.append(wordsInput[i])

			wordsPlayer = Words.objects.filter(gameID = task.gameID, tourID = task.tourID, user = request.user).order_by('id')
			wordsPlayer = map(lambda x: x.word, wordsPlayer)
			if wordsPlayer == wordsInputUnique:
				return

			print "before save_words " + str(request.user.id)
			lock = FileLock("/home/senderma/projects/banalnosti/lockSaveWords3")
			with lock:
				currentTime = timezone.now()
				taskNext = Tasks.objects.filter(taskTime__gt = task.taskTime).order_by('taskTime')[0]
				if (taskNext.action == "sendWords")  or ((taskNext.action == "countStatisticsWords") and (taskNext.taskTime > currentTime + datetime.timedelta(seconds = 2))):
					print "in save_words " + str(request.user.id)
					Words.objects.filter(gameID = task.gameID, tourID = task.tourID, user = request.user).delete()
					listAddWords = []
					for word in wordsInputUnique:
						listAddWords.append(Words(gameID = task.gameID, tourID = task.tourID, user = request.user, word = word))
					Words.objects.bulk_create(listAddWords)
					print "out save_words " + str(request.user.id)
				else :
					print str(request.user.id) + u"not save words decause "+ taskNext.action + u" " + str(taskNext.taskTime) + u" | " + str(currentTime) + u" => " + str(currentTime + datetime.timedelta(seconds = 2))
Exemplo n.º 12
0
def edit(word_id):
    word = Word.query.filter_by(id=word_id).first()

    if word == None:
        flash('Word not found. Add a word!', 'info')
        return redirect(url_for('add'))
    elif word.user_id != g.user.id:
        flash('You can\'t edit this word!', 'warning')
        return redirect(url_for('add'))

    form = WordForm(obj=word)
    if form.validate_on_submit():
        word.name = form.name.data
        word.explain = form.explain.data
        word.example = form.example.data
        word.updated_at = datetime.datetime.utcnow()
        db.session.add(word)
        db.session.commit()

    flash('Word "%s" has been modified.' % form.name.data, 'info')
    return render_template('form.html',
                           form=form,
                           title='Edit',
                           word=word.name)
Exemplo n.º 13
0
def upload_file():
    if request.method == 'POST':
        f = request.files['file']
        if not f:
            flash('Please attach a csv file with the words')
            form = WordForm()
            return render_template('add_word.html',
                                   form=form,
                                   title='Add Word')
        category = request.form.get('category')
        print(category, file=sys.stderr)
        filename = '/'.join([UPLOAD_DIR, secure_filename(f.filename)])
        f.save(filename)
        message = add_from_file(filename, category)
        flash(message)
        return render_template('home.html')
Exemplo n.º 14
0
def WordView(request):
    template_name = 'form_for_word.html'
    form = WordForm()
    return render(request, template_name, {'form': form})
Exemplo n.º 15
0
def wordlist(request, project_name):
    project = Project.objects.get(project_name=project_name)
    if request.method == 'POST':
        if 'single' in request.POST:
            form = WordForm(request.POST)
            if form.is_valid():
                word = form.cleaned_data['word']
                word_cn = form.cleaned_data['word_cn']
                source = form.cleaned_data['source']
                introduce = form.cleaned_data['introduce']
                try:
                    w = Word.objects.get(word = word)
                    w.project.add(project)
                    w.save()
                except:
                    w = Word(word = word,
                             word_cn = word_cn,
                             source = source,
                             introduce = introduce,
                             add_time = add_time,
                             )
                    w.save()
                    w.project.add(project)
                    w.save()
                return HttpResponseRedirect('.')
        elif 'macro' in request.POST:
            lines = request.POST['wordtable'].split('\r\n')
            for line in lines:
                if '|' not in line:
                    continue
                elif line.count('|') != 3:
                    continue
                else:
                    l = line.split('|')
                    try:
                        w = Word.objects.get(word = l[0])
                        w.project.add(project)
                        w.save()
                    except:
                        w = Word(word = l[0],
                                 word_cn = l[1],
                                 source = l[2],
                                 introduce = l[3],
                                 add_time = add_time,
                                 )
                        w.save()
                        w.project.add(project)
                        w.save()
            return HttpResponseRedirect('.')
        elif 'del' in request.POST:
            wids = request.POST.getlist('wid')
            wids = [int(wid) for wid in wids]
            Word.objects.filter(id__in=wids).delete()
            return HttpResponseRedirect('.')
    else:
        if request.user.has_perm('projects.%s_member'%project_name):
            perm_project_member = True
        else:
            perm_project_member = False
        wordlist = Word.objects.filter(project=project)
        form = WordForm()
    return render_to_response("wordlist.html",{'wordlist': wordlist, 'form': form, \
                                               'project': project, \
                                               'perm_project_member': perm_project_member},\
                        context_instance=RequestContext(request))
Exemplo n.º 16
0
 def show_word_details(self, word_id):
     word = session.query(self.model).filter_by(id=word_id).first()
     form = WordForm(word=word)
     gc.collect()