Ejemplo n.º 1
0
def edit_catalog(ctlg_id):
    catalog = CatalogModel.get_by_id(ctlg_id)
    form = CatalogForm(obj=catalog)
    if request.method == "POST":
        if form.validate_on_submit():
            catalog.ctlg_name = form.data.get('ctlg_name')
            catalog.ctlg_desc = form.data.get('ctlg_desc')
            catalog.put()
            flash(u'Catalog %s successfully saved.' % ctlg_id, 'success')
            return redirect(url_for('list_catalogs'))
    return render_template('edit_catalog.html', catalog=catalog, form=form)
Ejemplo n.º 2
0
def edit_catalog(ctlg_id):
    catalog = CatalogModel.get_by_id(ctlg_id)
    form = CatalogForm(obj=catalog)
    if request.method == "POST":
        if form.validate_on_submit():
            catalog.ctlg_name = form.data.get('ctlg_name')
            catalog.ctlg_desc = form.data.get('ctlg_desc')
            catalog.put()
            flash(u'Catalog %s successfully saved.' % ctlg_id, 'success')
            return redirect(url_for('list_catalogs'))
    return render_template('edit_catalog.html', catalog=catalog, form=form)
Ejemplo n.º 3
0
def list_catalogs():
    """List all catalogs"""
    catalogs = CatalogModel.query()
    form = CatalogForm()
    if form.validate_on_submit():
        catalog = CatalogModel(ctlg_name=form.ctlg_name.data,
                               ctlg_desc=form.ctlg_desc.data,
                               ctlg_owner=users.get_current_user())
        try:
            catalog.put()
            ctlg_id = catalog.key.id()
            flash(u'Catalog %s successfully saved.' % ctlg_id, 'success')
            return redirect(url_for('list_catalogs'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.',
                  'info')
            return redirect(url_for('list_catalogs'))
    return render_template('list_catalogs.html', catalogs=catalogs, form=form)
Ejemplo n.º 4
0
def list_catalogs():
    """List all catalogs"""
    catalogs = CatalogModel.query()
    form = CatalogForm()
    if form.validate_on_submit():
        catalog = CatalogModel(
            ctlg_name=form.ctlg_name.data,
            ctlg_desc=form.ctlg_desc.data,
            ctlg_owner=users.get_current_user()
        )
        try:
            catalog.put()
            ctlg_id = catalog.key.id()
            flash(u'Catalog %s successfully saved.' % ctlg_id, 'success')
            return redirect(url_for('list_catalogs'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('list_catalogs'))
    return render_template('list_catalogs.html', catalogs=catalogs, form=form)
Ejemplo n.º 5
0
def statistics(request, catalog=None):
    """
    тип графика
    название графика
    массив название
    массив данных
    подпись по x
    подпись по y
    """
    chart_type = 'column'
    chart_title = u'Название графика'
    row_title = u'Параметр'
    y_title = u'Ось Y'

    statistics = request.GET.get('statistics', 'requests')
    catalogs = []
    if not catalog:
        catalogs += ['sc2', 'ebooks']
    else:
        catalogs.append(catalog)
    # catalogs = ZCatalog.objects.all()
    start_date = datetime.datetime.now()
    end_date = datetime.datetime.now()
    date_group = u'2'  # группировка по дням
    attributes = []

    period_form = PeriodForm()
    group_form = GroupForm()
    attributes_form = AttributesForm()
    catalog_form = CatalogForm()
    if request.method == 'POST':
        period_form = PeriodForm(request.POST)
        group_form = GroupForm(request.POST)
        attributes_form = AttributesForm(request.POST)
        catalog_form = CatalogForm(request.POST)

        if period_form.is_valid():
            start_date = period_form.cleaned_data['start_date']
            end_date = period_form.cleaned_data['end_date']

        if group_form.is_valid():
            date_group = group_form.cleaned_data['group']

        if attributes_form.is_valid():
            attributes = attributes_form.cleaned_data['attributes']

        if catalog_form.is_valid():
            catalogs = catalog_form.cleaned_data['catalogs']

    if statistics == 'requests':
        attributes_form = None
        rows = requests_count(
            start_date=start_date,
            end_date=end_date,
            group=date_group,
            catalogs=catalogs
        )
        chart_title = u'Число поисковых запросов по дате'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'

    elif statistics == 'attributes':
        group_form = None
        rows = requests_by_attributes(
            start_date=start_date,
            end_date=end_date,
            attributes=attributes,
            catalogs=catalogs
        )

        chart_title = u'Число поисковых запросов по поисковым атрибутам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'

    elif statistics == 'terms':
        group_form = None
        rows = requests_by_term(
            start_date=start_date,
            end_date=end_date,
            attributes=attributes,
            catalogs=catalogs
        )

        chart_title = u'Число поисковых запросов по фразам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'
    else:
        return HttpResponse(u'Неправильный тип статистики')

    data_rows = json.dumps(rows, ensure_ascii=False)

    return render(request, 'ssearch/administration/statistics.html', {
        'data_rows': data_rows,
        'catalog_form': catalog_form,
        'period_form': period_form,
        'group_form': group_form,
        'attributes_form': attributes_form,
        'chart_type': chart_type,
        'chart_title': chart_title,
        'y_title': y_title,
        'row_title': row_title,
        'active_module': 'zgate'
    })
Ejemplo n.º 6
0
def statistics(request, catalog=None):
    """
    тип графика
    название графика
    массив название
    массив данных
    подпись по x
    подпись по y
    """
    chart_type = 'column'
    chart_title = u'Название графика'
    row_title = u'Параметр'
    y_title = u'Ось Y'

    statistics = request.GET.get('statistics', 'requests')
    catalogs = []
    if not catalog:
        catalogs += ['sc2', 'ebooks']
    else:
        catalogs.append(catalog)
    # catalogs = ZCatalog.objects.all()
    start_date = datetime.datetime.now()
    end_date = datetime.datetime.now()
    date_group = u'2'  # группировка по дням
    attributes = []

    period_form = PeriodForm()
    group_form = GroupForm()
    attributes_form = AttributesForm()
    catalog_form = CatalogForm()
    if request.method == 'POST':
        period_form = PeriodForm(request.POST)
        group_form = GroupForm(request.POST)
        attributes_form = AttributesForm(request.POST)
        catalog_form = CatalogForm(request.POST)

        if period_form.is_valid():
            start_date = period_form.cleaned_data['start_date']
            end_date = period_form.cleaned_data['end_date']

        if group_form.is_valid():
            date_group = group_form.cleaned_data['group']

        if attributes_form.is_valid():
            attributes = attributes_form.cleaned_data['attributes']

        if catalog_form.is_valid():
            catalogs = catalog_form.cleaned_data['catalogs']

    if statistics == 'requests':
        attributes_form = None
        rows = requests_count(
            start_date=start_date,
            end_date=end_date,
            group=date_group,
            catalogs=catalogs
        )
        chart_title = u'Число поисковых запросов по дате'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'

    elif statistics == 'attributes':
        group_form = None
        rows = requests_by_attributes(
            start_date=start_date,
            end_date=end_date,
            attributes=attributes,
            catalogs=catalogs
        )

        chart_title = u'Число поисковых запросов по поисковым атрибутам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'

    elif statistics == 'terms':
        group_form = None
        rows = requests_by_term(
            start_date=start_date,
            end_date=end_date,
            attributes=attributes,
            catalogs=catalogs
        )

        chart_title = u'Число поисковых запросов по фразам'
        row_title = u'Число поисковых запросов'
        y_title = u'Число поисковых запросов'
        chart_type = 'bar'
    else:
        return HttpResponse(u'Неправильный тип статистики')

    data_rows = json.dumps(rows, ensure_ascii=False)

    return render(request, 'ssearch/administration/statistics.html', {
        'data_rows': data_rows,
        'catalog_form': catalog_form,
        'period_form': period_form,
        'group_form': group_form,
        'attributes_form': attributes_form,
        'chart_type': chart_type,
        'chart_title': chart_title,
        'y_title': y_title,
        'row_title': row_title,
        'active_module': 'zgate'
    })