6
0

EditProjectName.py 834 B

12345678910111213141516171819202122232425262728293031323334
  1. from flask import make_response, abort
  2. from flask.views import View, request
  3. from pycs.database.Project import Project
  4. from pycs.frontend.notifications.NotificationManager import NotificationManager
  5. class EditProjectName(View):
  6. """
  7. edit a projects name
  8. """
  9. # pylint: disable=arguments-differ
  10. methods = ['POST']
  11. def dispatch_request(self, identifier):
  12. # extract request data
  13. data = request.get_json(force=True)
  14. if data.get('name') is None:
  15. return abort(400)
  16. # find project
  17. project = Project.query.get(identifier)
  18. if project is None:
  19. return abort(404)
  20. # set name
  21. project.name = data['name']
  22. project.commit()
  23. NotificationManager.edited("project", project.id, Project)
  24. return make_response()