示例#1
0
    def write(self, data, **kwargs):
        content_type = kwargs.get('content-type', 'text/html')
        if isinstance(data, (dict, list)):
            content_type = 'application/json'
            data = util.json(data)

        status = kwargs.get("status", 200)
        return HttpResponse(data, content_type=content_type, status=status)
示例#2
0
    "NC": "North Carolina",
    "ND": "North Dakota",
    "OH": "Ohio",
    "OK": "Oklahoma",
    "OR": "Oregon",
    "PA": "Pennsylvania",
    "RI": "Rhode Island",
    "SC": "South Carolina",
    "SD": "South Dakota",
    "TN": "Tennessee",
    "TX": "Texas",
    "UT": "Utah",
    "VT": "Vermont",
    "VA": "Virginia",
    "WA": "Washington",
    "WV": "West Virginia",
    "WI": "Wisconsin",
    "WY": "Wyoming"
}

buffer = []
for abbr in states:
    val = states[abbr]
    #id = len(buffer) + 1
    #buffer.append(util.json({"pk": id, "model": "rpg.state", "fields": {"label": val, "code": abbr}}))
    buffer.append('%s = {"label": "%s", "code": "%s"}' % (abbr, val, abbr))

buffer.sort()
print ",\n".join(buffer)
print util.json(buffer, indent=1)