Ejemplo n.º 1
0
def overview(request):
    """ overview of orders """

    context = {}
    account, account_params = get_mygengo_api('account', request)
    account.getBalance('json', account_params)
    balance_response = json.loads(account.getResponseBody())
    if 'response' not in balance_response:
        return HttpResponse(
            'myGengo API error. Check that your API keys are correctly set.')
    context['balance'] = balance_response['response']
    account.getStats('json', account_params)
    context['stats'] = json.loads(account.getResponseBody())['response']
    jobs, jobs_params = get_mygengo_api('jobs', request)
    jobs.getJobs('json', jobs_params)
    jobs_items = {
        'available': [],
        'reviewable': [],
        'approved': [],
        'revising': []
    }
    joblist = json.loads(jobs.getResponseBody())['response']
    for job in joblist:
        job['date'] = datetime.datetime.fromtimestamp(
            job['ctime']).strftime("%b %d %Y")
    context['jobs'] = joblist
    return render_to_response('overview.html',
                              RequestContext(request, context))
Ejemplo n.º 2
0
def service_quote(request):
    """ get quote for service """

    service, service_params = get_mygengo_api('service', request)
    job = {
        'body_src': request.REQUEST['body'],
        'lc_src': request.REQUEST['lc_src'],
        'lc_tgt': request.REQUEST['lc_tgt'],
        'tier': request.REQUEST['tier']
    }
    data = {'jobs': [job]}
    service_params = {
        'api_key': service_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(service_params,
                            separators=(',', ':'),
                            sort_keys=True)
    service_params = get_api_sig(service_params, service, query_json)
    service.getQuote('json', service_params)
    response_json = json.loads(service.getResponseBody())
    logging.info(service_params)
    logging.info(response_json)
    if 'err' in response_json:
        return HttpResponse(json.dumps(response_json),
                            mimetype="application/json")
    job_info = response_json['response']['jobs'][0]
    job_info['credits'] = "%.2f" % round(job_info['credits'],
                                         2)  # round to 2 decimal places
    return HttpResponse(json.dumps(job_info), mimetype="application/json")
Ejemplo n.º 3
0
def service_quote(request):
    """ get quote for service """

    service, service_params = get_mygengo_api('service', request)
    job = {
        'body_src': request.REQUEST['body'],
        'lc_src': request.REQUEST['lc_src'],
        'lc_tgt': request.REQUEST['lc_tgt'],
        'tier': request.REQUEST['tier']
    }
    data = { 'jobs': [job] }
    service_params = {
        'api_key': service_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(service_params, separators=(',', ':'), sort_keys=True)
    service_params = get_api_sig(service_params, service, query_json)        
    service.getQuote('json', service_params)
    response_json = json.loads(service.getResponseBody())
    logging.info(service_params)
    logging.info(response_json)
    if 'err' in response_json:
        return HttpResponse(json.dumps(response_json), mimetype="application/json")
    job_info = response_json['response']['jobs'][0]
    job_info['credits'] = "%.2f" % round(job_info['credits'],2) # round to 2 decimal places 
    return HttpResponse(json.dumps(job_info), mimetype="application/json")
Ejemplo n.º 4
0
def post_order(request):
    """ save an order sent in post request """

    job_fields = {
        'type': 'text',
        'slug': str(time()),
        'custom_data': str(time()),
        'body_src': request.POST['body_src'],
        'tier': request.POST['tier'],
        'lc_src': request.POST['lc_src'],
        'lc_tgt': request.POST['lc_tgt'],
    }

    for bool_field in ('as_group', 'auto_approve'):
        if bool_field in request.POST:
            job_fields[bool_field] = 1
        else:
            job_fields[bool_field] = 0

    data = {'job': job_fields}
    job, job_params = get_mygengo_api('job', request)
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)

    # translate/jobs (POST)
    # Submits a job or group of jobs to translate.
    job.postJob('json', job_params)

    return HttpResponseRedirect('/')
Ejemplo n.º 5
0
def post_order(request):
    """ save an order sent in post request """
    
    job_fields = {
        'type': 'text',
        'slug': str(time()),
        'custom_data': str(time()),
        'body_src': request.POST['body_src'],
        'tier': request.POST['tier'], 
        'lc_src': request.POST['lc_src'],
        'lc_tgt': request.POST['lc_tgt'],
    }
    
    for bool_field in ('as_group','auto_approve'):
        if bool_field in request.POST:
            job_fields[bool_field] = 1
        else:
            job_fields[bool_field] = 0
    
    data = {'job':  job_fields }
    job, job_params = get_mygengo_api('job', request)      
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)

    # translate/jobs (POST)
    # Submits a job or group of jobs to translate.
    job.postJob('json', job_params)

    return HttpResponseRedirect('/')
Ejemplo n.º 6
0
def get_language_info(request):
    """ get available language info """
    service, params = get_mygengo_api('service', request)
    service.getLanguages('json', params)
    language_response = json.loads(service.getResponseBody())
    if 'response' not in language_response:
        raise ObjectDoesNotExist
    languages = language_response["response"]
    service.getLanguagePair('json', params)
    language_pairs = json.loads(service.getResponseBody())["response"]
    return languages, language_pairs
Ejemplo n.º 7
0
def get_language_info(request):
    """ get available language info """
    service, params = get_mygengo_api('service', request)
    service.getLanguages('json', params)
    language_response = json.loads(service.getResponseBody())
    if 'response' not in language_response:
        raise ObjectDoesNotExist    
    languages = language_response["response"]
    service.getLanguagePair('json', params)
    language_pairs = json.loads(service.getResponseBody())["response"] 
    return languages, language_pairs
Ejemplo n.º 8
0
def overview(request):
    """ overview of orders """

    context =  {}   
    account, account_params =  get_mygengo_api('account', request)
    account.getBalance('json', account_params)
    balance_response = json.loads(account.getResponseBody())
    if 'response' not in balance_response:
        return HttpResponse('myGengo API error. Check that your API keys are correctly set.')
    context['balance'] = balance_response['response']
    account.getStats('json', account_params)
    context['stats'] = json.loads(account.getResponseBody())['response']
    jobs, jobs_params =  get_mygengo_api('jobs', request)  
    jobs.getJobs('json', jobs_params)   
    jobs_items = {'available':[],'reviewable':[], 'approved': [], 'revising': []}
    joblist = json.loads(jobs.getResponseBody())['response'] 
    for job in joblist:
        job['date'] = datetime.datetime.fromtimestamp(job['ctime']).strftime("%b %d %Y")
    context['jobs'] = joblist
    return render_to_response('overview.html', RequestContext(request, context))
Ejemplo n.º 9
0
def post_comment(request, job_id):
    """ post comment """
    data = {'body': request.REQUEST['comment']}
    job, job_params = get_mygengo_api('job', request)      
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)    
    job.postComment(job_id, 'json', job_params)    
    return HttpResponse(job.getResponseBody())
Ejemplo n.º 10
0
def post_comment(request, job_id):
    """ post comment """
    data = {'body': request.REQUEST['comment']}
    job, job_params = get_mygengo_api('job', request)
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)
    job.postComment(job_id, 'json', job_params)
    return HttpResponse(job.getResponseBody())
Ejemplo n.º 11
0
def post_purchase(request, job_id):
    """ purchase a translation for a job """

    data = {'action': 'purchase'}
    job, job_params = get_mygengo_api('job', request)
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)
    job.putPurchase(job_id, 'json', job_params)
    return HttpResponse(job.getResponseBody() + str(job_params))
Ejemplo n.º 12
0
def post_purchase(request, job_id):
    """ purchase a translation for a job """
    
    data = { 'action': 'purchase' } 
    job, job_params = get_mygengo_api('job', request)      
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)    
    job.putPurchase(job_id, 'json', job_params)
    return HttpResponse(job.getResponseBody() + str(job_params))      
Ejemplo n.º 13
0
def get_job(job_id, request):
    """ get job and comments given a job id """
    # TODO: cache 
    job, job_params =  get_mygengo_api('job', request)
    job_params["pre_mt"] = 0
    job.getJob(job_id, 'json', job_params)
    job_obj = json.loads(job.getResponseBody())['response']
    job_obj['job']['date'] = datetime.datetime.fromtimestamp(job_obj['job']['ctime']).strftime("%b %d %Y")
    # get comments
    job.getComments(job_id, 'json', job_params)
    job_obj['comments'] = json.loads(job.getResponseBody())['response'].get('thread',[])
    for comment in job_obj['comments']:
        comment['date'] = datetime.datetime.fromtimestamp(comment['ctime']).strftime("%I:%M%p, %b %d %Y")    
    languages, language_pairs = get_language_info(request)
    for lang_type in ('src','tgt'):
        for l in languages:
            if l['lc'] == job_obj['job']['lc_' + lang_type]:
                job_obj['job']['language_' + lang_type] = l['language']
    return job_obj
Ejemplo n.º 14
0
def post_reject(request, job_id):
    """ reject translation """

    data = {
        'action': 'reject',
        'reason': request.REQUEST['reason'],
        'comment': request.REQUEST['comment'],
        'captcha': request.REQUEST['captcha'],
        'follow_up': request.REQUEST['follow_up'],
    }

    job, job_params = get_mygengo_api('job', request)
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)
    job.putReject(job_id, 'json', job_params)
    return HttpResponse(job.getResponseBody() + str(job_params))
Ejemplo n.º 15
0
def get_job(job_id, request):
    """ get job and comments given a job id """
    # TODO: cache
    job, job_params = get_mygengo_api('job', request)
    job_params["pre_mt"] = 0
    job.getJob(job_id, 'json', job_params)
    job_obj = json.loads(job.getResponseBody())['response']
    job_obj['job']['date'] = datetime.datetime.fromtimestamp(
        job_obj['job']['ctime']).strftime("%b %d %Y")
    # get comments
    job.getComments(job_id, 'json', job_params)
    job_obj['comments'] = json.loads(job.getResponseBody())['response'].get(
        'thread', [])
    for comment in job_obj['comments']:
        comment['date'] = datetime.datetime.fromtimestamp(
            comment['ctime']).strftime("%I:%M%p, %b %d %Y")
    languages, language_pairs = get_language_info(request)
    for lang_type in ('src', 'tgt'):
        for l in languages:
            if l['lc'] == job_obj['job']['lc_' + lang_type]:
                job_obj['job']['language_' + lang_type] = l['language']
    return job_obj
Ejemplo n.º 16
0
def post_reject(request, job_id):
    """ reject translation """
    
    data = { 
        'action': 'reject',
        'reason': request.REQUEST['reason'],
        'comment': request.REQUEST['comment'],
        'captcha': request.REQUEST['captcha'],
        'follow_up': request.REQUEST['follow_up'],
       } 
       
    job, job_params = get_mygengo_api('job', request)      
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)    
    job.putReject(job_id, 'json', job_params)
    return HttpResponse(job.getResponseBody() + str(job_params))    
Ejemplo n.º 17
0
def post_approve(request, job_id):
    """ post approval """

    data = {
        'action': 'approve',
        'rating': int(request.REQUEST['rating']),
        'public': int(request.REQUEST['public'])
    }
    for arg in ('for_translator', 'for_mygengo'):
        if request.REQUEST.get(arg):
            data[arg] = request.REQUEST[arg]

    job, job_params = get_mygengo_api('job', request)
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)
    job.putApprove(job_id, 'json', job_params)
    return HttpResponse(job.getResponseBody() + str(job_params))
Ejemplo n.º 18
0
def post_approve(request, job_id):
    """ post approval """
    
    data = { 
            'action': 'approve',
            'rating': int(request.REQUEST['rating']),
            'public': int(request.REQUEST['public']) 
         }
    for arg in ('for_translator','for_mygengo'):
        if request.REQUEST.get(arg):
            data[arg] = request.REQUEST[arg]
    
    job, job_params = get_mygengo_api('job', request)      
    job_params = {
        'api_key': job_params['api_key'],
        '_method': 'post',
        'ts': str(int(time())),
        'data': json.dumps(data, separators=(',', ':'))
    }
    query_json = json.dumps(job_params, separators=(',', ':'), sort_keys=True)
    job_params = get_api_sig(job_params, job, query_json)    
    job.putApprove(job_id, 'json', job_params)
    return HttpResponse(job.getResponseBody() + str(job_params))
Ejemplo n.º 19
0
def preview(request, job_id):
    """ get JPEG image for job """
    job, job_params =  get_mygengo_api('job', request)    
    job.previewJob(job_id, 'json', job_params)
    return HttpResponse(job.response.fp.read(), mimetype="image/jpeg")
Ejemplo n.º 20
0
def preview(request, job_id):
    """ get JPEG image for job """
    job, job_params = get_mygengo_api('job', request)
    job.previewJob(job_id, 'json', job_params)
    return HttpResponse(job.response.fp.read(), mimetype="image/jpeg")