Giter VIP home page Giter VIP logo

buggyrace / buggy-race-server Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 2.95 MB

Race server and supporting material for running a "Buggy Racing" Python programming project

Home Page: https://www.buggyrace.net

License: Other

Dockerfile 0.12% Procfile 0.01% CSS 2.63% JavaScript 6.64% Python 47.43% HTML 42.86% Mako 0.05% Shell 0.02% Makefile 0.23%
compsci educational-software python teaching-materials flask

buggy-race-server's People

Contributors

davewhiteland avatar kuiperst avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

buggy-race-server's Issues

remove unused imports (especially py, but also others)

Most obviously, remove the py library import I introduced in the admin work.

It's not being used: it's effectively a redundant dev library:

NOTE: this library is in maintenance mode and should not be used in new code.

I suspect its inclusion is due to the IDE adding it without me realising due to some keystroke error, genuinely baffled.

We added it to requirements deploy here e795601 because this was a breaking change, but this is the wrong solution.

re-implement AUTH_CODE

Looks like it was taken out of the registration form, but it's useful when setting up a new site (unless we make injecting users/SQL directly into the DB which I don't recommend — this feels too useful when setting up.

be selective about which users' buggies are downloaded

When downloading buggies, it might be sensible to (automatically? optionally?) exclude any non-enrolled students' buggies from the list.

It's almost certainly wrong to include buggies from any student accounts that aren't active (since that's effectively how students are removed from the course).

make different fields of login/registration optional

A server might need to run collecting:

  • server username
  • institution's username
  • email

and any combination of those.

Actually using institution's username (and password) for login auth (LDAP etc) ought to be an option too but that's a chunk of worry.

use config/env settings via settings.py

It would be good to consolidate all the places we're using environment variables — Flask is loading them and exposing them via settings.py so that feels like the right place to be getting them all from — I've reached directly into os.env elsewhere in the code and that means I'm straying away from knowing what and where the defaults are. It already made me suspicious that the FORCE_REDIRECT_HTTP_TO_HTTPS setting might not have been working.

let admin add banner message(s)

currently there's a code change to announce project message — would be better to have these in the database so admin can set them up without code changes. It's very likely we'll need them again.

The existing solution used its own div but maybe could use flash messages + CSS?

It's very likely this will be a useful customisation for different installations

remove dependency on env variable setting a port number

The VS code integration for the last RHUL run (yay!) also introduced a requirement for ENV var CS1999_PORT to be set.

Make sure the default — in the event of the environment variable not being set — is to just work. Must be able to run the buggy editor standalone (defaulting to Flask's default port) — even if we don't expect it to be used in that way.

This might include being clear about how we're using VS Code and what config is needed on the institution's server instance — affects documentation as well as possibly other things I don't know about.

ensure GitHub issues CSV mechanism is OK

Now using get_tasks_as_issues_csv in the utils.py module when the server is running... but we were doing this "offline". Need to make sure the code is identical (some refactoring to do); the new version needs the application configuration to know how to construct the task URLs.

decide how to present race results

The idea was that there's a race log that shows the results.

Maybe a static log file that is manually added to the server? Obviously this should be automated.

Relevant to: 5-RACELOG

should respect IS_PRETTY_USERNAME_TITLECASE in error messages

In flash messages (e.g., failure to change a user's password) should run username through a util method that titlecases it if IS_PRETTY_USERNAME_TITLECASE is set — no point having it if we're not being consistent throughout the whole site.

"all columns" should be deselected if any other col is chosen

When displaying user table to admin, the user can choose which columns are visible. The buttons are filled/outlined depending on whether or not they are selected.

Currently, pressing "all columns" correctly toggles the state of the other buttons, but the state of the "all columns" button should be deselected as soon as all columns are not being displayed.

improve admin management (with roles in database)

Currently we've got a very simple environment-variable driven mechanism: if your username is in the (comma-separated) list of usernames in ADMIN_USERNAMES then you're admin.

Really this would be better (more robust) as an is_admin field in the user model.

Heroku incompatible buildpack

The old requirements.txt got removed in issue #21 however Heroku requires this file in the root.

For now, I have just made it recursively call requirements/prod.txt. We can tweak this later.

make settings configurable via web interface

In effect this means — where possible — the settings should be stored in the database. The config settings should still exist and be used as defaults when the project/database is initialised (also, there are some core settings — such as database credentials — where they can't belong).

But it's going to greatly facilitate setup for staff users if settings that are currently shown in admin/settings/ were editable there too. (Obvious examples are adding social media links, etc, but also institution names, etc.

Use Cloudflare to force https and document it

We've already set up the Cloudflare https page rules on the domains but need to tidy up (or decide to remove) the warnings in the Flask code — requests that originated as http but are handled by Cloudflare seem to be insecure from Flask's POV; check what is feasible here to remove confusing warnings on the page.

implement external static page hosting

By default, static pages are hosted (successfully!) on the server itself now. But it must be possible to pass that out so, ultimately, anything can be overridden, especially in the tech notes which can be quite opinionated (and we're not offering a mechanism for updating them through the web interface).

Currently there's a misleadingly named (legacy) setting GITHUB_PAGES_URL — this is no longer sensible (and shouldn't be in the "GitHub" settings group either (probably makes most sense in "Server") because it's not github pages. Rename to something like TECH_NOTES_URL, and should be blank if it's on this server (the default). However, that doesn't allow tech notes to be entirely suppressed.

(Currently the other item like this is the PROJECT_WORKFLOW_URL, but that's a single-page case. Also, dangerously, that currently has three behaviours:

  1. if it's empty, suppress the link entirely (there is no project workflow page)
  2. if it starts with http then it's an external URL
  3. if it's anything else force the default of project/workflow (yes even binky)

This seems wrong, so maybe should validate the entry to makes sure if it's not 1. or 2. it can only be project/workflow. This example is probably the model for the TECH_NOTES_URL

There is presumably an equivalent case for the three (or maybe two) project pages being hosted externally:

  • project index
  • project report
  • project tasks → this seems less relevant, since we're allowing task content to be edited on the server

Ultimately this is all about when the admin can and cannot edit text that's presented to students through the server.

make student GitHub insertion configurable

This isn't needed for RHUL, because it will be used for that, so this issue is also to ensure that the existing mechanism exists (e.g., having moved tasks into the database, there's no longer an issues.csv in the repo, so need to check we're picking the generated one up correctly.

There might be quite a lot of work to do checking how much technotes (and workflow?) is affected by not having the GitHub integration (my suspicion is: there's a lot, and this becomes a big issue).

Serve info (task list, notes, etc) from server, not GH pages

This makes deployment, i.e., the server, the standalone and complete project server.

Proposed solution: to generate the docs /info/ directory that is server as static HTML using Jekyll as that requires minimal change to existing info pages, of which there are plenty).

return diagnostic in the try-except block on the buggy race editor

This could be an issue on https://github.com/RHUL-CS-Projects/CS1999-buggy-race-editor but I don't want to do that while the project is running.

It turns out my belief that there are not useful diagnostics coming back from SQLite is simply wrong (maybe it's changed since 18 months ago? hard to believe) — so maybe that except block should only be catching sqlite3.OperationalError exceptions.

This would have been much kinder to the students because it does send back errors like:

sqlite3.OperationalError: no such column: qty_bananas

This just needs fixing with something like this:

        except Exception as e:
            con.rollback()
            msg = f"error in update operation: {e}"

or

        except sqlite3.OperationalError as e:
            con.rollback()
            msg = f"error in update operation: {e}"

Argh! this would have been much kinder!

fix bulk upload to accept more data

There's a problem with the bulk upload timing out but maybe we can replace this with a mechanism for injecting CSV → SQL directory (i.e., not by uploading to the web).

Didn't investigate why the existing method is _so inefficient though — but it is: times out if too many (and yet, not that many) users are added in one go.

use `url_for` for static URLs too

Specifically, added the buggy illustrations with hardcoded URLs: fix that

How does this work in CSS assets? (answer: presumably don't worry about it)

refactor the routes inside the app

Because we have an opportunity to refactor, we should seize it


It's currently all over the place for no good reason, maybe tidy it up.
One consequence is the views are disorganised so it's harder than it should be to find the right method/route in the code.

page currently maybe better?
user "home" (upload form) /users/ /user
upload buggy data /buggies/json /buggy/upload
view own buggy /buggy
user settings /users/settings /user/settings
change password settings /users/password /user/password
admin home /admin /admin ?
admin list of users /admin/users /admin/users
admin list of students /admin /admin/students
admin list of buggies /admin/buggies
registration /register
bulk-register /admin/bulk-register ✓ or /admin/register?
server settings /admin/settings/

update Flask version

The requirements/prod.txt want Flask 1.1.2 but Flask V1.X.X is no longer supported.

Recommend: go up to 2.1.2

Note that currently the 1.1.2 requirement breaks the build, because (from stackoverflow):

Jinja is a dependency of Flask and Flask V1.X.X uses the escape module from Jinja, however recently support for the escape module was dropped in newer versions of Jinja

⚠️ Note: we need to update the Buggy Editor code too ⚠️

Demo buggy race server

I think we can be generous and allow for a demo buggy race server, open for general registration on the main page to allow people to get a feel for how it works. This would just require some adaptations to the configs but we could run https://demo.buggyrace.net.

We are already deploying to a dev environment, so in the end it makes sense to move this over to a fully functional (or partly mock-up, i.e. admin features) demo environment.

replace Bootstrap with something nicer

Might be tailwind

am not enjoying using bootstrap and I think I could do a nicer job if I was out of it... but it's going to be quite a big job.

History: Bootstrap was part of the cookie-cutter repo that seeded this one, and did what it said on the tin. I just... don't like using it very much.

suppress "https" warning preventing GitHub setup for students

Currently the explicit warning of no https is distracting and potentially wrong (because the Flask app might not know about the https status since it's being applied outside — I think we saw this before).

Either take it out completely or make sure it's conditional on the (probably best OFF) FORCE_REDIRECT_HTTP_TO_HTTPS setting that isn't doing much except getting in the way at the moment.

track special tasks in tech_notes/pages

The API page helpfully links to task 5-API (which is when students need it¹) but that link will break if the task list is edited so either the phase or (less likely?) name are changed.

So "TASK_FOR_API" might be a config setting so, if it's changed, the docs/pages can keep up to date.

There are a few other places where the tech notes mention tasks too: need to think about this because currently admins can edit the tasks but not the tech_notes.


¹ ...although there's a good case for that being in phase 4 because it's interesting and less involved than the user stuff)

write race simulation

See DEVELOPMENT.md for current state-of-play


Doesn't run especially publicaly but the results should be published.

If it's not automated yet, needs to be published as HTML on the server by hand.

General idea:

  • check eligibility of buggies:
    1. rules are not violated (only even numbers of wheels)
    2. calculated cost of buggy is below race limit
  • manage in turns
  • each turn calculate
    • acceleration depending on mass and power
    • risk of puncture
    • risk of catastrophe
    • update mass by removing spent fuel
    • switch to aux power if the primary is used up
    • stop when either no buggies are running or one has... won?

handle number on end of repo name when forking

If a user forks the editor repo and then deletes it from their own account, if they fork it again (because our button correctly reappears), then the new (second and beyond) repo gets created with -1, -2-, -3 etc appended on the end. That is, GitHub remembers that this repo used to exist, and doesn't create the new one with a name clash. It looks like this is breaking the subsequent work on the repo injecting images.

I think this is new behaviour on GitHub, because I deleted and re-forked the repo multiple times when we were first setting this up, and it didn't used to happen.

add per-user API key to user records

This was always the intention: in addition to the API secret that the user sets for themselves — admin should be able to set an API key for any user. This more closely models a useful application (that the API key is granted on a per-user basis by admin, and also that the secret set by the user is similar to e.g., payment or transaction info) and also notifies admin/staff when a student is attempting this task (5-API)

ensure all download files are named consistently

Should always be inserting PROJECT_SLUG as a prefix if there is one, otherwise a slugified PROJECT_CODE if there is one (otherwise: no prefix).

Now we have quite a few download files — both for admin and students — this should be available in the utils module.

fix nav bar drop-down

The responsive navbar from cookiecutter-flask never seemed to work so need to fix that, because it's obvious (current bodge is to jump to the footer which contains the same links)

implement generation of task page

  1. Most inefficient: render it live on every request, which includes markdown conversion. Implement this first...
  2. Then call that render_template once, and store the output in a known file, which is then served by flask. This is probably the best middle way
  3. Maybe? Investigate optionally adding it to tech notes — but I don't think there's any need if 2 works well enough.

The only concern is lack of persistent filestore in some implementations (e.g., heroku), which means should render the template on startup. This might be correct; and then record the timestamp when it happened.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.