class FixedFileWrapper(FileWrapper):
+
def __iter__(self):
self.filelike.seek(0)
return self
+
def send_file(request, filename, content_type='image/jpeg'):
"""
Send a file through Django without loading the whole file into
response['Content-Length'] = os.path.getsize(filename)
return response
+
def nginx_media_accel(request, filename):
"""Send a protected medie file through nginx with X-Accel-Redirect"""
response['X-Accel-Redirect'] = url
return response
-def render(request, template, data = None, mimetype = None):
+
+def render(request, template, data=None, content_type=None):
return render_to_response(template, data, context_instance=RequestContext(request),
- mimetype=mimetype)
+ content_type=content_type)
+
def stream_from_processor(decoder, encoder, flag):
pipe = decoder | encoder
flag.value = True
flag.save()
+
def stream_from_file(file):
chunk_size = 0x100000
f = open(file, 'r')
break
yield chunk
+
def get_item_access(item, user):
# Item access rules according to this workflow:
# https://docs.google.com/spreadsheet/ccc?key=0ArKCjajoOT-fdDhJSDZoaUhqdDJvVkY5U3BXUWpNT0E#gid=0
access = 'full'
elif item.collection.public_access != 'mixed':
- if user.is_authenticated() :
+ if user.is_authenticated():
if item.collection.public_access == 'metadata' and item.collection.auto_period_access:
access = 'full'
else:
access = item.collection.public_access
elif item.collection.public_access == 'mixed':
- if user.is_authenticated() :
+ if user.is_authenticated():
if item.public_access == 'metadata' and item.auto_period_access:
access = 'full'
else:
return access
+
def get_revisions(nb, user=None):
last_revisions = Revision.objects.order_by('-time')
if user:
revisions.append({'revision': revision, 'element': element})
return revisions
+
def get_playlists(request, user=None):
if not user:
user = request.user
element = mods[type].objects.get(id=resource.resource_id)
except:
element = None
- resources.append({'element': element, 'type': resource.resource_type, 'public_id': resource.public_id })
+ resources.append({'element': element, 'type': resource.resource_type, 'public_id': resource.public_id})
playlists.append({'playlist': playlist, 'resources': resources})
- #add by Killian Mary for sort playlist by title
+ # add by Killian Mary for sort playlist by title
playlists.sort(key=lambda x: x['playlist'].title)
return playlists
media.title = title.replace('\n', '').strip()
media.save()
+
def auto_code(collection):
items = collection.items.all()
suffixes = []
suffixes.append(suffix)
if suffixes:
- return collection.code + '_' + str(max(suffixes)+1)
+ return collection.code + '_' + str(max(suffixes) + 1)
else:
return collection.code + '_001'
def get_room(content_type=None, id=None, name=None):
rooms = jqchat.models.Room.objects.filter(content_type=content_type,
- object_id=id)
+ object_id=id)
if not rooms:
room = jqchat.models.Room.objects.create(content_type=content_type,
- object_id=id,
- name=name[:254])
+ object_id=id,
+ name=name[:254])
else:
room = rooms[0]
return room