コード例 #1
0
ファイル: query.py プロジェクト: multiple1902/repartee
def queryHome(request):
    if request.method == "POST":
        # display query.query.html which includes queryResult.inc.html
        queryForm = QueryForm(request.POST)

        print queryForm.is_valid()
        queryID = md5.new(str(queryForm.cleaned_data)).hexdigest()

        if "queries" not in request.session:
            request.session["queries"] = {}

        request.session["queries"][queryID] = queryForm

        flows = Flow.objects.filter(getQFromQueryForm(queryForm))

        return render_to_response("query.query.html", {
                'queryForm': queryForm,
                'queryID': queryID,
                'resultsCount': len(flows),
            }, context_instance = RequestContext(request))

    else:
        # display query.home.html
        queryForm = QueryForm()
        return render_to_response("query.home.html", {
                'queryForm': queryForm,
            }, context_instance = RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: kaji-project/rekishi
def index(request):
    if request.method == 'GET':
        form = QueryForm()
        return render(request, 'builder/index.html', {
            'form': form,
        })
        # Render Form
    elif request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            print form.cleaned_data
            
            query = 'SELECT %s FROM %s.%s.%s;' % (
                    form.cleaned_data['field'],
                    form.cleaned_data['host'], 
                    form.cleaned_data['service'], 
                    form.cleaned_data['series']
                )
            data = db.query(query)
            data = influxdb_dataset(data)
            ret_value = json.dumps([series.to_dygraph() for series in data], indent=2)

            return render(request, 'api/basicgraph.html', {
                'data': ret_value,
                'query': query
            })
コード例 #3
0
def query_editor(request, query_id=None):
    form = QueryForm(request.POST) if request.method == 'POST' else QueryForm()
    query = None
    if query_id is not None:
        try:
            query = Query.objects.get(id=query_id)
        except:
            pass
        if not query:
            return HttpResponseRedirect("/sql_dashboards/query/")
    if request.method == "GET" and query_id is not None:
        form = QueryForm(instance=query)
    elif request.method == "POST" and ("run" in request.POST or "save" in request.POST or "run_save" in request.POST):
        form = QueryForm(request.POST, instance=query) if query else QueryForm(request.POST)
        if form.is_valid():
            query = form.save(commit=("save" in request.POST or "run_save" in request.POST), user=request.user)

        if query and ("run" in request.POST or "run_save" in request.POST):
            query_executed = True
            print(request.POST.keys())
            custom_data = dict([(k, v.initial) for k, v in CustomQueryForm(query).fields.items()]) if query.custom else None
            query.getAll(custom_data=custom_data)
    if request.method == "POST" and "save" in request.POST:
        return HttpResponseRedirect("/sql_dashboards/query/edit/%s" % query.id)
    return render_to_response("django_sql_dashboards/query_editor.html", locals(), RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: tOkeshu/memopol2
def query(request):
    form = QueryForm(request.GET)
    if not form.is_valid():
        return render_to_response('query.html')
    key=[]
    for fltr in ['commitee_filter', 'political_filter', 'country_filter']:
        val=form.cleaned_data.get(fltr)
        if val: key.append(val)
    meps = MEP.view('meps/query', startkey=key)
    return render_to_response('query.html', { 'meps': meps})
コード例 #5
0
def query_new(request):
    if request.method == "POST":
        form = QueryForm(request.POST.copy())
        if form.is_valid():
            query = form.save(commit=False)
            query.user = request.user
            query.save()
            return redirect('pred_list')
    else:
        form = QueryForm()
    return render(request, 'deep_stylo/query_edit.html', {'form': form})
コード例 #6
0
ファイル: views.py プロジェクト: gr/Btools
def query(request, **kwargs):
    if request.method == 'GET' and len(request.GET) > 0:
        form = QueryForm(request.GET)
        if form.is_valid(): 
            db=form.cleaned_data['db']
            db.encoding_in = form.cleaned_data['charset_in']
            db.encoding_out = form.cleaned_data['charset_out']
            db.syntax = form.cleaned_data['syntax']
            books = db.query(form.cleaned_data['query_type'], form.cleaned_data['query'])
            b_len = len(books)
    else:
        form = QueryForm()
    return render_to_response(kwargs['tpl'], locals())
コード例 #7
0
ファイル: views.py プロジェクト: Bouska/memopol2
def query(request):
    form = QueryForm(request.GET)
    if not form.is_valid():
        return render_to_response('query.html')
    key=[]
    #for fltr in ('commitee_filter', 'group_filter', 'country_filter'):
    #    val=form.cleaned_data.get(fltr)
    #    if val: key.append(val)
    key=[form.cleaned_data.get('country_filter') or u'DE',
         form.cleaned_data.get('group_filter') or u'PPE',
         form.cleaned_data.get('commitee_filter',None)]
    print key
    meps = MEP.view('meps/query', key=key)
    return render_to_response('query.html', { 'meps': meps})
コード例 #8
0
ファイル: views.py プロジェクト: csvenja/coursys
def new_query(request, report):
    report = get_object_or_404(Report, slug=report) 

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            messages.success(request, "Created new report query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm()

    return render(request, 'reports/new_query.html', {'form': form, 'report': report })
コード例 #9
0
ファイル: views.py プロジェクト: tedkirkpatrick/coursys
def new_query(request, report):
    report = get_object_or_404(Report, slug=report) 

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            messages.success(request, "Created new report query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm()

    return render(request, 'reports/new_query.html', {'form': form, 'report': report })
コード例 #10
0
ファイル: views.py プロジェクト: csvenja/coursys
def edit_query(request, report, query_id):
    report = get_object_or_404(Report, slug=report)
    query = get_object_or_404(Query, id=int(query_id))

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            query.delete()
            messages.success(request, "Edited query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm(instance=query)

    return render(request, 'reports/edit_query.html', {'form': form, 'report': report, 'query_id':query_id })
コード例 #11
0
ファイル: views.py プロジェクト: tedkirkpatrick/coursys
def edit_query(request, report, query_id):
    report = get_object_or_404(Report, slug=report)
    query = get_object_or_404(Query, id=int(query_id))

    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            f.report = report
            f.created_by = request.user.username
            f.save()
            query.delete()
            messages.success(request, "Edited query: %s" % f.query)
            return HttpResponseRedirect(reverse('reports.views.view_report', kwargs={'report':report.slug}))
    else:
        form = QueryForm(instance=query)

    return render(request, 'reports/edit_query.html', {'form': form, 'report': report, 'query_id':query_id })
コード例 #12
0
ファイル: views.py プロジェクト: kuleana/ay250_pyseminar
def list_results(request):
    """ list_results(request): called when list_requests.html is accessed. Displays bibtex info in user-friendly format for terms that match query """
    outstring = 'No Results to Display' # if no results, display this to user
    if request.method == 'POST':
        form=QueryForm(request.POST)
        if form.is_valid():
            search=str(request.POST['title'])
            connection = sqlite3.connect("bibtexinfo.db")
            cursor = connection.cursor()
            sql_cmd="SELECT * FROM bib WHERE "+search
            try:
                cursor.execute(sql_cmd)
                db_info = cursor.fetchall()
                if len(db_info)>0: outstring='' # if query successful, no error message is printed
            except:
                outstring = 'Invalid Format! Please Try Again' # if exception is raised, print format error
                db_info = []
    form=QueryForm()
    return render_to_response('list_results.html',locals(),context_instance=RequestContext(request))
コード例 #13
0
ファイル: views.py プロジェクト: lasarux/PollXpress
def query_edit(request, query_id=False, template='poll/query_form.html'):
    if query_id:
        instance = Query.objects.get(id=query_id)
    else:
        instance = None

    if request.method == 'POST':
        form = QueryForm(request.POST, instance=instance)
        if form.is_valid():
            query = form.save(commit=False)
            if not query_id:
                query.user = request.user
            query.save()
            messages.add_message(request, messages.SUCCESS,
                ugettext("Successfully saved query: %s") % query.name)
            return HttpResponseRedirect(reverse('query-view', args=[query.id]))
        
    form = QueryForm(instance=instance)
    data = {'form': form}
    return render_to_response(template, data, context_instance=RequestContext(request))
    def post(self, request):
        """A handler for a POST web request from search view

        Provides a web page with filled query form and listed queried tweets from twitter and/or
        saved queried data in mongoDB database with a specified tag
        :param request: HTTP web POST request
        :return: a web page with a search interface
        """
        form = QueryForm(request.POST)
        if form.is_valid():
            if 'form_save' in request.POST:
                # TODO: Implement async waiting for saving with progress bar
                self.save(form)
            return self.search(request, form)

        header = 'Error occurred'
        pages = []
        return render(
            request,
            self.template_name,
            {'form': form, 'header': header, 'pages': pages})
コード例 #15
0
def search(request):
    if request.method == 'POST' :
        form = QueryForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data['title']
            date = form.cleaned_data['date']
            
            query = """PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX prov: <http://www.w3.org/ns/prov#>

SELECT DISTINCT ?regulation ?title ?date ?sc WHERE {{
  ?regulation dcterms:title ?title .
  ?title bif:contains "{}"  OPTION( SCORE ?sc ).
  ?regulation prov:wasGeneratedAtTime ?date .
  
  FILTER(?date <= '{}'^^xsd:date)
}} ORDER BY DESC(?sc) DESC(?date) LIMIT 500
"""
            
            
            
            sparql = SPARQLWrapper(SPARQL_ENDPOINT)
                
            sparql.setReturnFormat(JSON)
            
            try :
                formatted_query = query.format(title, date)
                sparql.setQuery(formatted_query)    
                sparql_results = sparql.query().convert()
            except :
                try :
                    formatted_query = query.format("'{}'".format(title),date)
                    sparql.setQuery(formatted_query)
                    sparql_results = sparql.query().convert()
                except :
                    return HttpResponse("Something went wrong!<br/>Your query was:<br/><pre>{}</pre>".format(formatted_query))
                    
                
            
            results = []
            for row in sparql_results['results']['bindings'] :
                r = {}
                
                r['uri'] = row['regulation']['value']
                r['title'] = row['title']['value']
                r['date'] = row['date']['value']
                r['xml'] = r['uri'].replace('/id/','/doc/') + '/data.xml' 
                r['n3'] = r['uri'].replace('/id/','/doc/') + '/data.n3'
                r['score'] = row['sc']['value']
                
                results.append(r)
            
            endpoint = "http://doc.metalex.eu:8000/sparql"
            query_link = "http://yasgui.data2semantics.org/?query={}&endpoint={}&tabTitle={}".format(urllib.quote(formatted_query),urllib.quote(endpoint), urllib.quote(title))
            t = get_template('results.html')
            html = t.render(RequestContext(request, {'results': results, 'title': title, 'date': date, 'query_link': query_link}))
            
            return HttpResponse(html)       

    else:
        form = QueryForm()
    
    t = get_template('search.html')
    html = t.render(RequestContext(request, {'form': form,}))
    return HttpResponse(html)
コード例 #16
0
def search(request):
    if request.method == 'POST':
        form = QueryForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data['title']
            date = form.cleaned_data['date']

            query = """PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX prov: <http://www.w3.org/ns/prov#>

SELECT DISTINCT ?regulation ?title ?date ?sc WHERE {{
  ?regulation dcterms:title ?title .
  ?title bif:contains "{}"  OPTION( SCORE ?sc ).
  ?regulation prov:wasGeneratedAtTime ?date .
  
  FILTER(?date <= '{}'^^xsd:date)
}} ORDER BY DESC(?sc) DESC(?date) LIMIT 500
"""

            sparql = SPARQLWrapper(SPARQL_ENDPOINT)

            sparql.setReturnFormat(JSON)

            try:
                formatted_query = query.format(title, date)
                sparql.setQuery(formatted_query)
                sparql_results = sparql.query().convert()
            except:
                try:
                    formatted_query = query.format("'{}'".format(title), date)
                    sparql.setQuery(formatted_query)
                    sparql_results = sparql.query().convert()
                except:
                    return HttpResponse(
                        "Something went wrong!<br/>Your query was:<br/><pre>{}</pre>"
                        .format(formatted_query))

            results = []
            for row in sparql_results['results']['bindings']:
                r = {}

                r['uri'] = row['regulation']['value']
                r['title'] = row['title']['value']
                r['date'] = row['date']['value']
                r['xml'] = r['uri'].replace('/id/', '/doc/') + '/data.xml'
                r['n3'] = r['uri'].replace('/id/', '/doc/') + '/data.n3'
                r['score'] = row['sc']['value']

                results.append(r)

            endpoint = "http://doc.metalex.eu:8000/sparql"
            query_link = "http://yasgui.data2semantics.org/?query={}&endpoint={}&tabTitle={}".format(
                urllib.quote(formatted_query), urllib.quote(endpoint),
                urllib.quote(title))
            t = get_template('results.html')
            html = t.render(
                RequestContext(
                    request, {
                        'results': results,
                        'title': title,
                        'date': date,
                        'query_link': query_link
                    }))

            return HttpResponse(html)

    else:
        form = QueryForm()

    t = get_template('search.html')
    html = t.render(RequestContext(request, {
        'form': form,
    }))
    return HttpResponse(html)