@piwik_track
def read(self, request, since):
return self.changes(request, since)
+
+
+class PictureHandler(BaseHandler):
+ model = Picture
+ fields = ('slug', 'title')
+ allowed_methods = ('POST',)
+
+ def create(self, request):
+ if not request.user.has_perm('catalogue.add_book'):
+ return rc.FORBIDDEN
+
+ data = json.loads(request.POST.get('data'))
+ form = BookImportForm(data)
+ if form.is_valid():
+ form.save()
+ return rc.CREATED
+ else:
+ return rc.NOT_FOUND
from api import handlers
from catalogue.models import Book
-
+from picture.models import Picture
auth = OAuthAuthentication(realm="Wolne Lektury")
fragment_resource = Resource(handler=handlers.FragmentDetailHandler)
fragment_list_resource = Resource(handler=handlers.FragmentsHandler)
+picture_resource = Resource(handler=handlers.PictureHandler)
urlpatterns = patterns(
'piston.authentication',
# tags by category
url(r'^(?P<category>[a-z0-9-]+)/$', tag_list_resource),
+
+ # picture by slug
+ url(r'^pictures/$', picture_resource)
)
return self.slug
@classmethod
- def from_xml_file(cls, xml_file, images_path=None, overwrite=False):
+ def from_xml_file(cls, xml_file, image_file=None, overwrite=False):
"""
Import xml and it's accompanying image file.
"""
picture.tags = catalogue.models.Tag.tags_from_info(picture_xml.picture_info)
- img = picture_xml.image_file()
- try:
- picture.image_file.save(path.basename(picture_xml.image_path), File(img))
- finally:
- img.close()
+ if image_file is not None:
+ img = image_file
+ else:
+ img = picture_xml.image_file()
+
+ picture.image_file.save(path.basename(picture_xml.image_path), File(img))
picture.xml_file.save("%s.xml" % picture.slug, File(xml_file))
picture.save()