示例#1
0
文件: views.py 项目: PuercoPop/qchaes
def random():
    word = Entry.get_random()

    # Test if an entry was returned
    if word:
        word = word['slug']
        return redirect(url_for('qchar', word=word))
    else:
        return ""
示例#2
0
def define(slug):
    captcha = {'ip_address': request.remote_addr}
    form = DefinitionForm(request.form, captcha=captcha)
    if slug != 'x':
        form.entry.data = slug.replace('_', ' ')

    if request.method == 'POST' and form.validate():
        #Check if entry exists previously
        slug = slugEncode(form.entry.data).lower()
        try:
            entry = Entry.objects.get(slug=slug)
        except Entry.DoesNotExist:
            entry = Entry(name=form.entry.data)
        d = Definition(content=form.definition.data, example=form.example.data)
        d.save()
        entry.definitions.append(d)
        entry.save()
        return redirect(url_for('qchar', word=slug))
    return render_template('new_definition.html', form=form)
示例#3
0
def main():
    samples = []

    for i in range(3):
        e = Entry.objects.get(slug=Entry.get_random()['slug'])
        samples.append({'name': e.name, 'definition': e.get_hero()})

    return render_template('main.html',
                           letters=[x for x in uppercase],
                           samples=samples)
示例#4
0
文件: views.py 项目: ivoscc/qchaes
def define(slug):
    captcha = {'ip_address': request.remote_addr}
    form = DefinitionForm(request.form, captcha=captcha)
    if slug != 'x':
        form.entry.data = slug.replace('_', ' ')

    if request.method == 'POST' and form.validate():
        #Check if entry exists previously
        slug = slugEncode(form.entry.data).lower()
        try:
            entry = Entry.objects.get(slug=slug)
        except Entry.DoesNotExist:
            entry = Entry(name=form.entry.data)
        d = Definition(content=form.definition.data, example=form.example.data)
        d.save()
        entry.definitions.append(d)
        entry.save()
        return redirect(url_for('qchar', word=slug))
    return render_template('new_definition.html', form=form)
示例#5
0
文件: views.py 项目: ivoscc/qchaes
def main():
    samples = []

    for i in range(3):
        e = Entry.objects.get(slug=Entry.get_random()['slug'])
        samples.append({'name': e.name, 'definition': e.get_hero()})

    return render_template(
            'main.html',
            letters=[x for x in uppercase],
            samples=samples
        )
示例#6
0
文件: views.py 项目: ivoscc/qchaes
def search(page=0):
    id_list = Entry.search(''.join(request.args['b']))
    count = len(id_list) / settings.PAGE_SIZE + 1
    if page >= count:
        page = count - 1

    r = []
    for i in id_list[page * settings.PAGE_SIZE: settings.PAGE_SIZE * (page + 1)]:
        r.append(Entry.objects.get(id=i))

    paginator = Paginator(page, count)

    return render_template('results.html', results=r, paginator=paginator)
示例#7
0
def search(page=0):
    id_list = Entry.search(''.join(request.args['b']))
    count = len(id_list) / settings.PAGE_SIZE + 1
    if page >= count:
        page = count - 1

    r = []
    for i in id_list[page * settings.PAGE_SIZE:settings.PAGE_SIZE *
                     (page + 1)]:
        r.append(Entry.objects.get(id=i))

    paginator = Paginator(page, count)

    return render_template('results.html', results=r, paginator=paginator)
示例#8
0
文件: views.py 项目: PuercoPop/qchaes
def main():
    """
    Presents main Page
    With 3 random words on the front page if DB has more than 3 words.
    """
    samples = []

    for i in range(3):
        #e = Entry.objects.get(slug=Entry.get_random()['slug'])
        entry = Entry.get_random()
        if entry:
            samples.append({'name': entry.name, 'definition': entry.get_hero()})

    return render_template(
            'main.html',
            letters=[x for x in uppercase],
            samples=samples
        )
示例#9
0
def random():
    word = Entry.get_random()['slug']
    return redirect(url_for('qchar', word=word))
示例#10
0
                     (page + 1)]:
        r.append(Entry.objects.get(id=i))

    paginator = Paginator(page, count)

    return render_template('results.html', results=r, paginator=paginator)


@app.route('/buscar/top/')
def searchbox():
    term = request.args['term']
    if not re.match(ur"^[a-zA-Z0-9\s_áéíóúÁÉÍÓÚñÑ]+$", term):
        return ""
    term = term.encode('translit/long')
    if len(term) >= 1:
        return simplejson.dumps(Entry.search_terms(term))
    else:
        return ""


"""
# make apache handle it later on
@app.errorhandler(404)
def page_not_found(error):
        return render_template('404.html'), 404


@app.errorhandler(500)
def page_not_found(error):
        return render_template('404.html'), 500
"""
示例#11
0
文件: views.py 项目: ivoscc/qchaes
def random():
    word = Entry.get_random()['slug']
    return redirect(url_for('qchar', word=word))
示例#12
0
文件: views.py 项目: ivoscc/qchaes
    for i in id_list[page * settings.PAGE_SIZE: settings.PAGE_SIZE * (page + 1)]:
        r.append(Entry.objects.get(id=i))

    paginator = Paginator(page, count)

    return render_template('results.html', results=r, paginator=paginator)


@app.route('/buscar/top/')
def searchbox():
    term = request.args['term']
    if not re.match(ur"^[a-zA-Z0-9\s_áéíóúÁÉÍÓÚñÑ]+$", term):
        return ""
    term = term.encode('translit/long')
    if len(term) >= 1:
        return simplejson.dumps(Entry.search_terms(term))
    else:
        return ""

"""
# make apache handle it later on
@app.errorhandler(404)
def page_not_found(error):
        return render_template('404.html'), 404


@app.errorhandler(500)
def page_not_found(error):
        return render_template('404.html'), 500
"""