The CUED People database

The cuedmembers application contains models and logic to maintain a shadow copy of a list of CUED members. It augments the builtin django.contrib.auth.User model with information about a member of CUED. This includes:

  • The full list of “first names”;
  • Their research group and division (if any); and
  • Whether they are a current member of CUED.

Members

class cuedmembers.models.Member(*args, **kwargs)[source]

An extension of the standard Django User to indicate that a particular user is a member of the Department.

There is a one-to-one mapping of Users to Members however not every User is necessarily a Member.

Note

While there is nothing stopping you adding a foreign-key to a Member in models, its better to add a foreign-key to a User. That way you app’s models are decoupled from relying on the CUED membership database and may be of wider user.

The “Surname” and “Preferred name” fields from the Department are mapped through to the associated User’s last_name and first_name. The “First names” provided by the Department are stored in this model.

An “active” member is currently present at CUED.

Information in this model is expected to be provided by the Department. See http://www-itsd.eng.cam.ac.uk/datadownloads/support/div_people.html for some discussion of what the fields mean.

Note that is_active is the primary means by which one should judge if a Member is currently a member of the Department.

This model does not include role/course, host/supervisor, room number or phone number. The “arrived” flag is folded into the is_active field.

user

The django.contrib.auth.models.User associated with this Member.

first_names

A string containing the first names for the member supplied by the Department. Although it is tempting to use a space as a separator for these, that way danger lies!

research_group

The ResearchGroup which this member is a part of.

is_active

Members are not usually deleted from the database. Instead they become “active” or “inactive”. This is to allow for the same person to be considered as the same person if they leave CUED and then subsequently return.

crsid

This member’s CRSid. The CRSid is the username of the associated user.

This property merely returns the username of the associated User.

class cuedmembers.models.MemberManager[source]

A specialised Manager for Member instances.

active()[source]

A query-set of active users.

inactive()[source]

A query-set of inactive users.

update_or_create_by_crsid(crsid, defaults=None)[source]

Retrieve or create a new member from a crsid. If a corresponding user does not exist, it is created. The newly created user has set_unusable_password() called on it and is added to the database.

The first_name, last_name and email entries in defaults are set on the corresponding user and any other values are set on the member.

See the update_or_create() documentation for discussion of the defaults parameter.

cuedmembers.get_member_group()[source]

CUED members who are active are a member of a group. Membership of this group is automatic for those members who have is_active set to True when imported from CSV via csv.read_members_from_csv().

Note

The group membership is not automatically updated when save() is called on the models.Member model. This is because only advanced users who know what they’re doing should be fiddling with the database model directly!

By default this group is called “CUED Members” but the name may be overridden by setting the CUED_MEMBERS_GROUP setting.

Departmental structure

The Department is structure into Divisions which comprise separate Research Groups. The cuedmembers app ships with a fixture which is automatically loaded into the database at migrate-time which contains the current Divisions and Research Groups.

class cuedmembers.models.Division(*args, **kwargs)[source]

A division within CUED. The primary key for a division is actually its letter, A-F.

letter

The Divisional ID letter, A-F.

name

A human-readable name for the Division.

class cuedmembers.models.ResearchGroup(*args, **kwargs)[source]

A research group in CUED.

division

The Division which this research group is a part of.

name

A human-readable name for the Research Group.

Settings

CUED_MEMBERS_GROUP
String giving the name of the group created or returned by get_member_group().

Management commands

Synchronising membership data via CSV files

The importcuedmembers management command is used to synchronise the membership database with an authoritative source.

The Department provide CSV dumps of CUED membership. See http://www-itsd.eng.cam.ac.uk/datadownloads/support/div_people.html for more details. This command allows the ingestion of a CSV file in the format outlined at that page into the database.

Members listed in the CSV file are created if they don’t exist. Their personal details, such as first name, surname, etc. are updated from the CSV. A previously active member who does not appear in the CSV file is marked inactive. Similarly, a previously inactive member who appears in the CSV file is marked active.

By default, an email address of <crsid>@cam.ac.uk is used for each member. This can be configured through the --email-domain argument.

This command can take either a path to a CSV file on the local system or a http or https URL to a CSV file located on a remote server.