Permalink
Browse files

Bring back the friendly date time for file and image list views.

  • Loading branch information...
1 parent 86c9346 commit 7368fb0d67011b4e27be743b6feb97ede58bcdb9 @markotibold markotibold committed Nov 12, 2012
Showing with 12 additions and 8 deletions.
  1. +9 −0 fiber/rest_api/fields.py
  2. +3 −1 fiber/rest_api/serializers.py
  3. +0 −7 fiber/rest_api/views.py
@@ -2,6 +2,8 @@
from fiber.app_settings import PERMISSION_CLASS
from fiber.utils import class_loader
+from fiber.utils.date import friendly_datetime
+
PERMISSIONS = class_loader.load_class(PERMISSION_CLASS)
@@ -14,3 +16,10 @@ class CanEditField(serializers.Field):
def field_to_native(self, obj, field_name):
return PERMISSIONS.can_edit(self.context['request'].user, obj)
+
+class UpdatedField(serializers.Field):
+ """
+ Return a friendly timestamp.
+ """
+ def field_to_native(self, obj, field_name):
+ return friendly_datetime(obj.updated)
@@ -2,7 +2,7 @@
from fiber.models import Page, PageContentItem, ContentItem, File, Image
-from .fields import CanEditField
+from .fields import CanEditField, UpdatedField
class PageSerializer(serializers.ModelSerializer):
@@ -30,6 +30,7 @@ class FileSerializer(serializers.ModelSerializer):
file_url = serializers.Field(source='file.url')
filename = serializers.Field(source='get_filename')
can_edit = CanEditField()
+ updated = UpdatedField()
class Meta:
model = File
@@ -41,6 +42,7 @@ class ImageSerializer(serializers.ModelSerializer):
filename = serializers.Field(source='get_filename')
size = serializers.Field(source='get_size')
can_edit = CanEditField()
+ updated = UpdatedField()
class Meta:
model = Image
@@ -143,13 +143,6 @@ def check_fields(self, order_by):
if order_by not in self.orderable_fields:
raise ErrorResponse(status=HTTP_400_BAD_REQUEST, content="Can not order by the passed value.")
- def filter_response(self, obj):
- obj = super(PaginatedListView, self).filter_response(obj)
- if self.request.method.upper() == 'GET':
- obj['rows'] = obj['results']
- obj.pop('results')
- return obj
-
class FileListView(PaginatedListView):

0 comments on commit 7368fb0

Please sign in to comment.