rfid_lock_management Package

rfid_lock_management

admin

class rfid_lock_management.admin.AccessTimeAdmin(model, admin_site)[source]

Bases: django.contrib.admin.options.ModelAdmin

actions = None
change_view(request, extra_context=None)[source]

Don’t allow access to individual AccessTime objects.

No need to show the link to page for an individual AccessTime, so no field should link to it, as was set in changelist_view. However, the page can still be accessed, so redirect to change list.

changelist_view(request, extra_context=None)[source]

Don’t show links to individual AccessTime change forms from any field. (list_display_links = [] will not works - will default to linking from items in AccessTime column.

date_hierarchy = 'access_time'
has_add_permission(request, obj=None)[source]

Don’t display Save And Add button

has_delete_permission(request, obj=None)[source]

Don’t display “delete” button

list_display = ('access_time', 'lockuser_html_heading', 'door')
list_filter = ('lockuser', 'door')
lockuser_html_heading(obj)[source]

Returns the HTML with link to lock user’s change_form to display on the Access Times change list page.

media
class rfid_lock_management.admin.LockUserAdmin(model, admin_site)[source]

Bases: django.contrib.admin.options.ModelAdmin

Encapsulates all admin options and functionality for a given model.

actions = (<function deactivate at 0x102c60d70>,)
change_view(request, object_id, form_url='', extra_context=None)[source]

LockUser may have access to Doors that the staff user cannot admin; this must be accounted for when determining (Javascript) whether to disable “Assign keycard” button or select “Deactivate keycard” because all Doors have been unchecked. In change_form template, will get a set of these Door objects from context, then check the lockuser_set of each to see if the current lockuser has access to it.

deactivate(request, queryset)[source]

Staff should not have the ability to delete LockUsers, only to DEACTIVATE them.

Before deactivating, this checks if the LockUser is permitted doors that the staff user is not. This would mean that the staff user is not allowed to revoke the keycard, and the lock user would remain active.

fieldsets = ((None, {'fields': (('first_name', 'last_name'), 'email', 'phone_number', 'address', 'prettify_get_current_rfid', 'last_access_time_and_door_and_link_to_more', 'doors', 'deactivate_current_keycard')}),)
form

alias of LockUserForm

formfield_for_manytomany(db_field, request, **kwargs)[source]

The queryset() method in DoorAdmin restricts a staff user’s ability to view/change Doors that they do not have permission for (individual objects and change list). But on the listdisplay and changeform for LockUsers, staff users can still see Doors – and assign them – that they don’t have permission for. So here, we need to to limit the ManyToMany Door field output for the LockUser.

formfield_overrides = {<class 'django.db.models.fields.related.ManyToManyField'>: {'widget': <class 'django.forms.widgets.CheckboxSelectMultiple'>}}
get_doors_to_show(request)[source]
get_form(request, obj=None, **kwargs)[source]
get_other_doors(request, object_id)[source]

Doors that the staff User is not allowed to administer. In change_form template, will get a set of these Door objects from context, then check the lockuser_set of each to see if the current lockuser has access to it.

has_delete_permission(request, obj=None)[source]

Don’t display “delete” button

list_display = ('first_name', 'last_name', 'email', 'is_active', '_current_rfid_heading', '_doors_heading', '_last_access_heading')
list_filter = ('doors',)
media
readonly_fields = ('prettify_get_current_rfid', 'last_access_time_and_door_and_link_to_more', 'prettify_get_last_access_time')
save_model(request, obj, form, change)[source]

If deactivate current keycard was checked (which may have actually happened in clean, if no Doors were selected) need to deactivate current keycard. Doing this here rather than models.py because need to attach request.user to the RFIDkeycard object being deactivated, to record revoker.

class rfid_lock_management.admin.LockUserForm(*args, **kwargs)[source]

Bases: django.forms.models.ModelForm

class Meta[source]
model

alias of LockUser

LockUserForm.base_fields = {'first_name': <django.forms.fields.CharField object at 0x102c74290>, 'last_name': <django.forms.fields.CharField object at 0x102c74490>, 'email': <django.forms.fields.EmailField object at 0x102c74550>, 'address': <django.forms.fields.CharField object at 0x102c74610>, 'phone_number': <django.forms.fields.CharField object at 0x102c746d0>, 'birthdate': <django.forms.fields.DateField object at 0x102c74790>, 'doors': <django.forms.models.ModelMultipleChoiceField object at 0x102c749d0>, 'deactivate_current_keycard': <django.forms.fields.BooleanField object at 0x102c74950>, 'current_keycard_revoker': <django.forms.models.ModelChoiceField object at 0x102c74c10>}
LockUserForm.clean()[source]

If no Doors were selected – if user is not permitted to access any door – deactivate associated keycard.

If the user is permitted access to doors that the staff user is not permitted access, make sure lockuser still has access to door staff user is not permitted to manage, since those wouldn’t be on the form. Also, if ‘deactivate current keycard’ was checked in this situation, the keycard should NOT actually be revoked, because of those other doors.

LockUserForm.declared_fields = {}
LockUserForm.media

models

class rfid_lock_management.models.AccessTime(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Represents a visit to a space

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception AccessTime.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

AccessTime.door
AccessTime.get_this_lockuser_html()[source]

Returns the HTML with link to /lockuser/the_id/ to display on the AccessTime change list page

AccessTime.lockuser
AccessTime.objects = <django.db.models.manager.Manager object at 0x102c70410>
class rfid_lock_management.models.Door(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Doors with RFID locks installed.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception Door.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

Door.accesstime_set
Door.get_allowed_rfids()[source]

Return the RFIDs allowed to access this Door

Door.lockuser_set
Door.objects = <django.db.models.manager.Manager object at 0x102c6d190>
Door.save(*args, **kwargs)[source]

When a new Door is added, create a corresponding Permission, if it does not exist already.

class rfid_lock_management.models.LockUser(*args, **kwargs)[source]

Bases: django.db.models.base.Model

(Despite the misleading name, LockUsers are not subclassed Users, but subclassed Models.)

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception LockUser.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

LockUser.accesstime_set
LockUser.current_keycard_revoker
LockUser.doors
LockUser.get_all_access_times()[source]

Returns list of all access times (the actual access_time field, not the objects) for this user, which means that the search should include any other RFID’s this LockUser ever had. In other words, the search is by person, not by RFID.

LockUser.get_all_rfids()[source]

Get all RFID’s associated with this LockUser

LockUser.get_all_rfids_html()[source]

Returns HTML for displaying list of all keycards (excluding curent, if any). Includes date assigned and date revoked, as well as rfid number.

LockUser.get_allowed_doors()[source]

Get the Doors this user is allowed access to.

Returns the HTML with links to /door/the_id/ to display on the LockUser change list page.

LockUser.get_current_rfid()[source]

Of all RFID’s associated with this LockUser, get the one that’s active, i.e. has not been revoked.

LockUser.get_last_access_time()[source]

Get the last time this person used the lock. Same story with current RFID vs previous one as in the comment for get_all_access_time().

LockUser.is_active()[source]

Useful in LockUser’s list display

Including link to all access times (for change form)

Including link to all access times (for change form)

LockUser.objects = <django.db.models.manager.Manager object at 0x102c74210>
LockUser.prettify_get_allowed_doors()[source]
LockUser.prettify_get_current_rfid()[source]

Returns results of get_current_rfid(), but as a nice pretty string. Also display date assigned as well as rfid number on LockUser change form and list display.

LockUser.prettify_get_last_access_time()[source]
LockUser.prettify_get_last_access_time_and_door()[source]

Includes the door this access time is associated with (for change list)

LockUser.rfidkeycard_set
LockUser.save(*args, **kwargs)[source]

Overriding save(): - We’ll deactivate a LockUser’s current keycard here, if

deactivate_current_keycard is checked on the LockUser’s change_form.
  • If we’re assigning a new keycard, the keycard is created and saved here.
class rfid_lock_management.models.NewKeycardScan(*args, **kwargs)[source]

Bases: django.db.models.base.Model

For checking whether the current request is for authenticating a keycard or assigning new keycard.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception NewKeycardScan.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

NewKeycardScan.assigner_user
NewKeycardScan.get_next_by_time_initiated(*moreargs, **morekwargs)
NewKeycardScan.get_previous_by_time_initiated(*moreargs, **morekwargs)
NewKeycardScan.objects = <django.db.models.manager.Manager object at 0x102c6d790>
NewKeycardScan.timed_out(minutes=2)[source]

Check whether specified number of minutes have passed since staff user indicated they were going to go scan in a card in order to assign it, and return True if so.

class rfid_lock_management.models.RFIDkeycard(*args, **kwargs)[source]

Bases: django.db.models.base.Model

Door access represented by a (potentially reusable) RFID keycard (or keyfob or whatever) assigned to a LockUser.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception RFIDkeycard.MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

RFIDkeycard.assigner
RFIDkeycard.deactivate(user)[source]
RFIDkeycard.get_allowed_doors()[source]

Get the Doors this user is allowed access to.

RFIDkeycard.get_next_by_date_created(*moreargs, **morekwargs)
RFIDkeycard.get_previous_by_date_created(*moreargs, **morekwargs)
RFIDkeycard.is_active()[source]

If there is a date_revoked, the keycard is not active.

RFIDkeycard.lockuser
RFIDkeycard.objects = <django.db.models.manager.Manager object at 0x102c6de90>
RFIDkeycard.revoker
rfid_lock_management.models.create_testuser(app, created_models, verbosity, **kwargs)[source]

views

rfid_lock_management.views.chartify(request, *args, **kwargs)[source]

Return data in appropriate format for the HighCharts (JavaScript) AccessTime plot. Creates a series for each door.

rfid_lock_management.views.check(request, doorid, rfid)[source]

In addition to checking whether the given rfid is valid for the given door, this checks whether we’re actually trying to assign a new keycard rather than authenticating. If not doing a new keycard scan, create and save an AccessTime.

rfid_lock_management.views.do_json_resp(success, message)[source]
rfid_lock_management.views.finished_new_keycard_scan(request, *args, **kwargs)[source]

Verify this is the NewKeycardScan object we initiated, that the rfid is not the same as that of a currently active keycard, and that we haven’t timed out. Then get the rfid from the newly-scanned card.

The new RFIDkeycard object is created upon LockUser save, after change_form form has been submitted.

rfid_lock_management.views.get_allowed_rfids(request, doorid)[source]

Returns list of allowed rfid’s for the specified door in JSON format

rfid_lock_management.views.initiate_new_keycard_scan(request, *args, **kwargs)[source]

Try start waiting for new keycard scan; return success/fail message.

Table Of Contents

Previous topic

Unit and functional tests

Next topic

Other

This Page