herobase
The herobase app contains the core functionality of You are Hero.
The Basic models are Quest, UserProfile and Adventure, a model which
describes the relation between Quests and Users.
Models
This module provides all the basic Quest related models for You are HERO.
The most important are Quest, Userprofile (represents a hero) and Adventure.
This module also contains the ActionMixin, which provides basic logic for model actions.
The model actions connect state logic to the models.
-
class herobase.models.Adventure(*args, **kwargs)[source]
Model the relationship between a User and a Quest she is engaged in.
-
accept(*args, **kwargs)[source]
Accept adventure.user as a participant and send a notification.
-
done(*args, **kwargs)[source]
Confirm a users participation in a quest.
-
refuse(*args, **kwargs)[source]
Deny adventure.user participation in the quest.
-
class herobase.models.AdventureManager[source]
Custom Object Manager for Adventures, excluding canceled ones.
-
active()[source]
Show only adventures that have not been canceled.
-
class herobase.models.Quest(*args, **kwargs)[source]
A quest, owned by a user.
-
accepted_heroes()[source]
Return all accepted heroes and following states (heros who
are done or claim so)
-
active_heroes()[source]
Return all heroes active on a quest. These are accepted heroes
and heroes who claim to be done.
-
applying_heroes()[source]
Return all heroes, applying for the quest.
-
cancel(*args, **kwargs)[source]
Cancels the whole quest.
-
check_full(request=None)[source]
Calculates if quest is full or not. Needs to be called when
a hero is accepted or cancels his adventure.
-
clean()[source]
Clean function for form validation: Max XPs are associated to quest level
-
done(*args, **kwargs)[source]
Mark the quest as done. The quest is complete and inactive.
-
get_absolute_m_url()[source]
Get the url for this quests detail page.
-
get_absolute_url(*moreargs, **morekwargs)[source]
Get the url for this quests detail page.
-
classmethod get_suggested_quests(user, count)[source]
Return a (random) list of suggested quests for the user.
-
hero_apply(*args, **kwargs)[source]
Applies a hero to the quest and create an adventure for her.
-
hero_cancel(*args, **kwargs)[source]
Cancels an adventure on this quest.
-
needs_attention()[source]
Only for playtest. Later there should be Notifications for this.
-
remaining_slots()[source]
Number of heroes who may participate in the quest until maximum
number of heroes is achieved
-
class herobase.models.QuestManager[source]
Custom Quest Object Manager, for active and inactive Quest objects
-
class herobase.models.UserProfile(*args, **kwargs)[source]
This model extends a django user with additional hero information.
-
avatar()[source]
Return a String, containing a path to a thumbnail-image 270x270.
-
avatar_thumb[source]
Return a String, containing a path to a thumbnail-image 40x40.
-
avatar_thumbnails()[source]
Return a list of avatar thumbnails 50x50
-
avatar_thumbnails_tiny()[source]
Return a list of avatar thumbnails 15x15
-
level[source]
Calculate the user’s level based on her experience
-
relative_level_experience()[source]
Calculates percentage of XP for current level.
-
unread_messages_count[source]
Return number of unread messages.
-
herobase.models.create_user_profile(sender, instance, created, **kwargs)[source]
Create a user profile on user account creation.
-
herobase.models.get_system_user()[source]
Return an unique system-user. Creates one if not existing.
-
herobase.models.login_on_activation(sender, user, request, **kwargs)[source]
Logs in the user after activation
Views
The Views module provide view functions, which were called by the
url dispatcher,
and aggregate some data for use in templates.
-
class herobase.views.QuestCreateView(**kwargs)[source]
Basic Quest create view. This generic view-class should be refactored to a normal view function
-
form_class
alias of QuestCreateForm
-
herobase.views.abstract(request)[source]
static you are hero abstract view.
-
herobase.views.hero_classes(request)[source]
static view for explaining hero classes.
-
herobase.views.home_view(request)[source]
Proxy view for switching between the hero and the public home view
-
herobase.views.m_home_view(request)[source]
Proxy view for switching between the hero and the public home view
-
herobase.views.quest_detail_view(request, quest_id, template='herobase/quest/detail.html')[source]
Render detail template for quest, and adventure if it exists.
-
herobase.views.signups(request)[source]
Special view for nosy developers.
Tests
This file demonstrates writing tests using the unittest module.
These will pass when you run “manage.py test”.
Some tests...
-
class herobase.tests.AuthenticatedIntegrationTest(methodName='runTest')[source]
Integration tests for protected part of the homepage.
-
setUp()[source]
Start with logged in user
-
test_authenticated_homepage()[source]
check for username on home view.
-
test_logged_in()[source]
check login
-
test_quest_create()[source]
A user should be able to create a quest.
-
test_quest_detail()[source]
A owner should be able to see his quest detail-view and a hero applying for that quest.
-
test_quest_details_as_hero()[source]
A hero can see quest-details.
-
test_quest_details_as_owner()[source]
An owner can see quest-details.
-
test_quest_list()[source]
A user should be able to visit the quest-list-view.
-
test_stats()[source]
A user should be able to see the statistics.
-
test_suggested_quests()[source]
A user should be presented with quest suggestions.
-
test_user_edit()[source]
A user should be able to see his userprofile-edit-form.
-
test_user_profile()[source]
A user should be able to see another users public profile.
-
test_user_security_edit()[source]
A user should be able to see his userprofile-privacy-settings-form.
-
class herobase.tests.QuestTest(methodName='runTest')[source]
Basic Unittests for Quest cycle. (applay, accept, cancel, done, ...)
-
test_adventure_done()[source]
A hero should be able to mark his adventure as “done”, if he was accepted.
-
test_adventure_done_hero_actions()[source]
If my adventure is done, I’m not able to cancel or apply for the quest again.
-
test_adventure_done_owner_actions()[source]
If a hero is done with an adventure, the owner is not able to accept, refuse or mark him done again.
-
test_check_quest_full()[source]
A quest with max_heroes=1 should be full, if there is one accepted hero.
-
test_check_quest_not_full()[source]
A quest with max_heroes=2, shoould be open with one accepted hero.
-
test_hero_apply()[source]
If there is a open quest, and I’m not the owner, I should be able to apply for that quest.
-
test_hero_apply_full_not_valid()[source]
If the quest is full, I should not be able to apply for the quest.
-
test_hero_cancel()[source]
If I’m a hero, participating in a quest, I should be able to cancel my participation.
-
test_hero_cancel_not_valid()[source]
If I’m a hero, not participating in a quest, I should not be able to cancel.
-
test_invalid_action_raises_value_error()[source]
Not allowed action should raise an exception.
-
test_other_cancel_denied()[source]
If I’m not the owner and I try to process the “cancel” action, I get an exception.
-
test_other_cancel_not_valid()[source]
If I’m not the owner, I should not be able to cancel the quest.
-
test_owner_accept()[source]
If I’m the owner of a open quest, and a hero is applying, I should be able to accept her.
-
test_owner_cancel()[source]
If there is a open quest, the owner should be able to cancel that quest.
-
test_owner_done_done_not_valid()[source]
If my quest is already marked as “done”, i should not be able to mark it again.
-
test_owner_done_no_heroes()[source]
If there was no hero accepted for my quest, I can’t mark the quest as “done”.
-
test_owner_done_valid()[source]
If there is at least one accepted hero for my quest, I should be able to mark the quest as “done”.
-
test_owner_refuse()[source]
The owner is able to refuse a applying hero.
-
class herobase.tests.UnauthenticatedIntegrationTest(methodName='runTest')[source]
Integration Tests for the public part of the Homepage. Some things should be seen, other not.
-
test_homepage()[source]
Check if there is any response, and check for a “join”-button in the home-view.
-
test_quest_create()[source]
If a anonymous user want to create a quest, he is redirected to the login form.
-
herobase.tests.fake_request(user, path='/')[source]
create a fake request for testing purposes.
Test Factories
The factories in this file create the basic You are HERO models with default values.
With keyword arguments you can overwrite the default values.
-
herobase.test_factories.factory(f)[source]
factory decorator: provides a counter for use as id for example.
Backends
-
class herobase.backends.EmailAuthBackend[source]
Custom Authentication Backend for user validation with email addy and password.
Fields
-
class herobase.fields.LocationField(*args, **kwargs)[source]
Custom Field for geolocation
-
class herobase.fields.LocationFormField(max_length=None, min_length=None, *args, **kwargs)[source]
Custom Form field for geolocation
Utils
Up to now here is only a plain password hasher for faster tests. Never use it elsewhere.
-
class herobase.utils.PlainTextPasswordHasher[source]
I am an incredibly insecure algorithm you should never use;
I am only for faster tests.
-
herobase.utils.login_required(function)[source]
Decorator for views that checks that the user is logged in, redirecting
to the log-in page if necessary.