serializers.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from django.utils.translation import gettext_lazy as _
  2. from rest_framework import serializers
  3. from .models import UserReport
  4. # Copy credited to OSS Sentry sentry/web/error_page_embed.py
  5. DEFAULT_TITLE = _("It looks like we're having issues.")
  6. GENERIC_ERROR = _(
  7. "An unknown error occurred while submitting your report. Please try again."
  8. )
  9. FORM_ERROR = _("Some fields were invalid. Please correct the errors and try again.")
  10. SENT_MESSAGE = _("Your feedback has been sent. Thank you!")
  11. DEFAULT_SUBTITLE = _("Our team has been notified.")
  12. DEFAULT_SUBTITLE2 = _("If you'd like to help, tell us what happened below.")
  13. DEFAULT_NAME_LABEL = _("Name")
  14. DEFAULT_EMAIL_LABEL = _("Email")
  15. DEFAULT_COMMENTS_LABEL = _("What happened?")
  16. DEFAULT_CLOSE_LABEL = _("Close")
  17. DEFAULT_SUBMIT_LABEL = _("Submit Crash Report")
  18. class ErrorPageEmbedSerializer(serializers.Serializer):
  19. dsn = serializers.CharField()
  20. eventId = serializers.CharField()
  21. title = serializers.CharField(default=DEFAULT_TITLE)
  22. subtitle = serializers.CharField(default=DEFAULT_SUBTITLE)
  23. subtitle2 = serializers.CharField(default=DEFAULT_SUBTITLE2)
  24. labelName = serializers.CharField(default=DEFAULT_NAME_LABEL)
  25. labelEmail = serializers.CharField(default=DEFAULT_EMAIL_LABEL)
  26. labelComments = serializers.CharField(default=DEFAULT_COMMENTS_LABEL)
  27. labelClose = serializers.CharField(default=DEFAULT_CLOSE_LABEL)
  28. labelSubmit = serializers.CharField(default=DEFAULT_SUBMIT_LABEL)
  29. errorGeneric = serializers.CharField(default=GENERIC_ERROR)
  30. errorFormEntry = serializers.CharField(default=FORM_ERROR)
  31. successMessage = serializers.CharField(default=SENT_MESSAGE)
  32. class UserReportSerializer(serializers.ModelSerializer):
  33. eventId = serializers.CharField(source="event_id.hex")
  34. event = serializers.SerializerMethodField()
  35. user = serializers.CharField(default=None) # stub
  36. dateCreated = serializers.DateTimeField(source="created")
  37. class Meta:
  38. model = UserReport
  39. fields = (
  40. "eventId",
  41. "name",
  42. "event",
  43. "user",
  44. "dateCreated",
  45. "id",
  46. "comments",
  47. "email",
  48. )
  49. def get_event(self, obj):
  50. return {
  51. "eventId": obj.event_id.hex,
  52. }