Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fatih Erikli
committed
Sep 23, 2012
1 parent
18627ac
commit 4aacc1c
Showing
10 changed files
with
186 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
STATUS_OPEN = 0 | ||
STATUS_CLOSED = 1 | ||
|
||
STATUS_CHOICES = ( | ||
(STATUS_OPEN, _('Open')), | ||
(STATUS_CLOSED, _('Closed')), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django import forms | ||
|
||
from api_browser.models import Feedback | ||
|
||
|
||
class FeedbackForm(forms.ModelForm): | ||
class Meta: | ||
model = Feedback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.db import models | ||
from django.utils.encoding import smart_unicode | ||
|
||
from api_browser.constants import STATUS_CHOICES, STATUS_OPEN | ||
|
||
|
||
class Feedback(models.Model): | ||
""" | ||
Holds Feedback data. | ||
""" | ||
title = models.CharField(max_length=255) | ||
description = models.TextField(null=True, blank=True) | ||
status = models.IntegerField(choices=STATUS_CHOICES, default=STATUS_OPEN) | ||
duplicate = models.ForeignKey("self", null=True, blank=True) | ||
date_created = models.DateTimeField(auto_now_add=True) | ||
date_modified = models.DateTimeField(auto_now=True) | ||
|
||
def __unicode__(self): | ||
return smart_unicode(self.title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var APIBrowser = $.Class.extend({ | ||
|
||
EMPTY_RESPONSE: "(EMPTY RESPONSE)", | ||
SLIDE_DURATION: 100, | ||
|
||
selectors: { | ||
endpoint_form : ".endpoint form", | ||
endpoint_anchor: ".endpoint a", | ||
try_it: ".try-it", | ||
request: ".request", | ||
code: "code", | ||
response_status: ".response-status", | ||
response_headers: ".response-headers", | ||
response_body: ".response-body", | ||
url_parameters: ".url-parameters input" | ||
}, | ||
|
||
init: function () { | ||
this.load_rest_form(); | ||
this.make_expandable(this.selectors.endpoint_anchor, | ||
this.selectors.try_it, this.SLIDE_DURATION); | ||
this.fill_url_parameters(this.selectors.url_parameters, this.selectors.endpoint_form); | ||
}, | ||
|
||
load_rest_form: function () { | ||
$(this.selectors.endpoint_form).restForm({ | ||
"submit": this.submit_form.bind(this), | ||
"complete": this.complete_ajax_request.bind(this) | ||
}); | ||
}, | ||
|
||
"submit_form": function (form, request_headers) { | ||
form.siblings(this.selectors.request).show(). | ||
find(this.selectors.code).html(request_headers.join("\n")); | ||
}, | ||
|
||
"complete_ajax_request": function (form, xhr) { | ||
form.siblings(this.selectors.response_status).show().find( | ||
this.selectors.code).html(xhr.statusText + " (" + xhr.status + ")"); | ||
|
||
form.siblings(this.selectors.response_headers).show().find( | ||
this.selectors.code).html(xhr.getAllResponseHeaders()); | ||
|
||
form.siblings(this.selectors.response_body).show().find( | ||
this.selectors.code).text(xhr.responseText || this.EMPTY_RESPONSE); | ||
}, | ||
|
||
make_expandable: function (click_element, show_element, slide_duration) { | ||
$(click_element).click(function () { | ||
$(this).siblings(show_element).slideToggle(slide_duration || "normal"); | ||
return false; | ||
}); | ||
}, | ||
|
||
"fill_url_parameters": function (url_parameters, form_selector) { | ||
$(url_parameters).change(function () { | ||
var form = $(this).parents(form_selector); | ||
var rendered_url = form.data("endpoint-url").replace( | ||
$(this).data("token"), $(this).val()); | ||
form.attr("action", rendered_url) | ||
}) | ||
} | ||
|
||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.