"""Administrator interface to teams.""" from django.contrib import admin from apps.managers.challenge_mgr import challenge_mgr from apps.managers.team_mgr.models import Group, Team, Post from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class GroupAdmin(admin.ModelAdmin): """Group Admin""" list_display = ["name", ] page_text = "Groups are optional in this challenge." admin.site.register(Group, GroupAdmin) challenge_designer_site.register(Group, GroupAdmin) challenge_manager_site.register(Group, GroupAdmin) developer_site.register(Group, GroupAdmin) class TeamAdmin(admin.ModelAdmin): """Team Admin""" list_display = ["name", "size", "group"] fields = ["name", "size", "group"] admin.site.register(Team, TeamAdmin) challenge_designer_site.register(Team, TeamAdmin) challenge_manager_site.register(Team, TeamAdmin) developer_site.register(Team, TeamAdmin) class PostAdmin(admin.ModelAdmin): """Post administrator for teams, overrides delete_selected"""
from apps.managers.score_mgr.models import ScoreSetting, ScoreboardEntry, PointsTransaction, \ ReferralSetting from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class PointsTransactionAdmin(admin.ModelAdmin): """PointsTransaction administrator interface definition.""" list_display = ["user", "transaction_date", "points", "message"] search_fields = ["user__username", "message"] date_hierarchy = "transaction_date" admin.site.register(PointsTransaction, PointsTransactionAdmin) challenge_designer_site.register(PointsTransaction, PointsTransactionAdmin) challenge_manager_site.register(PointsTransaction, PointsTransactionAdmin) developer_site.register(PointsTransaction, PointsTransactionAdmin) class ScoreboardEntryAdmin(admin.ModelAdmin): """PointsTransaction administrator interface definition.""" list_display = [ "round_name", "profile", "points", "last_awarded_submission" ] search_fields = ["profile__name", "profile__user__username"] list_filter = ["round_name"] admin.site.register(ScoreboardEntry, ScoreboardEntryAdmin) challenge_designer_site.register(ScoreboardEntry, ScoreboardEntryAdmin) challenge_manager_site.register(ScoreboardEntry, ScoreboardEntryAdmin) developer_site.register(ScoreboardEntry, ScoreboardEntryAdmin)
from apps.managers.challenge_mgr import challenge_mgr from apps.managers.log_mgr.models import MakahikiLog from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class MakahikiLogAdmin(admin.ModelAdmin): """admin""" list_display = ('request_url', "remote_user", 'remote_ip', 'request_time', 'request_method', 'response_status') list_filter = ('response_status', 'remote_user') search_fields = ('request_url', 'remote_ip') ordering = ["-request_time"] date_hierarchy = "request_time" formfield_overrides = { models.CharField: { 'widget': TextInput(attrs={'size': '100'}) }, } def has_add_permission(self, request): return False admin.site.register(MakahikiLog, MakahikiLogAdmin) challenge_designer_site.register(MakahikiLog, MakahikiLogAdmin) challenge_manager_site.register(MakahikiLog, MakahikiLogAdmin) developer_site.register(MakahikiLog, MakahikiLogAdmin) challenge_mgr.register_admin_challenge_info_model("Status", 1, MakahikiLog, 1) challenge_mgr.register_developer_challenge_info_model("Status", 4, MakahikiLog, 1)
from apps.managers.score_mgr.models import ScoreSetting, ScoreboardEntry, PointsTransaction, \ ReferralSetting from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class PointsTransactionAdmin(admin.ModelAdmin): """PointsTransaction administrator interface definition.""" list_display = ["user", "transaction_date", "points", "message"] search_fields = ["user__username", "message"] date_hierarchy = "transaction_date" admin.site.register(PointsTransaction, PointsTransactionAdmin) challenge_designer_site.register(PointsTransaction, PointsTransactionAdmin) challenge_manager_site.register(PointsTransaction, PointsTransactionAdmin) developer_site.register(PointsTransaction, PointsTransactionAdmin) class ScoreboardEntryAdmin(admin.ModelAdmin): """PointsTransaction administrator interface definition.""" list_display = ["round_name", "profile", "points", "last_awarded_submission"] search_fields = ["profile__name", "profile__user__username"] list_filter = ["round_name"] admin.site.register(ScoreboardEntry, ScoreboardEntryAdmin) challenge_designer_site.register(ScoreboardEntry, ScoreboardEntryAdmin) challenge_manager_site.register(ScoreboardEntry, ScoreboardEntryAdmin) developer_site.register(ScoreboardEntry, ScoreboardEntryAdmin) class ScoreSettingAdmin(admin.ModelAdmin):
def first_name(self, obj): """return the user first_name.""" return obj.user.first_name first_name.short_description = 'First_name' def points(self, obj): """return the user overall points.""" return obj.points() points.short_description = 'Points' admin.site.register(Profile, ProfileAdmin) challenge_designer_site.register(Profile, ProfileAdmin) challenge_manager_site.register(Profile, ProfileAdmin) developer_site.register(Profile, ProfileAdmin) #challenge_mgr.register_site_admin_model("Players", Profile) class MakahikiUserAdmin(UserAdmin): """extends the UserAdmin for the user admin interface.""" list_display = ('username', 'email', 'first_name', 'last_name', 'is_active', 'is_staff', "profile", 'team', 'referred_by') actions = ["set_active", "set_inactive"] page_text = "Click on the name in the Username column to edit a player's " + \ "password, personal information, roles, and site administration groups. " + \ "Click on the name in the Profile column to edit a player's display name, " + \ "team, badges, etc." def set_active(self, request, queryset): """set the active flag priority."""
"""Defines the Action Feedback model.""" action = models.ForeignKey(Action, null=True, blank=True, help_text="The action this feedback is for.") user = models.ForeignKey(User, null=True, blank=True, help_text="The user providing the feedback.") rating = models.IntegerField(help_text="The user's rating of the action.", default=0) comment = models.CharField( max_length=1500, blank=True, null=True, help_text="The user's comments about the action.") added = models.DateTimeField(editable=False, help_text="The time the feedback was made.", auto_now_add=True) changed = models.DateTimeField(editable=False, help_text="The time the feedback was changed.", auto_now=True) admin_tool_tip = "Player Feedback about Actions" def __unicode__(self): return "%s rated %s %d and said %s" % \ (self.user.username, self.action.name, self.rating, self.comment) admin.site.register(ActionFeedback) challenge_designer_site.register(ActionFeedback) challenge_manager_site.register(ActionFeedback) developer_site.register(ActionFeedback) challenge_mgr.register_developer_game_info_model("Smart Grid Game", ActionFeedback)
"""log model admin.""" from django.contrib import admin from django.db import models from django.forms.widgets import TextInput from apps.managers.challenge_mgr import challenge_mgr from apps.managers.log_mgr.models import MakahikiLog from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class MakahikiLogAdmin(admin.ModelAdmin): """admin""" list_display = ('request_url', "remote_user", 'remote_ip', 'request_time', 'request_method', 'response_status') list_filter = ('response_status', 'remote_user') search_fields = ('request_url', 'remote_ip') ordering = ["-request_time"] date_hierarchy = "request_time" formfield_overrides = { models.CharField: {'widget': TextInput(attrs={'size': '100'})}, } def has_add_permission(self, request): return False admin.site.register(MakahikiLog, MakahikiLogAdmin) challenge_designer_site.register(MakahikiLog, MakahikiLogAdmin) challenge_manager_site.register(MakahikiLog, MakahikiLogAdmin) developer_site.register(MakahikiLog, MakahikiLogAdmin) challenge_mgr.register_admin_challenge_info_model("Status", 1, MakahikiLog, 1) challenge_mgr.register_developer_challenge_info_model("Status", 4, MakahikiLog, 1)
obj.save() except IntegrityError: # How do we indicate an error to the admin? pass copy_raffle_prize.short_description = "Copy selected Raffle Prizes" def winner_form(self, obj): """return the winner and link to pickup form.""" if obj.winner: return "%s (<a href='%s'>View pickup form</a>)" % (obj.winner.profile, reverse('raffle_view_form', args=(obj.pk,))) else: return '(None)' winner_form.allow_tags = True winner_form.short_description = 'Winner' def notice_sent(self, obj): """return True if the notification had been sent.""" return UserNotification.objects.filter( recipient=obj.winner, content_type=ContentType.objects.get(model="raffleprize"), object_id=obj.id).exists() notice_sent.short_description = 'Winner Notice Sent' admin.site.register(RafflePrize, RafflePrizeAdmin) challenge_designer_site.register(RafflePrize, RafflePrizeAdmin) challenge_manager_site.register(RafflePrize, RafflePrizeAdmin) developer_site.register(RafflePrize, RafflePrizeAdmin) challenge_mgr.register_designer_game_info_model("Raffle Game", RafflePrize) challenge_mgr.register_developer_game_info_model("Raffle Game", RafflePrize)
"""Administrator interface to badge.""" from django.contrib import admin from apps.managers.challenge_mgr import challenge_mgr from apps.widgets.badges.models import Badge, BadgeAward from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class BadgeAdmin(admin.ModelAdmin): """Category Admin""" list_display = ["name", "points", "award_condition", "award_trigger", "priority"] fields = ["name", "slug", "label", "description", "hint", "points", "priority", "award_condition", "award_trigger", "theme"] prepopulated_fields = {"slug": ("name",)} ordering = ["priority"] admin.site.register(Badge, BadgeAdmin) challenge_designer_site.register(Badge, BadgeAdmin) challenge_manager_site.register(Badge, BadgeAdmin) developer_site.register(Badge, BadgeAdmin) admin.site.register(BadgeAward) challenge_designer_site.register(BadgeAward) challenge_manager_site.register(BadgeAward) developer_site.register(BadgeAward) challenge_mgr.register_designer_game_info_model("Badge Game Mechanics", Badge) challenge_mgr.register_admin_game_info_model("Badge Game Mechanics", BadgeAward) challenge_mgr.register_developer_game_info_model("Badge Game Mechanics", Badge) challenge_mgr.register_developer_game_info_model("Badge Game Mechanics", BadgeAward)
"""Admin definition.""" from django.contrib import admin from apps.managers.challenge_mgr import challenge_mgr from apps.widgets.notifications.models import NoticeTemplate, UserNotification from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class UserNotificationAdmin(admin.ModelAdmin): """raffle admin""" list_display = ('recipient', 'content_object', 'content_type', 'unread', 'level') search_fields = ('recipient__username', 'content_type__name') admin.site.register(NoticeTemplate) challenge_designer_site.register(NoticeTemplate) challenge_manager_site.register(NoticeTemplate) developer_site.register(NoticeTemplate) admin.site.register(UserNotification, UserNotificationAdmin) challenge_designer_site.register(UserNotification, UserNotificationAdmin) challenge_manager_site.register(UserNotification, UserNotificationAdmin) developer_site.register(UserNotification, UserNotificationAdmin) challenge_mgr.register_designer_challenge_info_model("Other Settings", 3, NoticeTemplate, 3) challenge_mgr.register_admin_challenge_info_model("Notifications", 3, UserNotification, 2) challenge_mgr.register_developer_challenge_info_model("Status", 4, NoticeTemplate, 5) challenge_mgr.register_developer_challenge_info_model("Status", 4, UserNotification, 5)
"""EnergyGoal administrator interface definition.""" list_display = ["name", ] list_display_links = ["name", ] page_text = "There must only be one Participation Setting. You can edit the amount" + \ " of points awarded per player for the various levels of team participation." def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None): return False admin.site.register(ParticipationSetting, ParticipationSettingAdmin) challenge_designer_site.register(ParticipationSetting, ParticipationSettingAdmin) challenge_manager_site.register(ParticipationSetting, ParticipationSettingAdmin) developer_site.register(ParticipationSetting, ParticipationSettingAdmin) challenge_mgr.register_designer_game_info_model("Participation Game", ParticipationSetting) class TeamParticipationAdmin(admin.ModelAdmin): """EnergyGoal administrator interface definition.""" list_display = ["round_name", "team", "participation", "awarded_percent", "updated_at"] list_filter = ["round_name"] def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None): return False admin.site.register(TeamParticipation, TeamParticipationAdmin)
'prize_team_winners', args=(obj.pk, )) else: leader = obj.leader() return leader winner.allow_tags = True winner.short_description = 'Current Winner' def notice_sent(self, obj): """return True if the notification had been sent.""" if obj.award_to == 'individual_overall': leader = obj.leader() return self._notification_exists(obj, leader) elif obj.award_to == 'individual_team': teams = Team.objects.all() for team in teams: leader = obj.leader(team=team) return self._notification_exists(obj, leader) else: return "N/A" notice_sent.short_description = 'Winner Notice Sent' admin.site.register(Prize, PrizeAdmin) challenge_designer_site.register(Prize, PrizeAdmin) challenge_manager_site.register(Prize, PrizeAdmin) developer_site.register(Prize, PrizeAdmin) challenge_mgr.register_designer_game_info_model("Top Score Game", Prize) challenge_mgr.register_developer_game_info_model("Top Score Game", Prize)
"""daily status widget administrator interface""" from django.contrib import admin from apps.widgets.status.models import DailyStatus from apps.managers.challenge_mgr import challenge_mgr from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class DailyStatusAdmin(admin.ModelAdmin): """EnergyGoal administrator interface definition.""" list_display = [ "short_date", "daily_visitors", "setup_users", "updated_at" ] ordering = ["-date"] admin.site.register(DailyStatus, DailyStatusAdmin) challenge_designer_site.register(DailyStatus, DailyStatusAdmin) challenge_manager_site.register(DailyStatus, DailyStatusAdmin) developer_site.register(DailyStatus, DailyStatusAdmin) challenge_mgr.register_developer_challenge_info_model("Status", 3, DailyStatus, 7)
"""Energy goal widget administrator interface; shows the team, actual vs. goal, last update.""" from django.contrib import admin from apps.managers.challenge_mgr import challenge_mgr from apps.managers.resource_mgr.models import EnergyUsage from apps.widgets.resource_goal.admin import GoalSettingsAdmin, GoalAdmin, BaselineDailyAdmin, \ BaselineHourlyAdmin from apps.widgets.resource_goal.models import EnergyGoalSetting, EnergyGoal, EnergyBaselineDaily, \ EnergyBaselineHourly from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site admin.site.register(EnergyGoalSetting, GoalSettingsAdmin) challenge_designer_site.register(EnergyGoalSetting, GoalSettingsAdmin) challenge_manager_site.register(EnergyGoalSetting, GoalSettingsAdmin) developer_site.register(EnergyGoalSetting, GoalSettingsAdmin) admin.site.register(EnergyGoal, GoalAdmin) challenge_designer_site.register(EnergyGoal, GoalAdmin) challenge_manager_site.register(EnergyGoal, GoalAdmin) developer_site.register(EnergyGoal, GoalAdmin) admin.site.register(EnergyBaselineDaily, BaselineDailyAdmin) challenge_designer_site.register(EnergyBaselineDaily, BaselineDailyAdmin) challenge_manager_site.register(EnergyBaselineDaily, BaselineDailyAdmin) developer_site.register(EnergyBaselineDaily, BaselineDailyAdmin) admin.site.register(EnergyBaselineHourly, BaselineHourlyAdmin) challenge_designer_site.register(EnergyBaselineHourly, BaselineHourlyAdmin) challenge_manager_site.register(EnergyBaselineHourly, BaselineHourlyAdmin) developer_site.register(EnergyBaselineHourly, BaselineHourlyAdmin) challenge_mgr.register_designer_game_info_model("Energy Game", EnergyGoalSetting) challenge_mgr.register_admin_game_info_model("Energy Game", EnergyUsage)
"""daily status widget administrator interface""" from django.contrib import admin from apps.widgets.status.models import DailyStatus from apps.managers.challenge_mgr import challenge_mgr from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class DailyStatusAdmin(admin.ModelAdmin): """EnergyGoal administrator interface definition.""" list_display = ["short_date", "daily_visitors", "setup_users", "updated_at"] ordering = ["-date"] admin.site.register(DailyStatus, DailyStatusAdmin) challenge_designer_site.register(DailyStatus, DailyStatusAdmin) challenge_manager_site.register(DailyStatus, DailyStatusAdmin) developer_site.register(DailyStatus, DailyStatusAdmin) challenge_mgr.register_developer_challenge_info_model("Status", 3, DailyStatus, 7)
"""Energy goal widget administrator interface; shows the team, actual vs. goal, last update.""" from django.contrib import admin from apps.managers.challenge_mgr import challenge_mgr from apps.managers.resource_mgr.models import WaterUsage from apps.widgets.resource_goal.admin import GoalSettingsAdmin, GoalAdmin, BaselineDailyAdmin from apps.widgets.resource_goal.models import WaterGoalSetting, WaterGoal, WaterBaselineDaily, \ WaterBaselineHourly from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site admin.site.register(WaterGoalSetting, GoalSettingsAdmin) challenge_designer_site.register(WaterGoalSetting, GoalSettingsAdmin) challenge_manager_site.register(WaterGoalSetting, GoalSettingsAdmin) developer_site.register(WaterGoalSetting, GoalSettingsAdmin) admin.site.register(WaterGoal, GoalAdmin) challenge_designer_site.register(WaterGoal, GoalAdmin) challenge_manager_site.register(WaterGoal, GoalAdmin) developer_site.register(WaterGoal, GoalAdmin) admin.site.register(WaterBaselineDaily, BaselineDailyAdmin) challenge_designer_site.register(WaterBaselineDaily, BaselineDailyAdmin) challenge_manager_site.register(WaterBaselineDaily, BaselineDailyAdmin) developer_site.register(WaterBaselineDaily, BaselineDailyAdmin) challenge_mgr.register_designer_game_info_model("Water Game", WaterGoalSetting) challenge_mgr.register_admin_game_info_model("Water Game", WaterUsage) challenge_mgr.register_admin_challenge_info_model("Status", 1, WaterGoal, 3) challenge_mgr.register_developer_game_info_model("Water Game", WaterGoalSetting) challenge_mgr.register_developer_game_info_model("Water Game", WaterGoal) challenge_mgr.register_developer_game_info_model("Water Game", WaterBaselineDaily)
inlines = [PageSettingInline] formfield_overrides = { models.TextField: { 'widget': Textarea(attrs={ 'rows': 3, 'cols': 70 }) }, } admin.site.register(PageInfo, PageInfoAdmin) challenge_designer_site.register(PageInfo, DesignerPageInfoAdmin) challenge_manager_site.register(PageInfo, DesignerPageInfoAdmin) developer_site.register(PageInfo, PageInfoAdmin) class PageSettingAdmin(admin.ModelAdmin): """PageSetting administrator interface definition.""" list_display = ["page", "widget", "enabled"] list_editable = ["widget", "enabled"] admin.site.register(PageSetting, PageSettingAdmin) challenge_designer_site.register(PageSetting, PageSettingAdmin) challenge_manager_site.register(PageSetting, PageSettingAdmin) developer_site.register(PageSetting, PageSettingAdmin) class GameSettingInline(admin.TabularInline):
"unlock_condition", "priority",) }), ) inlines = [PageSettingInline] formfield_overrides = { models.TextField: {'widget': Textarea(attrs={'rows': 3, 'cols': 70})}, } admin.site.register(PageInfo, PageInfoAdmin) challenge_designer_site.register(PageInfo, DesignerPageInfoAdmin) challenge_manager_site.register(PageInfo, DesignerPageInfoAdmin) developer_site.register(PageInfo, PageInfoAdmin) class PageSettingAdmin(admin.ModelAdmin): """PageSetting administrator interface definition.""" list_display = ["page", "widget", "enabled"] list_editable = ["widget", "enabled"] admin.site.register(PageSetting, PageSettingAdmin) challenge_designer_site.register(PageSetting, PageSettingAdmin) challenge_manager_site.register(PageSetting, PageSettingAdmin) developer_site.register(PageSetting, PageSettingAdmin) class GameSettingInline(admin.TabularInline): """PageSettingInline admin."""
"""return the user first_name.""" return obj.user.first_name first_name.short_description = 'First_name' def points(self, obj): """return the user overall points.""" return obj.points() points.short_description = 'Points' admin.site.register(Profile, ProfileAdmin) challenge_designer_site.register(Profile, ProfileAdmin) challenge_manager_site.register(Profile, ProfileAdmin) developer_site.register(Profile, ProfileAdmin) #challenge_mgr.register_site_admin_model("Players", Profile) class MakahikiUserAdmin(UserAdmin): """extends the UserAdmin for the user admin interface.""" list_display = ('username', 'email', 'first_name', 'last_name', 'is_active', 'is_staff', "profile", 'team', 'referred_by') actions = ["set_active", "set_inactive"] page_text = "Click on the name in the Username column to edit a player's " + \ "password, personal information, roles, and site administration groups. " + \ "Click on the name in the Profile column to edit a player's display name, " + \ "team, badges, etc." def set_active(self, request, queryset): """set the active flag priority."""
"Sub-topics of sub-topics are not " "allowed.") if parent_topic and parent_topic.slug == self.cleaned_data["slug"]: raise forms.ValidationError( "Topic cannot be a sub-topic of itself.") return parent_topic class HelpTopicAdmin(admin.ModelAdmin): """Help topic administrative interface.""" # Automatically populates the slug field. prepopulated_fields = {"slug": ("title",)} list_filter = ["category", ] search_fields = ["slug", "title"] list_display = ["slug", "category", "priority", "parent_topic"] page_text = "Click on the slug to edit the details of the Help Topic. " + \ "There are three categories of Help Topic, FAQs, Rules, and Widget. " + \ "Widget Help Topics are displayed when a player clicks the help link for " + \ "an individual widget. FAQs, and Rules are used by the Help FAQ widget and " + \ "Help Rules widget." form = HelpAdminForm admin.site.register(HelpTopic, HelpTopicAdmin) challenge_designer_site.register(HelpTopic, HelpTopicAdmin) challenge_manager_site.register(HelpTopic, HelpTopicAdmin) developer_site.register(HelpTopic, HelpTopicAdmin) challenge_mgr.register_designer_challenge_info_model("Other Settings", 3, HelpTopic, 2) challenge_mgr.register_developer_challenge_info_model("Challenge", 1, HelpTopic, 5)
from apps.managers.resource_mgr.models import EnergyUsage, WaterUsage, ResourceSetting, \ ResourceBlackoutDate, WasteUsage from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class UsageAdmin(admin.ModelAdmin): """Administrator display list: team, date, and energy.""" list_display = ["date", "team", "time", "usage", "updated_at"] search_fields = ["team__name", ] list_filter = ['team'] date_hierarchy = "date" admin.site.register(EnergyUsage, UsageAdmin) challenge_designer_site.register(EnergyUsage, UsageAdmin) challenge_manager_site.register(EnergyUsage, UsageAdmin) developer_site.register(EnergyUsage, UsageAdmin) admin.site.register(WaterUsage, UsageAdmin) challenge_designer_site.register(WaterUsage, UsageAdmin) challenge_manager_site.register(WaterUsage, UsageAdmin) developer_site.register(WaterUsage, UsageAdmin) class ResourceSettingsAdmin(admin.ModelAdmin): """Administrator display list: team, date, and energy.""" list_display = ["name", "unit", "winning_order", "conversion_rate"] readonly_fields = ["name"] def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None):
slug = obj.slug obj.slug = slug + "-copy" try: obj.save() except IntegrityError: # How do we indicate an error to the admin? pass copy_action.short_description = "Copy selected Action(s)" def get_urls(self): return redirect_urls(self, "change") admin.site.register(Action, ActionAdmin) challenge_designer_site.register(Action, ActionAdmin) challenge_manager_site.register(Action, ActionAdmin) developer_site.register(Action, ActionAdmin) challenge_mgr.register_designer_game_info_model("Smart Grid Game", Action) challenge_mgr.register_developer_game_info_model("Smart Grid Game", Action) class ActivityAdminForm(forms.ModelForm): """Activity Admin Form.""" class Meta: """Meta""" model = Activity def clean_unlock_condition(self): """Validates the unlock conditions of the action.""" data = self.cleaned_data["unlock_condition"] utils.validate_form_predicates(data) return data
from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class BadgeAdmin(admin.ModelAdmin): """Badge Admin""" list_display = [ "name", "points", "award_condition", "award_trigger", "priority" ] fields = [ "name", "slug", "label", "description", "hint", "points", "priority", "award_condition", "award_trigger", "theme" ] prepopulated_fields = {"slug": ("name", )} ordering = ["priority"] admin.site.register(Badge, BadgeAdmin) challenge_designer_site.register(Badge, BadgeAdmin) challenge_manager_site.register(Badge, BadgeAdmin) developer_site.register(Badge, BadgeAdmin) admin.site.register(BadgeAward) challenge_designer_site.register(BadgeAward) challenge_manager_site.register(BadgeAward) developer_site.register(BadgeAward) challenge_mgr.register_designer_game_info_model("Badge Game Mechanics", Badge) challenge_mgr.register_admin_game_info_model("Badge Game Mechanics", BadgeAward) challenge_mgr.register_developer_game_info_model("Badge Game Mechanics", Badge) challenge_mgr.register_developer_game_info_model("Badge Game Mechanics", BadgeAward)
from apps.managers.team_mgr.models import Group, Team, Post from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class GroupAdmin(admin.ModelAdmin): """Category Admin""" list_display = [ "name", ] page_text = "Groups are optional in this challenge." admin.site.register(Group, GroupAdmin) challenge_designer_site.register(Group, GroupAdmin) challenge_manager_site.register(Group, GroupAdmin) developer_site.register(Group, GroupAdmin) class TeamAdmin(admin.ModelAdmin): """Category Admin""" list_display = ["name", "size", "group"] fields = ["name", "size", "group"] admin.site.register(Team, TeamAdmin) challenge_designer_site.register(Team, TeamAdmin) challenge_manager_site.register(Team, TeamAdmin) developer_site.register(Team, TeamAdmin) class PostAdmin(admin.ModelAdmin):
slug = obj.slug obj.slug = slug + "-copy" try: obj.save() except IntegrityError: # How do we indicate an error to the admin? pass copy_action.short_description = "Copy selected Action(s)" def get_urls(self): return redirect_urls(self, "change") admin.site.register(LibraryAction, LibraryActionAdmin) challenge_designer_site.register(LibraryAction, LibraryActionAdmin) challenge_manager_site.register(LibraryAction, LibraryActionAdmin) developer_site.register(LibraryAction, LibraryActionAdmin) challenge_mgr.register_designer_challenge_info_model("Smart Grid Game Library", 4, \ LibraryAction, 2) challenge_mgr.register_developer_challenge_info_model("Smart Grid Game Library", 4, \ LibraryAction, 2) class LibraryColumnNameAdmin(admin.ModelAdmin): """LibraryColumnName Admin.""" list_display = ["name"] prepopulated_fields = {"slug": ("name",)} fields = ["name", "slug"] admin.site.register(LibraryColumnName, LibraryColumnNameAdmin) challenge_designer_site.register(LibraryColumnName, LibraryColumnNameAdmin) challenge_manager_site.register(LibraryColumnName, LibraryColumnNameAdmin)
def clean_unlock_conditions(self): """Validates the unlock conditions of the quest.""" data = self.cleaned_data["unlock_conditions"] predicate_mgr.validate_form_predicates(data) return data def clean_completion_conditions(self): """Validates the unlock conditions of the quest.""" data = self.cleaned_data["completion_conditions"] predicate_mgr.validate_form_predicates(data) return data class QuestAdmin(admin.ModelAdmin): """Admin""" list_display = ["name", "priority", "unlock_conditions"] ordering = ["priority"] # Automatically populates the slug field. prepopulated_fields = {"quest_slug": ("name",)} form = QuestAdminForm admin.site.register(Quest, QuestAdmin) challenge_designer_site.register(Quest, QuestAdmin) challenge_manager_site.register(Quest, QuestAdmin) developer_site.register(Quest, QuestAdmin) challenge_mgr.register_designer_game_info_model("Quest Game Mechanics", Quest) challenge_mgr.register_developer_game_info_model("Quest Game Mechanics", Quest)
print_selected.short_description = "Set the printed or distributed flag." def view_selected(self, request, queryset): """Views the Bonus Points Codes for printing.""" _ = request _ = queryset return render_to_response( "view_bonus_points.html", {"codes": queryset, "per_page": 10}, context_instance=RequestContext(request) ) view_selected.short_description = "View the selected Bonus Points." def view_codes(self, request, queryset): """Views the Bonus Points Codes for printing.""" _ = request _ = queryset response = HttpResponseRedirect(reverse("bonus_view_codes", args=())) return response admin.site.register(BonusPoint, BonusPointAdmin) challenge_designer_site.register(BonusPoint, BonusPointAdmin) challenge_manager_site.register(BonusPoint, BonusPointAdmin) developer_site.register(BonusPoint, BonusPointAdmin) challenge_mgr.register_designer_game_info_model("Smart Grid Game", BonusPoint) challenge_mgr.register_admin_game_info_model("Smart Grid Game", BonusPoint) challenge_mgr.register_developer_game_info_model("Smart Grid Game", BonusPoint)
def is_ra(self, obj): """return the user name.""" return obj.profile.is_ra is_ra.short_description = 'Is RA' def points(self, obj): """return the user name.""" return obj.profile.points() points.short_description = 'Points' def setup_complete(self, obj): """return the user name.""" return obj.profile.setup_complete setup_complete.short_description = 'Setup completed' def referred_by(self, obj): """return the name of the referrer.""" return obj.profile.referring_user referred_by.short_description = 'Referred by' User.__doc__ = "Represents a player in the system." User.admin_tool_tip = "Challenge Players. They must be defined before anyone can play." challenge_designer_site.register(User, MakahikiUserAdmin) challenge_manager_site.register(User, MakahikiUserAdmin) developer_site.register(User, MakahikiUserAdmin) challenge_mgr.register_designer_challenge_info_model("Players", 2, User, 2) challenge_mgr.register_developer_challenge_info_model("Players", 2, User, 3)
args=(obj.pk, )) else: leader = obj.leader() return leader winner.allow_tags = True winner.short_description = 'Current Winner' def notice_sent(self, obj): """return True if the notification had been sent.""" if obj.award_to == 'individual_overall': leader = obj.leader() return self._notification_exists(obj, leader) elif obj.award_to == 'individual_team': teams = Team.objects.all() for team in teams: leader = obj.leader(team=team) return self._notification_exists(obj, leader) else: return "N/A" notice_sent.short_description = 'Winner Notice Sent' admin.site.register(Prize, PrizeAdmin) challenge_designer_site.register(Prize, PrizeAdmin) challenge_manager_site.register(Prize, PrizeAdmin) developer_site.register(Prize, PrizeAdmin) challenge_mgr.register_designer_game_info_model("Top Score Game", Prize) challenge_mgr.register_developer_game_info_model("Top Score Game", Prize)
from django.db import models from django.contrib.auth.models import User from django.contrib import admin from apps.widgets.smartgrid.models import Action from apps.managers.challenge_mgr import challenge_mgr from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site from apps.widgets.AskQuestion.models import AskQuestion class ReturnAnswer(models.Model): """Defines the Action Feedback model.""" m_question = models.ForeignKey(AskQuestion, null=True, blank=True, help_text="The user asking the question.") m_answer = models.CharField(max_length=8000) m_user = models.ForeignKey(User, null=True, blank=True, help_text="The user answering the question.") m_rating = models.IntegerField(null=True,default=1) def __unicode__(self): return "%s rated %s %d and said %s" % \ (self.user.username, self.action.name, self.rating, self.comment) admin.site.register(ReturnAnswer) challenge_designer_site.register(ReturnAnswer) challenge_manager_site.register(ReturnAnswer) developer_site.register(ReturnAnswer) #challenge_mgr.register_developer_game_info_model("Smart Grid Game", ActionFeedback)
from django.contrib import admin from apps.lib.avatar.models import Avatar from apps.managers.challenge_mgr import challenge_mgr from apps.admin.admin import developer_site admin.site.register(Avatar) developer_site.register(Avatar) Avatar.admin_tool_tip = "Player Avatars" challenge_mgr.register_developer_challenge_info_model("Players", 2, Avatar, 4)
is_ra.short_description = 'Is RA' def points(self, obj): """return the user name.""" return obj.profile.points() points.short_description = 'Points' def setup_complete(self, obj): """return the user name.""" return obj.profile.setup_complete setup_complete.short_description = 'Setup completed' def referred_by(self, obj): """return the name of the referrer.""" return obj.profile.referring_user referred_by.short_description = 'Referred by' User.__doc__ = "Represents a player in the system." User.admin_tool_tip = "Challenge Players. They must be defined before anyone can play." challenge_designer_site.register(User, MakahikiUserAdmin) challenge_manager_site.register(User, MakahikiUserAdmin) developer_site.register(User, MakahikiUserAdmin) challenge_mgr.register_designer_challenge_info_model("Players", 2, User, 2) challenge_mgr.register_developer_challenge_info_model("Players", 2, User, 3)
def clean_unlock_conditions(self): """Validates the unlock conditions of the quest.""" data = self.cleaned_data["unlock_conditions"] predicate_mgr.validate_form_predicates(data) return data def clean_completion_conditions(self): """Validates the unlock conditions of the quest.""" data = self.cleaned_data["completion_conditions"] predicate_mgr.validate_form_predicates(data) return data class QuestAdmin(admin.ModelAdmin): """Admin""" list_display = ["name", "priority", "unlock_conditions"] ordering = ["priority"] # Automatically populates the slug field. prepopulated_fields = {"quest_slug": ("name", )} form = QuestAdminForm admin.site.register(Quest, QuestAdmin) challenge_designer_site.register(Quest, QuestAdmin) challenge_manager_site.register(Quest, QuestAdmin) developer_site.register(Quest, QuestAdmin) challenge_mgr.register_designer_game_info_model("Quest Game Mechanics", Quest) challenge_mgr.register_developer_game_info_model("Quest Game Mechanics", Quest)
page_text = "There must only be one Participation Setting. You can edit the amount" + \ " of points awarded per player for the various levels of team participation." def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None): return False admin.site.register(ParticipationSetting, ParticipationSettingAdmin) challenge_designer_site.register(ParticipationSetting, ParticipationSettingAdmin) challenge_manager_site.register(ParticipationSetting, ParticipationSettingAdmin) developer_site.register(ParticipationSetting, ParticipationSettingAdmin) challenge_mgr.register_designer_game_info_model("Participation Game", ParticipationSetting) class TeamParticipationAdmin(admin.ModelAdmin): """EnergyGoal administrator interface definition.""" list_display = [ "round_name", "team", "participation", "awarded_percent", "updated_at" ] list_filter = ["round_name"] def has_add_permission(self, request): return False def has_delete_permission(self, request, obj=None):
copy_raffle_prize.short_description = "Copy selected Raffle Prizes" def winner_form(self, obj): """return the winner and link to pickup form.""" if obj.winner: return "%s (<a href='%s'>View pickup form</a>)" % ( obj.winner.profile, reverse('raffle_view_form', args=(obj.pk, ))) else: return '(None)' winner_form.allow_tags = True winner_form.short_description = 'Winner' def notice_sent(self, obj): """return True if the notification had been sent.""" return UserNotification.objects.filter( recipient=obj.winner, content_type=ContentType.objects.get(model="raffleprize"), object_id=obj.id).exists() notice_sent.short_description = 'Winner Notice Sent' admin.site.register(RafflePrize, RafflePrizeAdmin) challenge_designer_site.register(RafflePrize, RafflePrizeAdmin) challenge_manager_site.register(RafflePrize, RafflePrizeAdmin) developer_site.register(RafflePrize, RafflePrizeAdmin) challenge_mgr.register_designer_game_info_model("Raffle Game", RafflePrize) challenge_mgr.register_developer_game_info_model("Raffle Game", RafflePrize)
print_selected.short_description = "Set the printed or distributed flag." def view_selected(self, request, queryset): """Views the Bonus Points Codes for printing.""" _ = request _ = queryset return render_to_response("view_bonus_points.html", { "codes": queryset, "per_page": 10, }, context_instance=RequestContext(request)) view_selected.short_description = "View the selected Bonus Points." def view_codes(self, request, queryset): """Views the Bonus Points Codes for printing.""" _ = request _ = queryset response = HttpResponseRedirect(reverse("bonus_view_codes", args=())) return response admin.site.register(BonusPoint, BonusPointAdmin) challenge_designer_site.register(BonusPoint, BonusPointAdmin) challenge_manager_site.register(BonusPoint, BonusPointAdmin) developer_site.register(BonusPoint, BonusPointAdmin) challenge_mgr.register_designer_game_info_model("Smart Grid Game", BonusPoint) challenge_mgr.register_admin_game_info_model("Smart Grid Game", BonusPoint) challenge_mgr.register_developer_game_info_model("Smart Grid Game", BonusPoint)
"""Energy goal widget administrator interface; shows the team, actual vs. goal, last update.""" from django.contrib import admin from apps.managers.challenge_mgr import challenge_mgr from apps.managers.resource_mgr.models import WaterUsage from apps.widgets.resource_goal.admin import GoalSettingsAdmin, GoalAdmin, BaselineDailyAdmin from apps.widgets.resource_goal.models import WaterGoalSetting, WaterGoal, WaterBaselineDaily, \ WaterBaselineHourly from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site admin.site.register(WaterGoalSetting, GoalSettingsAdmin) challenge_designer_site.register(WaterGoalSetting, GoalSettingsAdmin) challenge_manager_site.register(WaterGoalSetting, GoalSettingsAdmin) developer_site.register(WaterGoalSetting, GoalSettingsAdmin) admin.site.register(WaterGoal, GoalAdmin) challenge_designer_site.register(WaterGoal, GoalAdmin) challenge_manager_site.register(WaterGoal, GoalAdmin) developer_site.register(WaterGoal, GoalAdmin) admin.site.register(WaterBaselineDaily, BaselineDailyAdmin) challenge_designer_site.register(WaterBaselineDaily, BaselineDailyAdmin) challenge_manager_site.register(WaterBaselineDaily, BaselineDailyAdmin) developer_site.register(WaterBaselineDaily, BaselineDailyAdmin) challenge_mgr.register_designer_game_info_model("Water Game", WaterGoalSetting) challenge_mgr.register_admin_game_info_model("Water Game", WaterUsage) challenge_mgr.register_admin_challenge_info_model("Status", 1, WaterGoal, 3) challenge_mgr.register_developer_game_info_model("Water Game", WaterGoalSetting) challenge_mgr.register_developer_game_info_model("Water Game", WaterGoal) challenge_mgr.register_developer_game_info_model("Water Game", WaterBaselineDaily) challenge_mgr.register_developer_game_info_model("Water Game", WaterBaselineHourly)
"""action_feedback model.""" from django.db import models from django.contrib.auth.models import User from django.contrib import admin from apps.widgets.smartgrid.models import Action from apps.managers.challenge_mgr import challenge_mgr from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class AskQuestion(models.Model): """Defines the Action Feedback model.""" m_question = models.CharField(max_length=8000) m_user = models.ForeignKey(User, null=True, blank=True, help_text="The user asking the question.") m_isopen = models.BooleanField() def __unicode__(self): return "%s rated %s %d and said %s" % \ (self.user.username, self.action.name, self.rating, self.comment) admin.site.register(AskQuestion) challenge_designer_site.register(AskQuestion) challenge_manager_site.register(AskQuestion) developer_site.register(AskQuestion) #challenge_mgr.register_developer_game_info_model("Smart Grid Game", ActionFeedback)
DesignerColumnName, DesignerLevel, DesignerQuestionChoice, Draft, DesignerColumnGrid, \ DesignerGrid from django.http import HttpResponseRedirect from apps.managers.predicate_mgr import predicate_mgr class DesignerDraftAdmin(admin.ModelAdmin): """Admin for Drafts.""" list_display = ["name", ] prepopulated_fields = {"slug": ("name",)} admin.site.register(Draft, DesignerDraftAdmin) challenge_designer_site.register(Draft, DesignerDraftAdmin) challenge_manager_site.register(Draft, DesignerDraftAdmin) developer_site.register(Draft, DesignerDraftAdmin) challenge_mgr.register_designer_challenge_info_model("Smart Grid Game Designer", 5, \ Draft, 1) challenge_mgr.register_developer_challenge_info_model("Smart Grid Game Designer", 4, \ Draft, 1) class DesignerActionAdmin(admin.ModelAdmin): """abstract admin for action.""" actions = ["delete_selected", "copy_action"] list_display = ["draft", "slug", "title", "type", "point_value"] search_fields = ["draft", "slug", "title"] list_filter = ['draft', 'type', ] def delete_selected(self, request, queryset): """override the delete selected."""
"""Energy goal widget administrator interface; shows the projects, actual vs. goal, last update.""" from django.contrib import admin from apps.managers.challenge_mgr import challenge_mgr from apps.widgets.projects.models import Comment, Goal, Project from apps.admin.admin import challenge_designer_site, challenge_manager_site, developer_site class ProjectAdmin(admin.ModelAdmin): """Project administrator interface definition.""" list_display = ["title", "short_description", "long_description", "number_of_members", "created", "deadline", "upvotes", "points", "status"] admin.site.register(Project, ProjectAdmin) challenge_designer_site.register(Project, ProjectAdmin) challenge_manager_site.register(Project, ProjectAdmin) developer_site.register(Project, ProjectAdmin) challenge_mgr.register_designer_game_info_model("Projects", Project) challenge_mgr.register_admin_game_info_model("Projects", Project) challenge_mgr.register_admin_challenge_info_model("Projects", 1, Project, 1) challenge_mgr.register_developer_challenge_info_model("Projects", 1, Project, 1) class CommentAdmin(admin.ModelAdmin): """Comment administrator interface definition"""