4.2.2.16. Package apps.widgets.smartgrid

Smartgrid widget module.

apps.widgets.smartgrid.MAX_COMMITMENTS = 5

Maximum number of commitments user can have at one time.

apps.widgets.smartgrid.NOSHOW_PENALTY_DAYS = 2

Number of days after event sign up which will incur no show penalty.

apps.widgets.smartgrid.NUM_GOLOW_ACTIONS = 3

Number of go low actions to display.

apps.widgets.smartgrid.SETUP_WIZARD_ACTIVITY = 'intro-video'

Slug of the activity used in the setup wizard.

4.2.2.16.1. Module apps.widgets.smartgrid.models

Smart Grid Game model definition.

class apps.widgets.smartgrid.models.Action(*args, **kwargs)[source]

Activity Base class.

Parameters:
  • id (AutoField) – Id
  • name (CharField) – The name of the action.
  • slug (SlugField) – A unique identifier of the action. Automatically generated if left blank.
  • title (CharField) – The title of the action.
  • image (ImageField) – Uploaded image for the activity. This will appear under the title when the action content is displayed.
  • video_id (CharField) – The id of the video (optional). Currently only YouTube video is supported. This is the unique id of the video as identified by the YouTube video url.
  • video_source (CharField) – The source of the video.
  • embedded_widget (CharField) – The name of the embedded widget (optional).
  • description (TextField) – The discription of the action. Uses Markdown formatting.
  • type (CharField) – The type of the actions.
  • pub_date (DateField) – Date from which the action will be available for users.
  • expire_date (DateField) – Date after which the action will be marked as expired.
  • unlock_condition (CharField) – if the condition is True, the action will be unlocked. Uses Makahiki Predicates.
  • unlock_condition_text (CharField) – The description of the unlock condition. It will be displayed to players when the lock icon is clicked.
  • related_resource (CharField) – The resource type this action related.
  • social_bonus (IntegerField) – Social bonus point value.
  • point_value (IntegerField) – The point value to be awarded.
get_action(action_type)[source]

Returns the concrete action object by type.

get_classname()[source]

Returns the classname.

class apps.widgets.smartgrid.models.ActionMember(*args, **kwargs)[source]

Represents the join between commitments and users. Has fields for commenting on a commitment and whether or not the commitment is currently active.

Parameters:
  • id (AutoField) – Id
  • user_id (ForeignKey) – User
  • action_id (ForeignKey) – Action
  • question_id (ForeignKey) – Question
  • submission_date (DateTimeField) – The submission date.
  • completion_date (DateField) – The completion date.
  • award_date (DateTimeField) – The award date.
  • approval_status (CharField) – The approval status.
  • social_bonus_awarded (BooleanField) – Is the social bonus awarded?
  • comment (TextField) – The comment from user submission.
  • social_email (TextField) – Email address of the person the user went with.
  • response (TextField) – The response of the submission.
  • admin_comment (TextField) – Reason for approval/rejection
  • image (ImageField) – Uploaded image for verification.
  • points_awarded (IntegerField) – Number of points to award for activities with variable point values.
  • created_at (DateTimeField) – Created at
  • updated_at (DateTimeField) – Updated at
  • admin_link (CharField) – Admin link
active()[source]

return active member

Sets admin_link if not already set.

days_left()[source]

Returns how many days are left before the user can submit the activity.

delete(using=None)[source]

Custom delete method to remove the points for completed action.

invalidate_cache()[source]

Invalidate the categories cache.

post_to_wall()[source]

post to team wall as system post.

save(*args, **kwargs)[source]

custom save method.

return the user first_name.

class apps.widgets.smartgrid.models.Activity(*args, **kwargs)[source]

Activities involve verifiable actions that users commit to. These actions can be verified by asking questions or posting an image attachment that verifies the user did the activity.

Parameters:
  • id (AutoField) – Id
  • name (CharField) – The name of the action.
  • slug (SlugField) – A unique identifier of the action. Automatically generated if left blank.
  • title (CharField) – The title of the action.
  • image (ImageField) – Uploaded image for the activity. This will appear under the title when the action content is displayed.
  • video_id (CharField) – The id of the video (optional). Currently only YouTube video is supported. This is the unique id of the video as identified by the YouTube video url.
  • video_source (CharField) – The source of the video.
  • embedded_widget (CharField) – The name of the embedded widget (optional).
  • description (TextField) – The discription of the action. Uses Markdown formatting.
  • type (CharField) – The type of the actions.
  • pub_date (DateField) – Date from which the action will be available for users.
  • expire_date (DateField) – Date after which the action will be marked as expired.
  • unlock_condition (CharField) – if the condition is True, the action will be unlocked. Uses Makahiki Predicates.
  • unlock_condition_text (CharField) – The description of the unlock condition. It will be displayed to players when the lock icon is clicked.
  • related_resource (CharField) – The resource type this action related.
  • social_bonus (IntegerField) – Social bonus point value.
  • point_value (IntegerField) – The point value to be awarded.
  • action_ptr_id (OneToOneField) – Action ptr
  • expected_duration (IntegerField) – Time (in minutes) that the activity is expected to take.
  • point_range_start (IntegerField) – Minimum number of points possible for a variable point activity.
  • point_range_end (IntegerField) – Maximum number of points possible for a variable point activity.
  • confirm_type (CharField) – If the type is ‘Question and Answer’, please provide the ‘Text prompt questions’ section below.
  • confirm_prompt (TextField) – Uses Markdown formatting.
  • admin_note (TextField) – Notes for admins when approving this activity. Uses Markdown formatting.
is_active()[source]

Determines if the activity is available for users to participate.

is_active_for_date(date)[source]

Determines if the activity is available for user participation at the given date.

pick_question(user_id)[source]

Choose a random question to present to a user.

class apps.widgets.smartgrid.models.ColumnGrid(*args, **kwargs)[source]

Defines the ColumnName positions in the Smart Grid.

Parameters:
  • id (AutoField) – Id
  • level_id (ForeignKey) – The level of the action.
  • column (IntegerField) – The column of the Smart Grid this Action is in.
  • name_id (ForeignKey) – The ColumnName in this location.
class apps.widgets.smartgrid.models.ColumnName(*args, **kwargs)[source]

ColumnNames are used to group actions in the Smart Grid.

Parameters:
  • id (AutoField) – Id
  • name (CharField) – The name of the column (max 255 characters).
  • slug (SlugField) – Automatically generated if left blank.
save(*args, **kwargs)[source]

Custom save method to set fields.

class apps.widgets.smartgrid.models.Commitment(*args, **kwargs)[source]

Commitments involve non-verifiable actions that a user can commit to. Typically, they will be worth fewer points than activities.

Parameters:
  • id (AutoField) – Id
  • name (CharField) – The name of the action.
  • slug (SlugField) – A unique identifier of the action. Automatically generated if left blank.
  • title (CharField) – The title of the action.
  • image (ImageField) – Uploaded image for the activity. This will appear under the title when the action content is displayed.
  • video_id (CharField) – The id of the video (optional). Currently only YouTube video is supported. This is the unique id of the video as identified by the YouTube video url.
  • video_source (CharField) – The source of the video.
  • embedded_widget (CharField) – The name of the embedded widget (optional).
  • description (TextField) – The discription of the action. Uses Markdown formatting.
  • type (CharField) – The type of the actions.
  • pub_date (DateField) – Date from which the action will be available for users.
  • expire_date (DateField) – Date after which the action will be marked as expired.
  • unlock_condition (CharField) – if the condition is True, the action will be unlocked. Uses Makahiki Predicates.
  • unlock_condition_text (CharField) – The description of the unlock condition. It will be displayed to players when the lock icon is clicked.
  • related_resource (CharField) – The resource type this action related.
  • social_bonus (IntegerField) – Social bonus point value.
  • point_value (IntegerField) – The point value to be awarded.
  • action_ptr_id (OneToOneField) – Action ptr
  • commitment_length (IntegerField) – Duration of commitment, in days.
class apps.widgets.smartgrid.models.ConfirmationCode(*args, **kwargs)[source]

Represents confirmation codes for activities.

Parameters:
  • id (AutoField) – Id
  • action_id (ForeignKey) – Action
  • code (CharField) – The confirmation code.
  • is_active (BooleanField) – Is the confirmation code still active?
  • user_id (ForeignKey) – The user who claimed the code.
  • create_date (DateTimeField) – Date the code was created.
  • printed_or_distributed (BooleanField) – Has the code been printed or distributed.
static generate_codes_for_activity(event, num_codes)[source]

Generates a set of random codes for the activity.

class apps.widgets.smartgrid.models.EmailReminder(*args, **kwargs)[source]

Email Reminder Class

Parameters:
  • id (AutoField) – Id
  • user_id (ForeignKey) – User
  • action_id (ForeignKey) – Action
  • send_at (DateTimeField) – The send time of the reminder.
  • sent (BooleanField) – Is reminder sent?
  • created_at (DateTimeField) – Created at
  • updated_at (DateTimeField) – Updated at
  • email_address (EmailField) – The email address.
send()[source]

Sends a reminder email to the user.

class apps.widgets.smartgrid.models.Event(*args, **kwargs)[source]

Events will be verified by confirmation code. It includes events and excursions.

Parameters:
  • id (AutoField) – Id
  • name (CharField) – The name of the action.
  • slug (SlugField) – A unique identifier of the action. Automatically generated if left blank.
  • title (CharField) – The title of the action.
  • image (ImageField) – Uploaded image for the activity. This will appear under the title when the action content is displayed.
  • video_id (CharField) – The id of the video (optional). Currently only YouTube video is supported. This is the unique id of the video as identified by the YouTube video url.
  • video_source (CharField) – The source of the video.
  • embedded_widget (CharField) – The name of the embedded widget (optional).
  • description (TextField) – The discription of the action. Uses Markdown formatting.
  • type (CharField) – The type of the actions.
  • pub_date (DateField) – Date from which the action will be available for users.
  • expire_date (DateField) – Date after which the action will be marked as expired.
  • unlock_condition (CharField) – if the condition is True, the action will be unlocked. Uses Makahiki Predicates.
  • unlock_condition_text (CharField) – The description of the unlock condition. It will be displayed to players when the lock icon is clicked.
  • related_resource (CharField) – The resource type this action related.
  • social_bonus (IntegerField) – Social bonus point value.
  • point_value (IntegerField) – The point value to be awarded.
  • action_ptr_id (OneToOneField) – Action ptr
  • expected_duration (IntegerField) – Time (in minutes) that the activity is expected to take.
  • event_date (DateTimeField) – Required for events.
  • event_location (CharField) – Location of the event
  • event_max_seat (IntegerField) – Specify the max number of seats available to the event.
is_event_completed()[source]

Determines if the event is completed.

class apps.widgets.smartgrid.models.Filler(*args, **kwargs)[source]

Filler action. It is always locked

Parameters:
  • id (AutoField) – Id
  • name (CharField) – The name of the action.
  • slug (SlugField) – A unique identifier of the action. Automatically generated if left blank.
  • title (CharField) – The title of the action.
  • image (ImageField) – Uploaded image for the activity. This will appear under the title when the action content is displayed.
  • video_id (CharField) – The id of the video (optional). Currently only YouTube video is supported. This is the unique id of the video as identified by the YouTube video url.
  • video_source (CharField) – The source of the video.
  • embedded_widget (CharField) – The name of the embedded widget (optional).
  • description (TextField) – The discription of the action. Uses Markdown formatting.
  • type (CharField) – The type of the actions.
  • pub_date (DateField) – Date from which the action will be available for users.
  • expire_date (DateField) – Date after which the action will be marked as expired.
  • unlock_condition (CharField) – if the condition is True, the action will be unlocked. Uses Makahiki Predicates.
  • unlock_condition_text (CharField) – The description of the unlock condition. It will be displayed to players when the lock icon is clicked.
  • related_resource (CharField) – The resource type this action related.
  • social_bonus (IntegerField) – Social bonus point value.
  • point_value (IntegerField) – The point value to be awarded.
  • action_ptr_id (OneToOneField) – Action ptr
class apps.widgets.smartgrid.models.Grid(*args, **kwargs)[source]

Defines the Smart Grid, holds the level, column, row, and Action.

Parameters:
  • id (AutoField) – Id
  • level_id (ForeignKey) – The level of the action.
  • column (IntegerField) – The column of the Smart Grid this Action is in.
  • row (IntegerField) – The row of the Smart Grid this Action is in.
  • action_id (ForeignKey) – The Action in this location.
class apps.widgets.smartgrid.models.Level(*args, **kwargs)[source]

Associates the actions to different levels.

Parameters:
  • id (AutoField) – Id
  • name (CharField) – The name of the level.
  • slug (SlugField) – Automatically generated if left blank.
  • priority (IntegerField) – Levels with lower values (higher priority) will be listed first.
  • unlock_condition (CharField) – if the condition is True, the level will be unlocked. Uses Makahiki Predicates.
  • unlock_condition_text (CharField) – The description of the unlock condition.
save(*args, **kwargs)[source]

Custom save method to set fields.

class apps.widgets.smartgrid.models.QuestionChoice(*args, **kwargs)[source]

Represents questions’s multiple choice

Parameters:
  • id (AutoField) – Id
  • question_id (ForeignKey) – Question
  • action_id (ForeignKey) – Action
  • choice (CharField) – The choice of question (max 255 characters).
class apps.widgets.smartgrid.models.Reminder(*args, **kwargs)[source]

Sends a reminder for an activity to a user. Reminders are queued up and sent later.

Parameters:
  • user_id (ForeignKey) – User
  • action_id (ForeignKey) – Action
  • send_at (DateTimeField) – The send time of the reminder.
  • sent (BooleanField) – Is reminder sent?
  • created_at (DateTimeField) – Created at
  • updated_at (DateTimeField) – Updated at
class Meta[source]

meta

Reminder.send()[source]

send methods that subclass all required to implement.

class apps.widgets.smartgrid.models.TextPromptQuestion(*args, **kwargs)[source]

Represents questions that can be asked of users in order to verify participation in activities.

Parameters:
  • id (AutoField) – Id
  • action_id (ForeignKey) – Action
  • question (TextField) – The question text.
  • answer (CharField) – The answer of question (max 255 characters).
class apps.widgets.smartgrid.models.TextReminder(*args, **kwargs)[source]

Text Reminder Class

Parameters:
  • id (AutoField) – Id
  • user_id (ForeignKey) – User
  • action_id (ForeignKey) – Action
  • send_at (DateTimeField) – The send time of the reminder.
  • sent (BooleanField) – Is reminder sent?
  • created_at (DateTimeField) – Created at
  • updated_at (DateTimeField) – Updated at
  • text_number (PhoneNumberField) – The phone number.
  • text_carrier (CharField) – The phone carrier.
send()[source]

Sends a reminder text to the user via an email.

apps.widgets.smartgrid.models.activity_image_file_path(instance=None, filename=None, user=None)[source]

Returns the file path used to save an activity confirmation image.

4.2.2.16.2. Module apps.widgets.smartgrid.views

Prepares the rendering of Smart Grid Game widget.

apps.widgets.smartgrid.views.action_admin(request, *args, **kwargs)[source]

handle the action admin.

apps.widgets.smartgrid.views.action_admin_list(request, *args, **kwargs)[source]

handle the action admin.

apps.widgets.smartgrid.views.add_action(request, *args, **kwargs)[source]

Handle the Submission of the task.

apps.widgets.smartgrid.views.bulk_change(request, *args, **kwargs)[source]

Handle change level from admin interface.

apps.widgets.smartgrid.views.drop_action(request, *args, **kwargs)[source]

Handle the drop task request.

apps.widgets.smartgrid.views.supply(request, page_name)[source]

Supplies view_objects for smartgrid widgets.

apps.widgets.smartgrid.views.view_action(request, *args, **kwargs)[source]

individual action page

4.2.2.16.3. Module apps.widgets.smartgrid.forms

Forms for activity.

class apps.widgets.smartgrid.forms.ActivityCodeForm(*args, **kwargs)[source]

confirmation code form.

clean()[source]

Custom validation to verify confirmation codes.

class apps.widgets.smartgrid.forms.ActivityFreeResponseForm(*args, **kwargs)[source]

Free response form.

class apps.widgets.smartgrid.forms.ActivityFreeResponseImageForm(*args, **kwargs)[source]

Free response and image upload form.

class apps.widgets.smartgrid.forms.ActivityImageForm(*args, **kwargs)[source]

Image upload form.

class apps.widgets.smartgrid.forms.ActivityTextForm(*args, **kwargs)[source]

Text form.

clean()[source]

Custom validation to verify confirmation codes.

class apps.widgets.smartgrid.forms.ChangeLevelForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False)[source]

change level form.

class apps.widgets.smartgrid.forms.CommitmentCommentForm(*args, **kwargs)[source]

commitment comment form.

clean_social_email()[source]

Check if this social_email is valid.

class apps.widgets.smartgrid.forms.EventCodeForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False)[source]

event code form in the upcoming event widget.

class apps.widgets.smartgrid.forms.GenerateCodeForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False)[source]

Form for generating confirmation codes.

class apps.widgets.smartgrid.forms.ReminderForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False)[source]

reminder form.

clean()[source]

validate form.

class apps.widgets.smartgrid.forms.SurveyForm(*args, **kwargs)[source]

survey form.

4.2.2.16.4. Module apps.widgets.smartgrid.admin

Admin definition for Smart Grid Game widget.

class apps.widgets.smartgrid.admin.ActionAdmin(model, admin_site)[source]

abstract admin for action.

copy_action(request, queryset)[source]

Copy the selected Actions.

delete_selected(request, queryset)[source]

override the delete selected.

class apps.widgets.smartgrid.admin.ActionMemberAdmin(model, admin_site)[source]

ActionMember Admin.

admin_note(obj)[source]

return the short question.

approve_selected(request, queryset)[source]

delete priority.

changelist_view(request, extra_context=None)[source]

Set the default filter of the admin view to pending. Based on iridescent’s answer to http://stackoverflow.com/questions/851636/default-filter-in-django-admin

delete_selected(request, queryset)[source]

override the delete selected.

form

alias of ActionMemberAdminForm

full_response(obj)[source]

return the full response.

get_form(request, obj=None, **kwargs)[source]

Override to remove the points_awarded field if the action does not have variable points.

short_question(obj)[source]

return the short question.

short_response(obj)[source]

return the short response

class apps.widgets.smartgrid.admin.ActionMemberAdminForm(*args, **kwargs)[source]

Activity Member admin.

class Meta[source]

Meta

model

alias of ActionMember

ActionMemberAdminForm.clean()[source]

Custom validator that checks values for variable point activities.

class apps.widgets.smartgrid.admin.ActivityAdmin(model, admin_site)[source]

Activity Admin

form

alias of ActivityAdminForm

class apps.widgets.smartgrid.admin.ActivityAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)[source]

Activity Admin Form.

class Meta[source]

Meta

model

alias of Activity

ActivityAdminForm.clean()[source]

Validates the admin form data based on a set of constraints. 1. If the verification type is “image” or “code”, then a confirm prompt is required. 2. Publication date must be before expiration date. 3. Either points or a point range needs to be specified.

ActivityAdminForm.clean_unlock_condition()[source]

Validates the unlock conditions of the action.

class apps.widgets.smartgrid.admin.ColumnNameAdmin(model, admin_site)[source]

ColumnName Admin

class apps.widgets.smartgrid.admin.CommitmentAdmin(model, admin_site)[source]

Commitment Admin.

form

alias of CommitmentAdminForm

get_urls()[source]

override the url definition.

class apps.widgets.smartgrid.admin.CommitmentAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)[source]

admin form

class Meta[source]

meta

model

alias of Commitment

CommitmentAdminForm.clean_unlock_condition()[source]

Validates the unlock conditions of the action.

class apps.widgets.smartgrid.admin.ConfirmationCodeAdmin(model, admin_site)[source]

admin for Bonus Points.

delete_selected(request, queryset)[source]

override the delete selected method.

print_selected(request, queryset)[source]

Changes the printed_or_distributed flag to True for the selected Confirmation Codes.

view_codes(request, queryset)[source]

Views the Codes for printing.

view_selected(request, queryset)[source]

Views the Codes for printing.

class apps.widgets.smartgrid.admin.EmailReminderAdmin(model, admin_site)[source]

reminder admin

class apps.widgets.smartgrid.admin.EventAdmin(model, admin_site)[source]

Event Admin

form

alias of EventAdminForm

class apps.widgets.smartgrid.admin.EventAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)[source]

Event Admin Form.

class Meta[source]

Meta

model

alias of Event

EventAdminForm.clean()[source]

Validates the admin form data based on a set of constraints.

  1. Events must have an event date.
  2. Publication date must be before expiration date.
EventAdminForm.clean_unlock_condition()[source]

Validates the unlock conditions of the action.

class apps.widgets.smartgrid.admin.FillerAdmin(model, admin_site)[source]

Commitment Admin.

form

alias of FillerAdminForm

get_urls()[source]

override the url definition.

class apps.widgets.smartgrid.admin.FillerAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)[source]

admin form

class Meta[source]

meta

model

alias of Filler

class apps.widgets.smartgrid.admin.LevelAdmin(model, admin_site)[source]

Level Admin

form

alias of LevelAdminForm

class apps.widgets.smartgrid.admin.LevelAdminForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.util.ErrorList'>, label_suffix=':', empty_permitted=False, instance=None)[source]

admin form

class Meta[source]

meta

model

alias of Level

LevelAdminForm.clean_unlock_condition()[source]

Validates the unlock conditions of the action.

class apps.widgets.smartgrid.admin.QuestionChoiceInline(parent_model, admin_site)[source]

Question Choice admin.

model

alias of QuestionChoice

class apps.widgets.smartgrid.admin.TextQuestionInline(parent_model, admin_site)[source]

Text Question admin.

formset

alias of TextQuestionInlineFormSet

model

alias of TextPromptQuestion

class apps.widgets.smartgrid.admin.TextQuestionInlineFormSet(data=None, files=None, instance=None, save_as_new=False, prefix=None, queryset=None, **kwargs)[source]

Custom formset model to override validation.

clean()[source]

Validates the form data and checks if the activity confirmation type is text.

class apps.widgets.smartgrid.admin.TextReminderAdmin(model, admin_site)[source]

reminder admin

apps.widgets.smartgrid.admin.redirect_urls(model_admin, url_type)[source]

change the url redirection.

4.2.2.16.5. Module apps.widgets.smartgrid.management.commands.process_notices

Invocation: python manage.py process_notices send out notifications such as round transition, commitment end, and process rsvps. should be scheduled daily at the beginning of the day.

class apps.widgets.smartgrid.management.commands.process_notices.Command(*args, **kwargs)[source]

command

handle(*args, **options)[source]

process daily notices

4.2.2.16.6. Module apps.widgets.smartgrid.management.commands.send_reminders

Invocation: python manage.py send_reminders send out reminders. Normally is scheduled hourly.

class apps.widgets.smartgrid.management.commands.send_reminders.Command(*args, **kwargs)[source]

command

handle(*args, **options)[source]

send reminders