Skip to content

Commit

Permalink
Merge branch 'master' into fix-edit-and-sold
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeteo committed Jan 25, 2016
2 parents a951467 + d4718a0 commit 268d1c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 8 additions & 0 deletions caravel/controllers/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def user_agent(user_agent):
return str(user_agents.parse(user_agent))


def email_order(entity):
user, domain = entity.principal.email.split("@")
return (domain, user)


@app.route("/moderation", methods=["GET", "POST"])
def moderation_view():
"""
Expand Down Expand Up @@ -48,6 +53,9 @@ def moderation_view():
inquiries = model.UnapprovedInquiry().query().fetch(100)
listings = model.UnapprovedListing().query().fetch(100)

inquiries.sort(key=email_order)
listings.sort(key=email_order)

return render_template("moderation/view.html",
inquiries=inquiries,
listings=listings)
6 changes: 2 additions & 4 deletions caravel/static/js/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ var enableModeration = function(csrfToken) {
elem.addEventListener("click", function() {
var this_ = this, xhr = new XMLHttpRequest;
xhr.open("POST", "/moderation", true);
this_.parentNode.parentNode.style.opacity = 0.5;
this_.parentNode.parentNode.remove();
xhr.onreadystatechange = function() {
if (xhr.status >= 200 && xhr.status < 300) {
this_.parentNode.parentNode.remove();
} else {
console.error("XHR FAILED");
window.alert("XHR FAILED");
}
};
xhr.setRequestHeader("Content-type",
Expand Down
18 changes: 8 additions & 10 deletions caravel/templates/moderation/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ <h2>Inquiries</h2>
<table class="table table-striped">
<thead>
<tr>
<th>User Agent</th>
<th>IP</th>
<th>Email</th>
<th>Device</th>
<th>Listing</th>
<th>Message</th>
<th>Email</th>
<th>Moderation</th>
</tr>
</thead>
{% for inquiry in inquiries %}
<tr>
<td>{{ user_agent(inquiry.principal.device.user_agent) }}</td>
<td>{{ inquiry.principal.device.ip_address }}</td>
<td>{{ inquiry.principal.email }}</td>
<td>{{ user_agent(inquiry.principal.device.user_agent) }}<br/>
{{ inquiry.principal.device.ip_address }}</td>
<td><a href="{{ url_for('show_listing',
listing=inquiry.listing.get()) }}">
{{ inquiry.listing.get().title }}</td>
<td>{{ inquiry.message }}</td>
<td>{{ inquiry.principal.email }}</td>
<td><a data-approve="{{ inquiry.key.urlsafe() }}"
class="btn btn-success">Approve</a>
<a data-deny="{{ inquiry.key.urlsafe() }}"
Expand All @@ -37,21 +36,20 @@ <h2>Listings</h2>
<table class="table table-striped">
<thead>
<tr>
<th>User Agent</th>
<th>IP</th>
<th>Email</th>
<th>Device</th>
<th>Title</th>
<th>Body</th>
<th>Email</th>
<th>Moderation</th>
</tr>
</thead>
{% for listing in listings %}
<tr>
<td>{{ user_agent(listing.principal.device.user_agent) }}</td>
<td>{{ listing.principal.device.ip_address }}</td>
<td>{{ listing.principal.email }}</td>
<td>{{ listing.title }}</td>
<td>{{ listing.body }}</td>
<td>{{ listing.principal.email }}</td>
<td><a data-approve="{{ listing.key.urlsafe() }}"
class="btn btn-success">Approve</a>
<a data-deny="{{ listing.key.urlsafe() }}"
Expand Down

0 comments on commit 268d1c5

Please sign in to comment.