~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/userservice/__init__.py

  • Committer: William Grant
  • Date: 2010-07-28 04:13:05 UTC
  • mfrom: (1801.1.2 die-cjson-die)
  • Revision ID: grantw@unimelb.edu.au-20100728041305-xwypm3cn1l1mnki1
Port from cjson to (simple)json.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
import sys
103
103
import datetime
104
104
 
105
 
import cjson
 
105
try:
 
106
    import json
 
107
except ImportError:
 
108
    import simplejson as json
106
109
 
107
110
import ivle.database
108
111
from ivle import (util, chat)
212
215
                             msg,
213
216
                             req.config['usrmgt']['magic'],
214
217
                            )
215
 
    except cjson.DecodeError:
 
218
    except ValueError:
216
219
        # Gave back rubbish - set the response to failure
217
220
        response = {'response': 'usrmgt-failure'}
218
221
 
230
233
 
231
234
    # Write the response
232
235
    req.content_type = "text/plain"
233
 
    req.write(cjson.encode(response))
 
236
    req.write(json.dumps(response))
234
237
 
235
238
def handle_get_enrolments(req, fields):
236
239
    """
266
269
            'groups':          [{'name': group.name,
267
270
                                 'nick': group.nick} for group in e.groups]
268
271
        })
269
 
    response = cjson.encode(dict_enrolments)
 
272
    response = json.dumps(dict_enrolments)
270
273
    req.content_type = "text/plain"
271
274
    req.write(response)
272
275
 
300
303
                        'nick': g.nick} for g in p.project_groups]
301
304
        })
302
305
 
303
 
    response = cjson.encode(dict_projectsets)
 
306
    response = json.dumps(dict_projectsets)
304
307
    req.write(response)
305
308
 
306
309
@require_method('POST')
374
377
                           msg,
375
378
                           req.config['usrmgt']['magic'],
376
379
                          )
377
 
    except cjson.DecodeError, e:
 
380
    except ValueError, e:
378
381
        raise Exception("Could not understand usrmgt server response:" +
379
382
                        e.message)
380
383
 
427
430
        if member in offeringmembers:
428
431
            offeringmembers.remove(member)
429
432
 
430
 
    response = cjson.encode(
 
433
    response = json.dumps(
431
434
        {'groupmembers': groupmembers, 'available': offeringmembers})
432
435
 
433
436
    req.content_type = "text/plain"
468
471
                           msg,
469
472
                           req.config['usrmgt']['magic'],
470
473
                          )
471
 
    except cjson.DecodeError, e:
 
474
    except ValueError, e:
472
475
        raise Exception("Could not understand usrmgt server response: %s" +
473
476
                        e.message)
474
477
 
475
478
        if 'response' not in usrmgt or usrmgt['response']=='failure':
476
479
            raise Exception("Failure creating repository: " + str(usrmgt))
477
480
 
478
 
    return(cjson.encode({'response': 'okay'}))
 
481
    return(json.dumps({'response': 'okay'}))
479
482
 
480
483
@require_method('POST')
481
484
def handle_unassign_group(req, fields):
515
518
                           msg,
516
519
                           req.config['usrmgt']['magic'],
517
520
                          )
518
 
    except cjson.DecodeError, e:
 
521
    except ValueError, e:
519
522
        raise Exception("Could not understand usrmgt server response: %s" +
520
523
                        e.message)
521
524
 
522
525
        if 'response' not in usrmgt or usrmgt['response']=='failure':
523
526
            raise Exception("Failure creating repository: " + str(usrmgt))
524
527
 
525
 
    return(cjson.encode({'response': 'okay'}))
 
528
    return(json.dumps({'response': 'okay'}))
526
529
 
527
530
# Map action names (from the path)
528
531
# to actual function objects