Python django.utils.simplejson.dumps() Examples
The following are 30
code examples of django.utils.simplejson.dumps().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.utils.simplejson
, or try the search function
.
Example #1
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def add_emails_to_addressbook(self, id, emails): """ Add new emails to addressbook @param id: unsigned int addressbook ID @param emails: list of dictionaries [ {'email': 'test@test.com', 'variables': {'varname_1': 'value_1', ..., 'varname_n': 'value_n' }}, {...}, {'email': 'testn@testn.com'}} ] @return: dictionary with response message """ logger.info("Function call: add_emails_to_addressbook into: {}".format(id, )) if not id or not emails: self.__handle_error("Empty addressbook id or emails") try: emails = json.dumps(emails) except: logger.debug("Emails: {}".format(emails)) return self.__handle_error("Emails list can't be converted by JSON library") return self.__handle_result(self.__send_request('addressbooks/{}/emails'.format(id), 'POST', {'emails': emails}))
Example #2
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def sms_get_phones_info_from_blacklist(self, phones): """ SMS: get info by phones from the blacklist @param phones: array phones @return: dictionary with response message """ if not phones: return self.__handle_error("Empty phones") try: phones = json.dumps(phones) except: logger.debug("Phones: {}".format(phones)) return self.__handle_error("Phones list can't be converted by JSON library") data_to_send = { 'phones': phones } logger.info("Function call: sms_add_phones_to_blacklist") return self.__handle_result(self.__send_request('sms/black_list/by_numbers', 'GET', data_to_send))
Example #3
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def sms_delete_phones(self, addressbook_id, phones): """ SMS: remove phones from the address book @return: dictionary with response message """ if not addressbook_id or not phones: return self.__handle_error("Empty addressbook id or phones") try: phones = json.dumps(phones) except: logger.debug("Phones: {}".format(phones)) return self.__handle_error("Phones list can't be converted by JSON library") data_to_send = { 'addressBookId': addressbook_id, 'phones': phones } logger.info("Function call: sms_delete_phones") return self.__handle_result(self.__send_request('sms/numbers', 'DELETE', data_to_send))
Example #4
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def sms_add_phones_with_variables(self, addressbook_id, phones): """ SMS: add phones with variables from the address book @return: dictionary with response message """ if not addressbook_id or not phones: return self.__handle_error("Empty addressbook id or phones") try: phones = json.dumps(phones) except: logger.debug("Phones: {}".format(phones)) return self.__handle_error("Phones list can't be converted by JSON library") data_to_send = { 'addressBookId': addressbook_id, 'phones': phones } logger.info("Function call: sms_add_phones_with_variables") return self.__handle_result(self.__send_request('sms/numbers/variables', 'POST', data_to_send))
Example #5
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def sms_add_phones(self, addressbook_id, phones): """ SMS: add phones from the address book @return: dictionary with response message """ if not addressbook_id or not phones: return self.__handle_error("Empty addressbook id or phones") try: phones = json.dumps(phones) except: logger.debug("Phones: {}".format(phones)) return self.__handle_error("Phones list can't be converted by JSON library") data_to_send = { 'addressBookId': addressbook_id, 'phones': phones } logger.info("Function call: sms_add_phones") return self.__handle_result(self.__send_request('sms/numbers', 'POST', data_to_send))
Example #6
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def sms_add_phones_to_blacklist(self, phones, comment): """ SMS: add phones to blacklist @param phones: array phones @param comment: string describing why phones added to blacklist @return: dictionary with response message """ if not phones: return self.__handle_error("Empty phones") try: phones = json.dumps(phones) except: logger.debug("Phones: {}".format(phones)) return self.__handle_error("Phones list can't be converted by JSON library") data_to_send = { 'phones': phones, 'description': comment } logger.info("Function call: sms_add_phones_to_blacklist") return self.__handle_result(self.__send_request('sms/black_list', 'POST', data_to_send))
Example #7
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def sms_delete_phones_from_blacklist(self, phones): """ SMS: remove phones from blacklist @param phones: array phones @return: dictionary with response message """ if not phones: return self.__handle_error("Empty phones") try: phones = json.dumps(phones) except: logger.debug("Phones: {}".format(phones)) return self.__handle_error("Phones list can't be converted by JSON library") data_to_send = { 'phones': phones } logger.info("Function call: sms_add_phones_to_blacklist") return self.__handle_result(self.__send_request('sms/black_list', 'DELETE', data_to_send))
Example #8
Source File: bottle.py From POC-EXP with GNU General Public License v3.0 | 6 votes |
def apply(self, callback, _): dumps = self.json_dumps if not dumps: return callback def wrapper(*a, **ka): try: rv = callback(*a, **ka) except HTTPError: rv = _e() if isinstance(rv, dict): #Attempt to serialize, raises exception on failure json_response = dumps(rv) #Set content type only if serialization successful response.content_type = 'application/json' return json_response elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict): rv.body = dumps(rv.body) rv.content_type = 'application/json' return rv return wrapper
Example #9
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 6 votes |
def delete_emails_from_addressbook(self, id, emails): """ Delete email addresses from addressbook @param id: unsigned int addressbook ID @param emails: list of emails ['test_1@test_1.com', ..., 'test_n@test_n.com'] @return: dictionary with response message """ logger.info("Function call: delete_emails_from_addressbook from: {}".format(id, )) if not id or not emails: self.__handle_error("Empty addressbook id or emails") try: emails = json.dumps(emails) except: logger.debug("Emails: {}".format(emails)) return self.__handle_error("Emails list can't be converted by JSON library") return self.__handle_result(self.__send_request('addressbooks/{}/emails'.format(id), 'DELETE', {'emails': emails}))
Example #10
Source File: sessions.py From python-for-android with Apache License 2.0 | 6 votes |
def __delitem__(self, keyname): """ Delete item from session data. Args: keyname: The keyname of the object to delete. """ bad_key = False sessdata = self._get(keyname = keyname) if sessdata is None: bad_key = True else: sessdata.delete() if keyname in self.cookie_vals: del self.cookie_vals[keyname] bad_key = False self.output_cookie[self.cookie_name + '_data'] = \ simplejson.dumps(self.cookie_vals) print self.output_cookie.output() if bad_key: raise KeyError(str(keyname)) if keyname in self.cache: del self.cache[keyname]
Example #11
Source File: bottle.py From EasY_HaCk with Apache License 2.0 | 6 votes |
def apply(self, callback, _): dumps = self.json_dumps if not dumps: return callback def wrapper(*a, **ka): try: rv = callback(*a, **ka) except HTTPError: rv = _e() if isinstance(rv, dict): #Attempt to serialize, raises exception on failure json_response = dumps(rv) #Set content type only if serialization successful response.content_type = 'application/json' return json_response elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict): rv.body = dumps(rv.body) rv.content_type = 'application/json' return rv return wrapper
Example #12
Source File: sessions.py From python-for-android with Apache License 2.0 | 6 votes |
def put(self, keyname, value, session): """ Insert a keyname/value pair into the datastore for the session. Args: keyname: The keyname of the mapping. value: The value of the mapping. """ keyname = session._validate_key(keyname) if value is None: raise ValueError('You must pass a value to put.') # Use simplejson for cookies instead of pickle. session.cookie_vals[keyname] = value # update the requests session cache as well. session.cache[keyname] = value session.output_cookie[session.cookie_name + '_data'] = \ simplejson.dumps(session.cookie_vals) print session.output_cookie.output()
Example #13
Source File: bottle.py From warriorframework with Apache License 2.0 | 6 votes |
def apply(self, callback, _): dumps = self.json_dumps if not dumps: return callback def wrapper(*a, **ka): try: rv = callback(*a, **ka) except HTTPError: rv = _e() if isinstance(rv, dict): #Attempt to serialize, raises exception on failure json_response = dumps(rv) #Set content type only if serialization successful response.content_type = 'application/json' return json_response elif isinstance(rv, HTTPResponse) and isinstance(rv.body, dict): rv.body = dumps(rv.body) rv.content_type = 'application/json' return rv return wrapper
Example #14
Source File: views.py From astrobin with GNU Affero General Public License v3.0 | 6 votes |
def ajax_add_toggleproperty(request): if request.method == "POST": object_id = request.POST.get("object_id") content_type = get_object_or_404(ContentType, pk=request.POST.get("content_type_id")) property_type = request.POST.get("property_type") obj = content_type.get_object_for_this_type(pk=object_id) response_dict = {} # check if it was created already if ToggleProperty.objects.filter(content_type=content_type, object_id=object_id, \ property_type=property_type, user=request.user): # return conflict response code if already satisfied return HttpResponse(status=409) # if not create it tp = ToggleProperty.objects.create_toggleproperty(property_type, obj, request.user) if settings.TOGGLEPROPERTIES.get('show_count'): count = ToggleProperty.objects.toggleproperties_for_object(property_type, obj).count() response_dict['count'] = count return HttpResponse(simplejson.dumps(response_dict), 'application/javascript', status=200) else: return HttpResponse(status=405)
Example #15
Source File: views.py From astrobin with GNU Affero General Public License v3.0 | 6 votes |
def ajax_remove_toggleproperty(request): if request.method == "POST": object_id = request.POST.get("object_id") content_type = get_object_or_404(ContentType, pk=request.POST.get("content_type_id")) property_type = request.POST.get("property_type") response_dict = {} tp = get_object_or_404(ToggleProperty, object_id=object_id, content_type=content_type, property_type=property_type, user=request.user) tp.delete() obj = content_type.get_object_for_this_type(pk=object_id) if settings.TOGGLEPROPERTIES.get('show_count'): count = ToggleProperty.objects.toggleproperties_for_object(property_type, obj).count() response_dict['count'] = count return HttpResponse(simplejson.dumps(response_dict), 'application/javascript', status=200) else: return HttpResponse(status=405)
Example #16
Source File: sessions.py From python-for-android with Apache License 2.0 | 5 votes |
def clear(self): """ Remove all items """ sessiondata = self._get() # delete from datastore if sessiondata is not None: for sd in sessiondata: sd.delete() # delete from memcache self.cache = {} self.cookie_vals = {} self.output_cookie[self.cookie_name + '_data'] = \ simplejson.dumps(self.cookie_vals) print self.output_cookie.output()
Example #17
Source File: bottle.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def json_dumps(data): raise ImportError( "JSON support requires Python 2.6 or simplejson.")
Example #18
Source File: flash.py From python-for-android with Apache License 2.0 | 5 votes |
def __setattr__(self, name, value): """ Create a cookie when setting the 'msg' attribute. """ if name == 'cookie': self.__dict__['cookie'] = value elif name == 'msg': self.__dict__['msg'] = value self.__dict__['cookie'][COOKIE_NAME] = simplejson.dumps(value) self.__dict__['cookie'][COOKIE_NAME]['path'] = '/' print self.cookie else: raise ValueError('You can only set the "msg" attribute.')
Example #19
Source File: sessions.py From python-for-android with Apache License 2.0 | 5 votes |
def put(self, keyname, value, session): """ Insert a keyname/value pair into the datastore for the session. Args: keyname: The keyname of the mapping. value: The value of the mapping. """ keyname = session._validate_key(keyname) if value is None: raise ValueError('You must pass a value to put.') # datestore write trumps cookie. If there is a cookie value # with this keyname, delete it so we don't have conflicting # entries. if session.cookie_vals.has_key(keyname): del(session.cookie_vals[keyname]) session.output_cookie[session.cookie_name + '_data'] = \ simplejson.dumps(session.cookie_vals) print session.output_cookie.output() sessdata = session._get(keyname=keyname) if sessdata is None: sessdata = _AppEngineUtilities_SessionData() sessdata.session_key = session.session.session_key sessdata.keyname = keyname sessdata.content = pickle.dumps(value) # UNPICKLING CACHE session.cache[keyname] = pickle.dumps(value) session.cache[keyname] = value sessdata.put() # todo _set_memcache() should be going away when this is done # session._set_memcache()
Example #20
Source File: main_rsa.py From python-for-android with Apache License 2.0 | 5 votes |
def post(self): """Fetches the user's data.""" try: feed = gdocs.GetDocumentListFeed() json = [] for entry in feed.entry: if entry.lastModifiedBy is not None: last_modified_by = entry.lastModifiedBy.email.text else: last_modified_by = '' if entry.lastViewed is not None: last_viewed = entry.lastViewed.text else: last_viewed = '' json.append({'title': entry.title.text, 'links': {'alternate': entry.GetHtmlLink().href}, 'published': entry.published.text, 'updated': entry.updated.text, 'resourceId': entry.resourceId.text, 'type': entry.GetDocumentType(), 'lastModifiedBy': last_modified_by, 'lastViewed': last_viewed }) self.response.out.write(simplejson.dumps(json)) except gdata.service.RequestError, error: OAuthDance.post(self)
Example #21
Source File: main_hmac.py From python-for-android with Apache License 2.0 | 5 votes |
def post(self): """Fetches the user's data.""" try: feed = gdocs.GetDocumentListFeed() json = [] for entry in feed.entry: if entry.lastModifiedBy is not None: last_modified_by = entry.lastModifiedBy.email.text else: last_modified_by = '' if entry.lastViewed is not None: last_viewed = entry.lastViewed.text else: last_viewed = '' json.append({'title': entry.title.text, 'links': {'alternate': entry.GetHtmlLink().href}, 'published': entry.published.text, 'updated': entry.updated.text, 'resourceId': entry.resourceId.text, 'type': entry.GetDocumentType(), 'lastModifiedBy': last_modified_by, 'lastViewed': last_viewed }) self.response.out.write(simplejson.dumps(json)) except gdata.service.RequestError, error: OAuthDance.post(self)
Example #22
Source File: tickets.py From yats with MIT License | 5 votes |
def search(request): searchable_fields = settings.TICKET_SEARCH_FIELDS if request.method == 'POST' and 'reportname' in request.POST and request.POST['reportname']: rep = tickets_reports() rep.name = request.POST['reportname'] rep.search = json.dumps(request.session['last_search'], cls=DjangoJSONEncoder) rep.save(user=request.user) request.session['last_search'] = convert_sarch(clean_search_values(request.session['last_search'])) request.session['last_search_caption'] = request.POST['reportname'] return table(request, search=request.session['last_search'], list_caption=request.session['last_search_caption']) if request.method == 'POST': form = SearchForm(request.POST, include_list=searchable_fields, is_stuff=request.user.is_staff, user=request.user, customer=request.organisation.id) form.is_valid() request.session['last_search'] = convert_sarch(clean_search_values(form.cleaned_data)) request.session['last_search_caption'] = '' return table(request, search=request.session['last_search']) if 'last_search' in request.session and 'new' not in request.GET: return table(request, search=request.session['last_search'], list_caption=request.session.get('last_search_caption', '')) return HttpResponseRedirect('/tickets/search/extended/')
Example #23
Source File: bottle.py From POC-EXP with GNU General Public License v3.0 | 5 votes |
def __init__(self, json_dumps=json_dumps): self.json_dumps = json_dumps
Example #24
Source File: bottle.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def json_dumps(data): raise ImportError( "JSON support requires Python 2.6 or simplejson.")
Example #25
Source File: bottle.py From EasY_HaCk with Apache License 2.0 | 5 votes |
def __init__(self, json_dumps=json_dumps): self.json_dumps = json_dumps
Example #26
Source File: core.py From gdata-python3 with Apache License 2.0 | 5 votes |
def jsonc_to_string(jsonc_obj): """Converts a Jsonc object into a string of JSON-C.""" return simplejson.dumps(_convert_to_object(jsonc_obj))
Example #27
Source File: core.py From gdata-python3 with Apache License 2.0 | 5 votes |
def prettify_jsonc(jsonc_obj, indentation=2): """Converts a Jsonc object to a pretified (intented) JSON string.""" return simplejson.dumps(_convert_to_object(jsonc_obj), indent=indentation)
Example #28
Source File: cache.py From canvas with BSD 3-Clause "New" or "Revised" License | 5 votes |
def write_offline_manifest(manifest): filename = get_offline_manifest_filename() default_storage.save(filename, ContentFile(simplejson.dumps(manifest, indent=2)))
Example #29
Source File: shortcuts.py From yats with MIT License | 5 votes |
def remember_changes(request, form, ticket): from yats.models import tickets_history new, old = field_changes(form) h = tickets_history() h.ticket = ticket h.new = json.dumps(new) h.old = json.dumps(old) h.action = 4 h.save(user=request.user)
Example #30
Source File: pysendpulse.py From sendpulse-rest-api-python with Apache License 2.0 | 5 votes |
def get_emails_stat_by_campaigns(self, emails): """ Get campaigns statistic for list of emails @param emails: list of emails ['test_1@test_1.com', ..., 'test_n@test_n.com'] @return: dictionary with response message """ logger.info("Function call: get_emails_stat_by_campaigns") if not emails: self.__handle_error("Empty emails") try: emails = json.dumps(emails) except: logger.debug("Emails: {}".format(emails)) return self.__handle_error("Emails list can't be converted by JSON library") return self.__handle_result(self.__send_request('emails/campaigns', 'POST', {'emails': emails}))