Skip to content

Commit

Permalink
Merge pull request #142 from markotibold/rf2
Browse files Browse the repository at this point in the history
Porting to REST Framework 2, thanks @markotibold
  • Loading branch information
dbunskoek committed Dec 21, 2012
2 parents e323894 + f028db8 commit 026cea8
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 392 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: python
python:
- 2.6
install:
- "pip install . --use-mirrors"
- "pip install -r testproject/requirements.txt --use-mirrors"
script:
- cd testproject
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog

## dev

* Enhancement: Ported to REST Framework. **Note:** projects with local REST Framework 0.3.X or 0.3.4
dependencies will break.
* Enhancements: Updated README file and added this changelog.


## 0.9.9.1

**Date**: 6th Dec 2012

* Security-Bugfix: Changed permission check in API from IsAuthenticated to IsAdminUser


## 0.9.9

**Date**: 27th Nov 2012

* Enhancement: Title fields of pages are now required. Solves inconsistent behaviour in the UI.

---

Older changes not documented. Revert to the git log for details.
104 changes: 0 additions & 104 deletions INSTALL.rst

This file was deleted.

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include LICENSE.rst
include README.rst
include README.md
recursive-include fiber/templates *
recursive-include fiber/static *
59 changes: 27 additions & 32 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
.. image:: https://secure.travis-ci.org/ridethepony/django-fiber.png
:target: http://travis-ci.org/#!/ridethepony/django-fiber
[![Travis build image][travis-build-image]][travis]

============
Django Fiber
============
[travis]: http://travis-ci.org/#!/ridethepony/django-fiber
[travis-build-image]: https://secure.travis-ci.org/ridethepony/django-fiber.png

# Django Fiber

---

**Announcement**: We've upgraded to Django REST Framework 2. This means that if you want to use the latest
Fiber and you use Django REST Framework 0.3.X or 0.4.X for your own project, you'll have to bite the bullet and upgrade your local REST Framework code.

---

Do you want to see a Django Fiber screencast, to get a feel for what it can do for you? Check it out here:
http://vimeo.com/ridethepony/django-fiber
Expand All @@ -14,36 +21,26 @@ https://github.com/ridethepony/django-fiber-example
Convinced? Want to use Django Fiber in your own Django project? Then follow the instructions below:


Installation:
=============
## Installation

We're assuming you are using Django 1.3.x or 1.4.

::

$ pip install django-fiber


Requirements:
=============
## Requirements

These dependencies are automatically installed:

::

Pillow==1.7.7
djangorestframework==0.3.3
django-mptt==0.5.1
django-compressor>=0.7.1


Settings:
=========

settings.py
-----------
## Settings

::
### settings.py

import django.conf.global_settings as DEFAULT_SETTINGS

Expand All @@ -59,11 +56,10 @@ settings.py
INSTALLED_APPS = (
...
'django.contrib.staticfiles',
'djangorestframework',
'mptt',
'compressor',
'fiber',
...
...
)

import os
Expand All @@ -75,10 +71,7 @@ settings.py
'compressor.finders.CompressorFinder',
)

urls.py
-------

::
### urls.py

from django.conf import settings

Expand All @@ -92,19 +85,21 @@ urls.py
)


Post-installation:
==================
## Post-installation

Create database tables::
Create database tables:

$ python manage.py syncdb

All static Fiber files need to be symlinked in (or copied to) your media folder::
All static Fiber files need to be symlinked in (or copied to) your media folder:

$ python manage.py collectstatic --link


Further documentation:
======================
## Further documentation
For further usage and configuration details take a look at our documentation project at [readthedocs](https://django-fiber.readthedocs.org/).

## Changelog
See CHANGELOG.md for the latest changes.

You can find usage instructions, and other documentation, in the docs folder.
[changelog]: CHANGELOG.md
9 changes: 9 additions & 0 deletions fiber/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ def delete(self, *args, **kwargs):
def get_image_information(self):
self.width, self.height = get_image_dimensions(self.image) or (0, 0)

def get_filename(self):
return os.path.basename(self.image.name)

def get_size(self):
return '%s x %d' % (self.width, self.height)


class File(models.Model):
created = models.DateTimeField(_('created'), auto_now_add=True)
Expand All @@ -335,3 +341,6 @@ def save(self, *args, **kwargs):
def delete(self, *args, **kwargs):
os.remove(os.path.join(settings.MEDIA_ROOT, str(self.file)))
super(File, self).delete(*args, **kwargs)

def get_filename(self):
return os.path.basename(self.file.name)
25 changes: 25 additions & 0 deletions fiber/rest_api/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from rest_framework import serializers

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)


class CanEditField(serializers.Field):
"""
A custom field that returns True if request.user has
permission to edit obj.
"""

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)
16 changes: 0 additions & 16 deletions fiber/rest_api/forms.py

This file was deleted.

Loading

0 comments on commit 026cea8

Please sign in to comment.