Exemple #1
0
def search():
    # TODO: add filter by user
    keyword = request.args.get('keyword')
    start_date = request.args.get('start')
    end_date = request.args.get('end')
    kwargs = dict()
    form = SearchForm(search=keyword, start_date=start_date, end_date=end_date)

    if keyword and not keyword.isspace():
        filters = dict()
        if start_date:
            start_date = datetime.strptime(start_date, '%m/%d/%Y')
            filters['modified_on__gte'] = temp
        if end_date:
            end_date = datetime.strptime(end_date,
                                         '%m/%d/%Y') + timedelta(days=1)
            filters['modified_on__lte'] = temp
        query_set = (WikiPage.objects(**filters).search_text(keyword).only(
            'title', 'modified_on',
            'modified_by').order_by('$text_score', '-modified_on'))

        kwargs = paginate(query_set)

    if form.validate_on_submit():
        return redirect(
            url_for('.search',
                    keyword=form.search.data,
                    start=form.start_date.data,
                    end=form.end_date.data))

    return render_template('wiki/search.html', form=form, **kwargs)
Exemple #2
0
def login_record():
    query_set = WikiLoginRecord.objects
    kwargs = paginate(query_set)
    return render_template('admin/login_records.html', **kwargs)


# TODO: delete page
# TODO: delete file
Exemple #3
0
def changes():
    selected_wiki_user = request.args.get('user')
    wiki_users = WikiUser.objects.distinct('name')
    filters = dict()
    try:
        selected_index = wiki_users.index(selected_wiki_user) + 1
        filters['modified_by'] = selected_wiki_user
    except ValueError:
        selected_index = 0

    query_set = (WikiPage.objects(**filters).only(
        'title', 'modified_on', 'modified_by').order_by('-modified_on'))
    kwargs = paginate(query_set)

    return render_template('wiki/changes.html',
                           wiki_users=wiki_users,
                           selected_index=selected_index,
                           **kwargs)
Exemple #4
0
def all_files():
    query_set = WikiFile.objects.order_by('+id')
    kwargs = paginate(query_set)
    return render_template('admin/all_files.html', **kwargs)
Exemple #5
0
def all_pages():
    fields = ['title', 'modified_on', 'modified_by']
    query_set = WikiPage.objects.only(*fields).order_by('+id')
    kwargs = paginate(query_set)
    return render_template('admin/all_pages.html', **kwargs)