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

« back to all changes in this revision

Viewing changes to lib/common/db.py

  • Committer: drtomc
  • Date: 2008-03-04 04:54:09 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:641
console: slightly more aggressive output buffering - wait till we've at least
    128 bytes of output. Leads to much better perception of performance by
    significantly reducing the network overheads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
        Raises a DBException if the dictionary contains invalid fields.
141
141
        """
142
142
        if not DB.check_dict(dict, tablefields, disallowed):
143
 
            raise DBException("Supplied dictionary contains invalid fields.")
 
143
            extras = set(dict.keys()) - tablefields
 
144
            raise DBException("Supplied dictionary contains invalid fields. (%s)" % (repr(extras)))
144
145
        # Build two lists concurrently: field names and values, as SQL strings
145
146
        fieldnames = []
146
147
        values = []
289
290
        "rolenm", "studentid", "acct_exp", "pass_exp", "last_login", "svn_pass"
290
291
    ]
291
292
    login_fields = frozenset(login_fields_list)
292
 
    # Do not return passhash when reading from the DB
293
 
    login_getfields = login_fields - frozenset(["passhash"])
294
293
 
295
294
    def create_user(self, user_obj=None, dry=False, **kwargs):
296
295
        """Creates a user login entry in the database.
331
330
            # else, we'll trust the user, but it SHOULD be "no_agreement"
332
331
            # (We can't change it because then the user object would not
333
332
            # reflect the DB).
 
333
        if 'local_password' in fields:
 
334
            del fields['local_password']
334
335
        # Execute the query.
335
336
        return self.insert(fields, "login", self.login_fields, dry=dry)
336
337
 
365
366
        Raises a DBException if the login is not found in the DB.
366
367
        """
367
368
        userdict = self.get_single({"login": login}, "login",
368
 
            self.login_getfields, self.login_primary,
 
369
            self.login_fields, self.login_primary,
369
370
            error_notfound="get_user: No user with that login name", dry=dry)
370
371
        if dry:
371
372
            return userdict     # Query string
375
376
    def get_users(self, dry=False):
376
377
        """Returns a list of all users in the DB, as User objects.
377
378
        """
378
 
        userdicts = self.get_all("login", self.login_getfields, dry=dry)
 
379
        userdicts = self.get_all("login", self.login_fields, dry=dry)
379
380
        if dry:
380
381
            return userdicts    # Query string
381
382
        # Package into User objects