mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-05-19 08:50:44 +02:00
Fix saving and loading custom queries, update for Py3/Django2.x
This commit is contained in:
parent
2a3abc44fc
commit
ea8c75b884
@ -19,11 +19,25 @@ from helpdesk.models import Attachment, EmailTemplate
|
|||||||
|
|
||||||
from model_utils import Choices
|
from model_utils import Choices
|
||||||
|
|
||||||
from base64 import encodebytes as b64encode
|
from base64 import b64encode
|
||||||
from base64 import decodebytes as b64decode
|
from base64 import b64decode
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
logger = logging.getLogger('helpdesk')
|
logger = logging.getLogger('helpdesk')
|
||||||
|
|
||||||
|
def query_to_base64(query):
|
||||||
|
"""
|
||||||
|
Converts a query dict object to a base64-encoded bytes object.
|
||||||
|
"""
|
||||||
|
return b64encode(json.dumps(query).encode('UTF-8'))
|
||||||
|
|
||||||
|
def query_from_base64(b64data):
|
||||||
|
"""
|
||||||
|
Converts base64-encoded bytes object back to a query dict object.
|
||||||
|
"""
|
||||||
|
return json.loads(b64decode(b64data).decode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
def query_to_dict(results, descriptions):
|
def query_to_dict(results, descriptions):
|
||||||
"""
|
"""
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
{% block helpdesk_title %}{% trans "Tickets" %}{% endblock %}
|
{% block helpdesk_title %}{% trans "Tickets" %}{% endblock %}
|
||||||
|
|
||||||
{% block helpdesk_head %}
|
{% block helpdesk_head %}
|
||||||
<script src='{% static "helpdesk/filter.js" %}'></script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
@ -235,7 +235,22 @@
|
|||||||
<button id='select_inverse_btn' type="button" class="btn btn-primary btn-sm"><i class="fas fa-expand-arrows-alt"></i> {% trans "Invert" %}</button>
|
<button id='select_inverse_btn' type="button" class="btn btn-primary btn-sm"><i class="fas fa-expand-arrows-alt"></i> {% trans "Invert" %}</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p><label for='id_mass_action'>{% trans "With Selected Tickets:" %}</label> <select name='action' id='id_mass_action'><option value='take'>{% trans "Take (Assign to me)" %}</option><option value='delete'>{% trans "Delete" %}</option><optgroup label='{% trans "Close" %}'><option value='close'>{% trans "Close (Don't Send E-Mail)" %}</option><option value='close_public'>{% trans "Close (Send E-Mail)" %}</option></optgroup><optgroup label='{% trans "Assign To" %}'><option value='unassign'>{% trans "Nobody (Unassign)" %}</option>{% for u in user_choices %}<option value='assign_{{ u.id }}'>{{ u.get_username }}</option>{% endfor %}</optgroup></select> <button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-arrow-circle-right"></i> {% trans "Go" %}</button></p>
|
<p>
|
||||||
|
<label for='id_mass_action'>{% trans "With Selected Tickets:" %}</label>
|
||||||
|
<select name='action' id='id_mass_action'>
|
||||||
|
<option value='take'>{% trans "Take (Assign to me)" %}</option>
|
||||||
|
<option value='delete'>{% trans "Delete" %}</option>
|
||||||
|
<optgroup label='{% trans "Close" %}'>
|
||||||
|
<option value='close'>{% trans "Close (Don't Send E-Mail)" %}</option>
|
||||||
|
<option value='close_public'>{% trans "Close (Send E-Mail)" %}</option>
|
||||||
|
</optgroup>
|
||||||
|
<optgroup label='{% trans "Assign To" %}'>
|
||||||
|
<option value='unassign'>{% trans "Nobody (Unassign)" %}</option>
|
||||||
|
{% for u in user_choices %}<option value='assign_{{ u.id }}'>{{ u.get_username }}</option>{% endfor %}
|
||||||
|
</optgroup>
|
||||||
|
</select>
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-arrow-circle-right"></i> {% trans "Go" %}</button>
|
||||||
|
</p>
|
||||||
{% csrf_token %}</form>
|
{% csrf_token %}</form>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.panel-body -->
|
<!-- /.panel-body -->
|
||||||
@ -246,6 +261,7 @@
|
|||||||
|
|
||||||
|
|
||||||
{% block helpdesk_js %}
|
{% block helpdesk_js %}
|
||||||
|
<script src='{% static "helpdesk/filter.js" %}'></script>
|
||||||
<script>
|
<script>
|
||||||
{% if not server_side %}
|
{% if not server_side %}
|
||||||
$('#ticketTable').DataTable({
|
$('#ticketTable').DataTable({
|
||||||
|
@ -819,16 +819,12 @@ def ticket_list(request):
|
|||||||
return HttpResponseRedirect(reverse('helpdesk:list'))
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from helpdesk.lib import b64decode
|
from helpdesk.lib import query_from_base64
|
||||||
try:
|
try:
|
||||||
if six.PY3:
|
# we get a string like: b'stuff'
|
||||||
if DJANGO_VERSION[0] > 1:
|
# so leave of the first two chars (b') and last (')
|
||||||
# if Django >= 2.0
|
b64query = saved_query.query[2:-1]
|
||||||
query_params = json.loads(b64decode(str(saved_query.query).lstrip("b\\'")).decode())
|
query_params = query_from_base64(b64query)
|
||||||
else:
|
|
||||||
query_params = json.loads(b64decode(str(saved_query.query)).decode())
|
|
||||||
else:
|
|
||||||
query_params = json.loads(b64decode(str(saved_query.query)))
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Query deserialization failed. (E.g. was a pickled query)
|
# Query deserialization failed. (E.g. was a pickled query)
|
||||||
return HttpResponseRedirect(reverse('helpdesk:list'))
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
||||||
@ -920,8 +916,8 @@ def ticket_list(request):
|
|||||||
'Django Documentation on string matching in SQLite</a>.')
|
'Django Documentation on string matching in SQLite</a>.')
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from helpdesk.lib import b64encode
|
from helpdesk.lib import query_to_base64
|
||||||
urlsafe_query = b64encode(json.dumps(query_params).encode('UTF-8'))
|
urlsafe_query = query_to_base64(query_params)
|
||||||
|
|
||||||
user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True))
|
user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True))
|
||||||
|
|
||||||
@ -1153,16 +1149,12 @@ def run_report(request, report):
|
|||||||
return HttpResponseRedirect(reverse('helpdesk:report_index'))
|
return HttpResponseRedirect(reverse('helpdesk:report_index'))
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from helpdesk.lib import b64decode
|
from helpdesk.lib import query_from_base64
|
||||||
try:
|
try:
|
||||||
if six.PY3:
|
# we get a string like: b'stuff'
|
||||||
if DJANGO_VERSION[0] > 1:
|
# so leave of the first two chars (b') and last (')
|
||||||
# if Django >= 2.0
|
b64query = saved_query.query[2:-1]
|
||||||
query_params = json.loads(b64decode(str(saved_query.query).lstrip("b\\'")).decode())
|
query_params = query_from_base64(b64query)
|
||||||
else:
|
|
||||||
query_params = json.loads(b64decode(str(saved_query.query)).decode())
|
|
||||||
else:
|
|
||||||
query_params = json.loads(b64decode(str(saved_query.query)))
|
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
return HttpResponseRedirect(reverse('helpdesk:report_index'))
|
return HttpResponseRedirect(reverse('helpdesk:report_index'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user