Esempio n. 1
0
def savemarkers(request):
    if request.method == "POST":
        collection = get_svohp_collection()
        check_access(request.user, collection, write=True, fail_if_denied=True)
        record = get_object_or_404(collection.records, name=request.POST['name'])
        field = Field.objects.get(standard__prefix='dc', name='description')
        fv, created = FieldValue.objects.get_or_create(record=record,
                                              field=field,
                                              hidden=True,
                                              label='Markers',
                                              defaults=dict(value=''))
        if created or fv.value == '':
            markers = dict()
        else:
            markers = dict(map(lambda v: v.split(','), fv.value.split('\n')))
        markers[request.POST['index']] = request.POST['time']
        to_remove = []
        prev_val = None
        for key in sorted(markers.keys()):
            if prev_val:
                if prev_val >= markers[key]:
                    to_remove.append(key)
            else:
                prev_val = markers[key]
        for key in to_remove:
            del markers[key]
        fv.value = '\n'.join('%s,%s' % (v,k) for v,k in markers.iteritems())
        fv.save()
        return dict(message="Markers saved")
    else:
        return dict(result='Invalid method. Use POST.')
Esempio n. 2
0
 def _check_permission_for_user(self, user, **permissions):
     # checks if user is owner or has ACL access
     if check_access(user, self, **permissions):
         return True
     # if record does not have individual ACL...
     if len(_records_with_individual_acl_by_ids([self.id])) > 0:
         return False
     # ...check collection access
     return len(accessible_ids(user, self.collection_set, **permissions)) > 0
Esempio n. 3
0
 def _check_permission_for_user(self, user, **permissions):
     # checks if user is owner or has ACL access
     if check_access(user, self, **permissions):
         return True
     # if record does not have individual ACL...
     if len(_records_with_individual_acl_by_ids([self.id])) > 0:
         return False
     # ...check collection access
     return filter_by_access(user, self.collection_set, **permissions).count() > 0
Esempio n. 4
0
def interview(request, name):

    collection = get_svohp_collection()
    record = get_object_or_404(collection.records, name=name)
    fvs = record.get_fieldvalues(hidden=True)
    transcript = re.sub('(\n\s*)+', '\n\n', filter(lambda f: f.label=='Transcript', fvs)[0].value).strip()
    markers = filter(lambda f: f.label=='Markers', fvs)
    if markers:
        markers = dict(map(lambda v: v.split(','), markers[0].value.split('\n')))
    mp3 = record.media_set.filter(mimetype='audio/mpeg')[0]
    edit = check_access(request.user, collection, write=True) and (request.GET.get('edit') == 'edit')

    return render_to_response('svohp-interview.html',
                              {'data': dict((fv.field.name, fv.value) for fv in filter(lambda f: not f.hidden, fvs)),
                               'transcript': transcript,
                               'record': record,
                               'mp3url': mp3.get_absolute_url(),
                               'edit': edit,
                               'markers': markers,
                               },
                              context_instance=RequestContext(request))
Esempio n. 5
0
 def editable_by(self, user):
     return self.record.editable_by(user) and check_access(
         user, self.storage, write=True)
Esempio n. 6
0
 def editable_by(self, user):
     return self.record.editable_by(user) and check_access(user, self.storage, write=True)
Esempio n. 7
0
 def editable_by(self, user):
     return (
         # checks if user is owner:
         check_access(user, self, write=True) or
         # or if user has write access to collection:
         len(accessible_ids(user, self.collection_set, write=True)) > 0)