Source

fat-po-editor / fat / fat_po_editor / views / repository.py

Full commit
# -*- coding: utf-8 -*-

from django.http import HttpResponse
from django.utils.translation import ugettext as _

from fat_po_editor.util.json import json_http_response_success
from fat_po_editor.util.json import json_http_response_fail
from fat_po_editor.util.json import json_http_response
from fat_po_editor.bl import repository

def add(request):
    if request.method == 'POST':
        repository_path = request.POST.get('path', '')
        try:
            repository.add(repository_path)
        except repository.UserAlertError as e:
            return json_http_response_fail({
                        'message': e.message})
        
        repositories = list(x.path for x in repository.get_all() or [])
        
        return (
            json_http_response_success({
                'message': _(u'Repository path %(repository_path)s was added') % dict(
                    repository_path=repository_path),
                'repositories': repositories}))
    else:
        return HttpResponse(u'Waiting for POST data')

def path_autocomplete(request):
    from fat_po_editor.util.path import autocomplete
    
    path = request.GET.get('term', '')
    try:
        paths = autocomplete(path)
    except repository.UserAlertError as e:
        return json_http_response_fail({
                    'message': e.message})
    return json_http_response(paths)