A corporation manager and dashboard for EVE Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

46 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. from flask import abort, g, redirect, request, url_for
  3. from flask_mako import render_template
  4. from ._provided import blueprint, config
  5. def get_current():
  6. """Return the name of the currently selected campaign, or None."""
  7. if not config["enabled"]:
  8. return None
  9. setting = g.auth.get_character_modprop("campaigns", "current")
  10. if not setting or setting not in config["enabled"]:
  11. return config["enabled"][0]
  12. return setting
  13. def home():
  14. """Render and return the main campaign page."""
  15. current = get_current()
  16. if current:
  17. campaign = config["campaigns"][current]
  18. return render_template(
  19. "campaigns/campaign.mako", name=current, campaign=campaign)
  20. return render_template("campaigns/empty.mako")
  21. def navitem():
  22. """Render and return the navigation item for this module."""
  23. current = get_current()
  24. if current:
  25. result = render_template("campaigns/navitem.mako", current=current)
  26. return result.decode("utf8")
  27. @blueprint.rroute("/campaign")
  28. def campaign():
  29. """Render and return the current campaign page."""
  30. return home()
  31. @blueprint.rroute("/settings/campaign", methods=["POST"])
  32. def set_campaign():
  33. """Update the user's currently selected campaign."""
  34. campaign = request.form.get("campaign")
  35. if campaign not in config["enabled"]:
  36. abort(400)
  37. g.auth.set_character_modprop("campaigns", "current", campaign)
  38. return redirect(url_for(".campaign"), 303)