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

« back to all changes in this revision

Viewing changes to ivle/util.py

  • Committer: William Grant
  • Date: 2010-02-15 05:37:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215053750-hihmegnp8e7dshc2
Ignore test coverage files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    This is the old "standard" exception class for IVLE errors. It is only
32
32
    used in fileservice, and should not be used in any new code.
33
33
    """
 
34
 
 
35
    message = None
 
36
 
34
37
    def __init__(self, httpcode, message=None):
35
38
        self.httpcode = httpcode
36
39
        self.message = message
257
260
        os.rmdir(path)
258
261
    except os.error:
259
262
        onerror(os.rmdir, path, sys.exc_info())
 
263
 
 
264
def format_submission_principal(user, principal):
 
265
    """Render a list of users to fit in the offering project listing.
 
266
 
 
267
    Given a user and a list of submitters, returns 'solo' if the
 
268
    only submitter is the user, or a string of the form
 
269
    'with A, B and C' if there are any other submitters.
 
270
 
 
271
    If submitters is None, we assume that the list of members could
 
272
    not be determined, so we just return 'group'.
 
273
    """
 
274
    if principal is None:
 
275
        return 'group'
 
276
 
 
277
    if principal is user:
 
278
        return 'solo'
 
279
 
 
280
    display_names = sorted(
 
281
        member.display_name for member in principal.members
 
282
        if member is not user)
 
283
 
 
284
    if len(display_names) == 0:
 
285
        return 'solo (%s)' % principal.name
 
286
    elif len(display_names) == 1:
 
287
        return 'with %s (%s)' % (display_names[0], principal.name)
 
288
    elif len(display_names) > 5:
 
289
        return 'with %d others (%s)' % (len(display_names), principal.name)
 
290
    else:
 
291
        return 'with %s and %s (%s)' % (', '.join(display_names[:-1]),
 
292
                                        display_names[-1], principal.name)