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.
 
 
 
 
 

58 lines
1.9 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 current_campaign():
  29. """Render and return the current campaign page."""
  30. current = get_current()
  31. if current:
  32. return redirect(url_for(".campaign", name=current), 303)
  33. return render_template("campaigns/empty.mako")
  34. @blueprint.rroute("/campaigns/<name>")
  35. def campaign(name):
  36. """Render and return a campaign page."""
  37. if name not in config["enabled"]:
  38. abort(404)
  39. campaign = config["campaigns"][name]
  40. return render_template(
  41. "campaigns/campaign.mako", name=name, campaign=campaign)
  42. @blueprint.rroute("/settings/campaign", methods=["POST"])
  43. def set_campaign():
  44. """Update the user's currently selected campaign."""
  45. campaign = request.form.get("campaign")
  46. if campaign not in config["enabled"]:
  47. abort(400)
  48. g.auth.set_character_modprop("campaigns", "current", campaign)
  49. return redirect(url_for(".campaign", name=campaign), 303)