views.py 721 B

1234567891011121314151617181920
  1. # Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
  2. # Copyright: (c) <spug.dev@gmail.com>
  3. # Released under the AGPL-3.0 License.
  4. from django.views.generic import View
  5. from apps.notify.models import Notify
  6. from libs import json_response, JsonParser, Argument
  7. class NotifyView(View):
  8. def get(self, request):
  9. notifies = Notify.objects.filter(unread=True)
  10. return json_response(notifies)
  11. def patch(self, request):
  12. form, error = JsonParser(
  13. Argument('ids', type=list, help='参数错误')
  14. ).parse(request.body)
  15. if error is None:
  16. Notify.objects.filter(id__in=form.ids).update(unread=False)
  17. return json_response(error=error)