renierdbruyn 14 Light Poster

I have a function that does certain checks, if the the checks fail, it will add values to a dict, i.e:

outstanding = {}
sims = [_sim for _sim in self.context.sims if unicode(_sim.iccid)]
# for sim in [_sim for _sim in self.context.sims if unicode(_sim.iccid)]:
print sims
count = len(sims)
if count > 250:
    outstanding["pack.maximum"] = count
if count < 5:
    outstanding["pack.minimum"] = count

If these checks fail I raise an exception:

if outstanding:
    raise HTTPInternalServerError(outstanding)

This will raise an error on my template, I handle with ajax error handler:

error: function(jqXHR, textStatus, errorThrown) {
  console.log(jqXHR);
  hide_spinner();
  show_error(1,"There was an error submitting the pack creation");
  show_error(2, jqXHR.responseText); # this returns the the dict on the body of the `500` message 
},

Show error is a javasctipt function:

function show_error(count,content) {
  $("#pack-issue-count").text(count);
  $("#pack-issue-body").html(content);
  $("#pack-issues").modal();
}

Okay, now my problem is I do not know how to use the passed dict values to display it with custom html, i.e,

{% if k == "pack.maximum" %}
<dt><span class='label label-important'>Critical</span>Maximum Pack size exeeded/dt>
<dd>a Pack can consist of a maximum of <span class='badge badge-success'>250</span>.
You have <span class="badge badge-important">{{ v }}</span></dd>
{% endif %}

How can I use the dict values in the ajax error handler?
Is there a better approach?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.