~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-20 04:52:31 UTC
  • mto: This revision was merged to the branch mainline in revision 1826.
  • Revision ID: grantw@unimelb.edu.au-20100720045231-8ia3uk8nao8zdq1i
Replace cjson with json, or simplejson if json is not available (Python <2.6)

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
    """
265
268
            'groups':          [{'name': group.name,
266
269
                                 'nick': group.nick} for group in e.groups]
267
270
        })
268
 
    response = cjson.encode(dict_enrolments)
 
271
    response = json.dumps(dict_enrolments)
269
272
    req.content_type = "text/plain"
270
273
    req.write(response)
271
274
 
299
302
                        'nick': g.nick} for g in p.project_groups]
300
303
        })
301
304
 
302
 
    response = cjson.encode(dict_projectsets)
 
305
    response = json.dumps(dict_projectsets)
303
306
    req.write(response)
304
307
 
305
308
@require_method('POST')
373
376
                           msg,
374
377
                           req.config['usrmgt']['magic'],
375
378
                          )
376
 
    except cjson.DecodeError, e:
 
379
    except ValueError, e:
377
380
        raise Exception("Could not understand usrmgt server response:" +
378
381
                        e.message)
379
382
 
426
429
        if member in offeringmembers:
427
430
            offeringmembers.remove(member)
428
431
 
429
 
    response = cjson.encode(
 
432
    response = json.dumps(
430
433
        {'groupmembers': groupmembers, 'available': offeringmembers})
431
434
 
432
435
    req.content_type = "text/plain"
467
470
                           msg,
468
471
                           req.config['usrmgt']['magic'],
469
472
                          )
470
 
    except cjson.DecodeError, e:
 
473
    except ValueError, e:
471
474
        raise Exception("Could not understand usrmgt server response: %s" +
472
475
                        e.message)
473
476
 
474
477
        if 'response' not in usrmgt or usrmgt['response']=='failure':
475
478
            raise Exception("Failure creating repository: " + str(usrmgt))
476
479
 
477
 
    return(cjson.encode({'response': 'okay'}))
 
480
    return(json.dumps({'response': 'okay'}))
478
481
 
479
482
@require_method('POST')
480
483
def handle_unassign_group(req, fields):
514
517
                           msg,
515
518
                           req.config['usrmgt']['magic'],
516
519
                          )
517
 
    except cjson.DecodeError, e:
 
520
    except ValueError, e:
518
521
        raise Exception("Could not understand usrmgt server response: %s" +
519
522
                        e.message)
520
523
 
521
524
        if 'response' not in usrmgt or usrmgt['response']=='failure':
522
525
            raise Exception("Failure creating repository: " + str(usrmgt))
523
526
 
524
 
    return(cjson.encode({'response': 'okay'}))
 
527
    return(json.dumps({'response': 'okay'}))
525
528
 
526
529
# Map action names (from the path)
527
530
# to actual function objects