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.

routes.py 2.5 KiB

6 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. from flask import abort, g, redirect, request, url_for
  3. from flask_mako import render_template
  4. from .getters import get_current
  5. from .._provided import blueprint, config
  6. __all__ = ["home", "navitem", "current_campaign", "campaign", "operation",
  7. "set_campaign"]
  8. def home():
  9. """Render and return the main campaign page."""
  10. current = get_current()
  11. if current:
  12. campaign = config["campaigns"][current]
  13. return render_template("campaigns/campaign.mako",
  14. name=current, campaign=campaign, enabled=True)
  15. return render_template("campaigns/empty.mako")
  16. def navitem():
  17. """Render and return the navigation item for this module."""
  18. current = get_current()
  19. if current:
  20. result = render_template("campaigns/navitem.mako", current=current)
  21. return result.decode("utf8")
  22. @blueprint.rroute("/campaign")
  23. def current_campaign():
  24. """Render and return the current campaign page."""
  25. current = get_current()
  26. if current:
  27. return redirect(url_for(".campaign", name=current), 303)
  28. return render_template("campaigns/empty.mako")
  29. @blueprint.rroute("/campaigns/<name>")
  30. def campaign(name):
  31. """Render and return a campaign page."""
  32. if name not in config["campaigns"]:
  33. abort(404)
  34. campaign = config["campaigns"][name]
  35. enabled = name in config["enabled"]
  36. return render_template("campaigns/campaign.mako",
  37. name=name, campaign=campaign, enabled=enabled)
  38. @blueprint.rroute("/campaigns/<cname>/operations/<opname>")
  39. def operation(cname, opname):
  40. """Render and return an operation page."""
  41. if cname not in config["campaigns"]:
  42. abort(404)
  43. campaign = config["campaigns"][cname]
  44. if opname not in campaign["operations"]:
  45. abort(404)
  46. operation = campaign["operations"][opname]
  47. enabled = cname in config["enabled"] and opname in campaign["enabled"]
  48. return render_template("campaigns/operation.mako",
  49. cname=cname, campaign=campaign, opname=opname,
  50. operation=operation, enabled=enabled)
  51. @blueprint.rroute("/settings/campaign", methods=["POST"])
  52. def set_campaign():
  53. """Update the user's currently selected campaign."""
  54. campaign = request.form.get("campaign")
  55. if campaign not in config["enabled"]:
  56. abort(400)
  57. g.auth.set_character_modprop("campaigns", "current", campaign)
  58. return redirect(url_for(".campaign", name=campaign), 303)