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.
 
 
 
 
 

73 lines
2.6 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("campaigns/campaign.mako",
  19. name=current, campaign=campaign, enabled=True)
  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["campaigns"]:
  38. abort(404)
  39. campaign = config["campaigns"][name]
  40. enabled = name in config["enabled"]
  41. return render_template("campaigns/campaign.mako",
  42. name=name, campaign=campaign, enabled=enabled)
  43. @blueprint.rroute("/campaigns/<cname>/operations/<opname>")
  44. def operation(cname, opname):
  45. """Render and return an operation page."""
  46. if cname not in config["campaigns"]:
  47. abort(404)
  48. campaign = config["campaigns"][cname]
  49. if opname not in campaign["operations"]:
  50. abort(404)
  51. operation = campaign["operations"][opname]
  52. enabled = cname in config["enabled"] and opname in campaign["enabled"]
  53. return render_template("campaigns/operation.mako",
  54. cname=cname, campaign=campaign, opname=opname,
  55. operation=operation, enabled=enabled)
  56. @blueprint.rroute("/settings/campaign", methods=["POST"])
  57. def set_campaign():
  58. """Update the user's currently selected campaign."""
  59. campaign = request.form.get("campaign")
  60. if campaign not in config["enabled"]:
  61. abort(400)
  62. g.auth.set_character_modprop("campaigns", "current", campaign)
  63. return redirect(url_for(".campaign", name=campaign), 303)