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

« back to all changes in this revision

Viewing changes to www/apps/userservice/__init__.py

  • Committer: mattgiuca
  • Date: 2008-02-21 22:13:35 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:536
apps/userservice: Generalised searching for actions (dict mapping action names to
    functions).
    Create and update user are now handled correctly, but still temporarily
    return the JSON msg intended for usrmgt (can't get usrmgt to work yet).

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
        path = req.path
109
109
    # The path determines which "command" we are receiving
110
110
    fields = req.get_fieldstorage()
111
 
    if req.path == "activate_me":
112
 
        handle_activate_me(req, fields)
113
 
    else:
 
111
    try:
 
112
        func = actions_map[req.path]
 
113
    except KeyError:
114
114
        req.throw_error(req.HTTP_BAD_REQUEST)
 
115
    func(req, fields)
115
116
 
116
117
def handle_activate_me(req, fields):
117
118
    """Create the jail, svn, etc, for the currently logged in user (this is
201
202
    # Make a dict of fields to create
202
203
    create = {}
203
204
    for f in create_user_fields_required:
204
 
        try:
205
 
            create[f] = fields.getfirst(f)
206
 
        except AttributeError:
 
205
        val = fields.getfirst(f)
 
206
        if val is not None:
 
207
            create[f] = val
 
208
        else:
207
209
            req.throw_error(req.HTTP_BAD_REQUEST)
208
210
    for f in create_user_fields_optional:
209
 
        try:
210
 
            create[f] = fields.getfirst(f)
211
 
        except AttributeError:
 
211
        val = fields.getfirst(f)
 
212
        if val is not None:
 
213
            create[f] = val
 
214
        else:
212
215
            pass
213
216
 
214
217
    # Get the arguments for usermgt.create_user from the session
215
218
    # (The user must have already logged in to use this app)
216
219
    msg = {'create_user': create}
217
220
    # TEMP
218
 
    req.write(msg)
 
221
    req.write(repr(msg))
219
222
    return
220
223
    # END TEMP
221
224
 
257
260
    # Make a dict of fields to update
258
261
    update = {}
259
262
    for f in fieldlist:
260
 
        try:
261
 
            update[f] = fields.getfirst(f)
262
 
        except AttributeError:
 
263
        val = fields.getfirst(f)
 
264
        if val is not None:
 
265
            update[f] = val
 
266
        else:
263
267
            pass
264
268
 
265
269
    # Get the arguments for usermgt.create_user from the session
270
274
    }
271
275
    msg = {'update_user': args}
272
276
    # TEMP
273
 
    req.write(msg)
 
277
    req.write(repr(msg))
274
278
    return
275
279
    # END TEMP
276
280
 
278
282
        decode = False)
279
283
    req.content_type = "text/plain"
280
284
    req.write(response)
 
285
 
 
286
# Map action names (from the path)
 
287
# to actual function objects
 
288
actions_map = {
 
289
    "activate_me": handle_activate_me,
 
290
    "create_user": handle_create_user,
 
291
    "update_user": handle_update_user,
 
292
}