fluxscoreboard.views

This package contains all views, organized in classes. It is divided into frontend views in fluxscoreboard.views.front and backend views in fluxscoreboard.views.admin.

fluxscoreboard.views.front

class fluxscoreboard.views.front.BaseView(request)[source]

A base class for all other frontpage views. If you build a frontend view class, derive from this. You can access the current logged in team from the team property. A list of menu items will be present in menu, which returns different items based on whether the user is logged in.

current_state

A pair of ctf_state, logged_in where ctf_state represents the current state as per settings and logged_in is a boolean that shows whether the user is currently logged in to a team.

menu

Get the current menu items as a list of tuples (view_name, title).

title

From the menu get a title for the page.

class fluxscoreboard.views.front.SpecialView(request)[source]

Contains special views, i.e. pages for status codes like 404 and 403.

forbidden()[source]

A forbidden view that only returns a 403 if the user isn’t logged in otherwise just redirect to login.

notfound()[source]

Renders a 404 view that integrates with the page. The attached template is 404.mako.

class fluxscoreboard.views.front.FrontView(request)[source]

All views that are part of the actual page, i.e. the scoreboard and anything surrounding it. Most views in here must be protected by logged_in_view and not the usual pyramid.view.view_config. Some exceptions may exist, such as the ref() view.

challenge()[source]

A view of a single challenge. The query is very similar to that of challenges() with the limitation that only one challenge is fetched. Additionally, this page displays a form to enter the solution of that challenge and fetches a list of announcements for the challenge.

challenges()[source]

A list of all challenges similar to the scoreboard view in a table. It has a very complex query that gets all challennges together with a boolean of whether the current team has solved it, and the number of times this challenge was solved overall. This list of tuples (challenge, team_solved, number_solved_total) is then given to the template and rendered.

home()[source]

A view for the page root which just redirects to the scoreboard view.

news()[source]

Just a list of all announcements that are currently published, ordered by publication date, the most recent first.

scoreboard()[source]

The central most interesting view. This contains a list of all teams with their points, sorted with the highest points on top. The most complex part of the query is the query that calculates the sum of points right in the SQL.

submit_solution()[source]

A special form that, in addition to the form provided by challenge(), allows a user to submit solutions for a challenge. The difference here is that the challenge is chosen from a select list. Otherwise it is basically the same and boils down to the same logic.

teams()[source]

Only a list of teams.

class fluxscoreboard.views.front.UserView(request)[source]

This view is used for everything user- (or in our case team-) related. It contains stuff like registration, login and confirmation. It depends on the purpose of the view whether to make it a logged_in_view or a pyramid.view.view_config.

confirm_registration(self_wrap, *args, **kwargs)[source]

After a registration has been made, the team recieves a confirmation mail with a token. With this token the team activates its account by visitng this view. It fetches the team corresponding to the token and activates it.

login(self_wrap, *args, **kwargs)[source]

A view that logs in the user. Displays a login form and in case of a POST request, handles the login by checking whether it is valid. If it is, the user is logged in and redirected to the frontpage.

logout()[source]

A simple view that logs out the user and redirects to the login page.

profile()[source]

Here a team can alter their profile, i.e. change their email, password, location or timezone. The team name is fixed and can only be changed by administrators.

register(self_wrap, *args, **kwargs)[source]

Display and handle registration of new teams.

fluxscoreboard.views.admin

class fluxscoreboard.views.admin.AdminView(request)[source]

The view for everything corresponding to administration. The views here are not protected because they must be protected from the outside, i.e. HTTP Authorization or similar.

_admin_delete(route_name, DatabaseClass, title, title_plural=None)[source]

Generic function to delete a single item from the database. Its arguments have the same meaning as explained in _admin_list() with the addition of title_plural which is just a pluraized version of the title argument. Also returns something that can be returned directly to the application.

Note

To avoid problems with cascade instead of just emitting an SQL DELETE statement, this queries for all affected objects (should be one) and deletes them afterwards. This ensures that the Python-side cascades appropriately delete all dependent objects.

_admin_edit(route_name, FormClass, DatabaseClass, title)[source]

A generic function for a view that is invoked after an edit (or add) has been performed. It is separate from that of AdminView._admin_list() to keep the code cleaner. It has the same parameters and return types but can only be invoked as a POST.

_admin_list(route_name, FormClass, DatabaseClass, title, change_query=None)[source]

A generic function for all views that contain a list of things and also a form to edit or add entries.

Note

This only handles items with their own single primary key and not anything with composite foreign keys.

Args:

route_name: A string containing the name of the route to which the admin should be redirected aver an edit was saved. For example "admin_challenges".

FormClass: The class of the form that should be displayed at the bottom of the page to edit or add items. For example fluxscoreboard.forms.admin.ChallengeForm.

DatabaseClass: The ORM class from the model that is used to add and fetch items. For example fluxscoreboard.models.challenge.Challenge.

title: A string that expresses a singular item, for example "Challenge". Will be used for flash messages.

change_query: A function that receives one parameter (a query), modifies it and returns the new query. May for example be used to modify the order or refine results. Optional.

Returns:
A dictionary or similar that can be directly returned to the application to be rendered as a view.

An example usage might be like this:

def challenges(self):
return self._admin_list('admin_challenges', ChallengeForm,
                        Challenge, "Challenge")
_admin_toggle_status(route_name, DatabaseClass, title=u'', status_types={False: False, True: True}, status_variable_name=u'published', status_messages={False: u'Unpublished %(title)s', True: u'Published %(title)s'})[source]

Generic function that allows to toggle a special status on the challenge. By default it toggles the published property of any given item.

Many arguments are the same as in _admin_list() with these additional arguments:

status_types: A two-element dictionary that contains True and False as keys and any value that describes the given status. For example: If the “unpublished” status is described by the string “offline”, then the value for key False would be "offline". It depends on the database model, which value is used here. The default is just a boolean mapping.

status_variable_name: What is the name of the property in the model that contains the status to be changed. Defaults to “published”.

status_messages: The same keys as for status_types but as values contains messages to be displayed, based on which action was the result. Gives access to the title variable via %(title)s inside the string. The defaults are sensible values for the the default status. Most likely you want to change this if changing status_variable_name.

Returns:
A dictionary or similar that can be directly returned from a view.
_list_retparams(page, form, is_new=None)[source]

Get a dictionary of parameters to return to a list + edit form view.

page must be an instance of webhelpers.paginate.Page and form must be an instance of the form to be displayed (whatever that is).

admin()[source]

Root view of admin page, redirect to announcements.

categories()[source]

A view to list, add and edit categories. Implemented with _admin_list().

category_delete()[source]

A view to delete a category. Implemented with _admin_delete().

category_edit()[source]

This view accepts an edit form, handles it and reacts accordingly (either redirect or, on error, show errors). Implemented with _admin_edit().

chalenge_toggle_published()[source]

Switch a challenge between published and unpublished.

challenge_delete()[source]

A view to delete a challenge. Implemented with _admin_delete().

challenge_edit()[source]

This view accepts an edit form, handles it and reacts accordingly (either redirect or, on error, show errors). Implemented with _admin_edit().

challenge_feedback()[source]

Display feedback list.

challenge_toggle_status()[source]

A view to toggle the online/offline status of a challenge. Implemented with _admin_toggle_status().

challenges()[source]

A view to list, add and edit challenges. Implemented with _admin_list().

items(DatabaseClass)[source]

Construct a simple query to the database. Even though it is dead simple it is factored out because it is used in more than one place.

massmail()[source]

Send a massmail to all users in the system. It also stores the sent mail and its recipients in the database to keep a permanent record of sent messages.

massmail_single()[source]

View a single massmail that was sent.

news()[source]

A view to list, add and edit announcements. Implemented with _admin_list().

news_delete()[source]

A view to delete an announcement. Implemented with _admin_delete().

news_edit()[source]

This view accepts an edit form, handles it and reacts accordingly (either redirect or, on error, show errors). Implemented with _admin_edit().

news_toggle_status()[source]

A view to publish or unpublish an announcement. Implemented with _admin_toggle_status().

page(items)[source]

Return a webhelpers.paginate.Page instance for an items iterable.

redirect(route_name, current_page=None)[source]

For a given route name and page number get a redirect to that page. Convenience method for writing clean code.

settings()[source]

Adjust runtime application settings.

submissions()[source]

List, add or edit a submission. This is different because it consists of composite foreign keys and thus needs separate though similar logic. But in the end it is basically the same functionality as with the other list views.

submissions_delete()[source]

Delete a submission.

team_activate()[source]

De-/Activate a team.

team_cleanup()[source]

Remove ALL inactive teams. Warning: DANGEROUS

team_delete()[source]

Delete a team.

team_edit()[source]

This view accepts an edit form, handles it and reacts accordingly (either redirect or, on error, show errors). Implemented with _admin_edit().

team_ips()[source]

A list of IPs per team.

team_regenerate_token()[source]

Manually regenerate the teams challenge token

team_resend_activation()[source]

Resend the activation mail for a team.

team_toggle_local()[source]

Toggle the local attribute of a team.

teams()[source]

List, add or edit a team.

test_login()[source]

If there is at least one team, log in as it to see the page.