Remove some debug code

This commit is contained in:
Mark Veidemanis 2022-07-21 13:50:56 +01:00
parent 4b4b8bfe72
commit 79b1f7676e
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
6 changed files with 23 additions and 231 deletions

View File

@ -56,13 +56,10 @@ def update_customer_fields(stripe_id, email=None, first_name=None, last_name=Non
"""
Update the customer fields in Stripe.
"""
print("Update customer fields called")
if email:
print("Email modified")
stripe.Customer.modify(stripe_id, email=email)
logger.info(f"Modified Stripe customer {stripe_id} to have email {email}")
if first_name or last_name:
print("Name modified")
name = expand_name(first_name, last_name)
stripe.Customer.modify(stripe_id, name=name)
logger.info(f"Modified Stripe customer {stripe_id} to have email {name}")

View File

@ -1,182 +0,0 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="box">
<form method="POST">
{% csrf_token %}
<div class="field">
<label class="label">Search</label>
<div class="field-body">
<div class="field">
<div class="control is-expanded has-icons-left">
<input name="query" class="input" type="text" placeholder="Query">
<span class="icon is-small is-left">
<i class="fas fa-magnifying-glass"></i>
</span>
</div>
</div>
</div>
</div>
<div class="columns">
<div class="column">
<label class="label">Timescale</label>
<div class="field-body">
<div class="field">
<div class="control is-expanded has-icons-left">
<div class="select is-fullwidth">
<select name="timescale">
{% for timescale in timescales %}
<option value="{{ timescale }}">{{ timescale }}</option>
{% endfor %}
</select>
<span class="icon is-small is-left">
<i class="fas fa-magnifying-glass"></i>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="column">
<label class="label">Fields</label>
<div class="field">
<div class="control is-expanded has-icons-left">
<div class="select is-fullwidth is-multiple">
<select multiple name="fields">
{% for field in fields %}
<option value="{{ field }}">{{ field }}</option>
{% endfor %}
</select>
<span class="icon is-small is-left">
<i class="fas fa-magnifying-glass"></i>
</span>
</div>
</div>
</div>
</div>
<div class="column">
<label class="label">Results</label>
<div class="field">
<div class="control is-expanded has-icons-left">
<div class="select is-fullwidth">
<select name="size">
{% for size in sizes %}
<option value="{{ size }}">{{ size }}</option>
{% endfor %}
</select>
<span class="icon is-small is-left">
<i class="fas fa-magnifying-glass"></i>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-primary is-fullwidth">
Search
</button>
<button hx-post="{% url 'search' %}"
hx-trigger="click"
hx-target="#parent-div"
hx-swap="outerHTML">
Click Me!
</button>
</div>
</div>
</form>
</div>
{% if results is not None %}
<div class="box">
<div class="table-container">
<table class="table is-striped is-hoverable is-fullwidth">
<thead>
<tr>
<th>TS</th>
<th>msg</th>
<th>host</th>
<th>nick</th>
<th>channel</th>
<th>net</th>
</tr>
</thead>
<tbody>
{% for item in results %}
<tr>
<td>{{ item.ts }}</td>
<td>{{ item.msg }}</td>
<td>{{ item.host }}</td>
<td>{{ item.nick }}</td>
<td>{{ item.channel }}</td>
<td>{{ item.net }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="box">
<div class="columns">
<div class="column">
<p>{{ card }} hits</p>
</div>
{% if redacted != 0 %}
<div class="column">
<p>{{ redacted }} redacted</p>
</div>
{% endif %}
{% if exemption is not None %}
<div class="column">
<p>god mode</p>
</div>
{% endif %}
<div class="column">
<p>{{ took }}ms</p>
</div>
</div>
</div>
<div class="columns">
<div class="column is-half">
<div class="box">
<label class="label">Volume</label>
<canvas id="volumeChart"></canvas>
<script type="text/javascript">
$.post('{% url "chart_volume_json" %}', function(data) {
var ctx = $("#volumeChart").get(0).getContext("2d");
new Chart(ctx, {
type: 'line', data: data
});
});
</script>
</div>
</div>
<div class="column">
<div class="box">
<label class="label">Sentiment</label>
<canvas id="sentimentChart"></canvas>
<script type="text/javascript">
$.post('{% url "chart_sentiment_json" %}', function(data) {
var ctx = $("#sentimentChart").get(0).getContext("2d");
new Chart(ctx, {
type: 'line', data: data
});
});
</script>
</div>
</div>
</div>
{% endif %}
{% endblock %}

View File

@ -1,11 +0,0 @@
{% load static %}
<html>
<head>
</head>
<body>
</body>
</html>

View File

@ -1,16 +1,12 @@
{% load static %}
<div id="results">
{% if results is not None %}
<div style="display: none" id="jsonData" data-json="{{ data }}"></div>
<div class="columns">
<div class="column">
<div class="box">
<label class="label">Sentiment</label>
<canvas id="volume"></canvas>
<script src="{% static 'chart.js' %}"></script>
</div>
</div>
{% if results is not None %}
<div style="display: none" id="jsonData" data-json="{{ data }}">
</div>
<div class="box">
<canvas id="volume"></canvas>
<script src="{% static 'chart.js' %}"></script>
</div>
<div class="box">
<div class="table-container">

View File

@ -1,5 +1,4 @@
import logging
import pprint
import stripe
from django.conf import settings
@ -15,7 +14,6 @@ from core.lib.products import assemble_plan_map
from core.models import ContentBlock, Plan, Session
logger = logging.getLogger(__name__)
pp = pprint.PrettyPrinter(indent=4)
# Create your views here

View File

@ -1,14 +1,13 @@
from rest_framework.views import APIView
import logging
from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
from django.contrib.auth.mixins import LoginRequiredMixin
import json
from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
from django.views import View
from rest_framework.parsers import JSONParser
from core.lib.opensearch import initialise_opensearch, run_main_query
client = initialise_opensearch()
@ -23,7 +22,6 @@ def query_results(request, post_params, api=False):
results = run_main_query(client, request.user, query, fields, size)
if not results:
return False
# pp.pprint(results)
results_parsed = []
if "hits" in results.keys():
if "hits" in results["hits"]:
@ -42,45 +40,41 @@ def query_results(request, post_params, api=False):
}
return context
class Search(LoginRequiredMixin, View):
#parser_classes = [JSONParser]
# parser_classes = [JSONParser]
template_name = "ui/results.html"
plan_name = "drilldown"
def post(self, request):
if not request.user.has_plan(self.plan_name):
return render(request, "denied.html")
context = query_results(request, request.POST)
print("context: ", context)
context['data'] = json.dumps(
context["data"] = json.dumps(
[
{
'id': item.get('id'),
'value': item.get("sentiment", 0),
'date': item.get("ts"),
"id": item.get("id"),
"value": item.get("sentiment", 0),
"date": item.get("ts"),
}
for item in context["results"]
]
)
print("context['data']: ", context['data'])
if context:
print("OGING TO RENDER")
return render(request, self.template_name, context)
else:
return HttpResponse("No results")
class APISearch(LoginRequiredMixin, View):
#parser_classes = [JSONParser]
# parser_classes = [JSONParser]
template_name = "ui/results.html"
plan_name = "drilldown"
def post(self, request):
print("POST")
if not request.user.has_plan(self.plan_name):
return JsonResponse({"success": False})
print("PERMS")
context = query_results(request, request.POST)
print("CONTEXT", context)
return JsonResponse(context)