def toggle(request, slug, template='files/file_list_row.html'): res = {} if request.method == "POST": try: file = POFile.objects.get(slug=slug) except: return XMLResponse({'message': ResponseMessage.error(_('File not found.'))}) else: if not file.release.enabled or not file.release.project.enabled: return XMLResponse({'message': ResponseMessage.error(_('Sorry, you are not supposed to change anything on a disabled component.'))}) team = Team.objects.get(project=file.component.project, language=file.language) if not team.is_member(request.user): return XMLResponse({'message': ResponseMessage.error(_('You are not a member of this team.'))}) res['id'] = file.slug if file.locked: # if the file is locked by the same user or the user is admin or coord # then can unlock the file if file.locks.get().can_unlock(request.user): if file.submits.all_pending(): res['message'] = ResponseMessage.info(_('%s will be automatically unlocked once submitted.') % file.filename) else: file.locks.get().delete() if request.POST.has_key('text'): comment = request.POST.get('text') else: comment = '' POFileLog.objects.create(pofile=file, user=request.user, action='R', comment=comment) res['message'] = ResponseMessage.success(_('Unlocked %s') % file.filename) else: res['message'] = ResponseMessage.error(_('%s is already locked.') % file.filename) else: file.locks.create(owner=request.user) res['message'] = ResponseMessage.success(_('Locked %s') % file.filename) page = render_to_string(template, {'pofile': file, 'team': team}, context_instance = RequestContext(request)) res['content_HTML'] = page return XMLResponse(res) else: raise Http403