def get_state_flags(unit, detail=False): """Return state flags.""" return { "state": " ".join(get_state_css(unit)), "unit": unit, "detail": detail, }
def save_zen(request, project, component, lang): """Save handler for zen mode.""" _obj, _project, unit_set = parse_params(request, project, component, lang) checksum_form = ChecksumForm(unit_set, request.POST) if not checksum_form.is_valid(): show_form_errors(request, checksum_form) return HttpResponseBadRequest("Invalid checksum") unit = checksum_form.cleaned_data["unit"] translationsum = "" form = TranslationForm(request.user, unit, request.POST) if not form.is_valid(): show_form_errors(request, form) elif not request.user.has_perm("unit.edit", unit): messages.error(request, _("Insufficient privileges for saving translations.")) else: perform_translation(unit, form, request) translationsum = hash_to_checksum(unit.get_target_hash()) response = { "messages": [], "state": "success", "translationsum": translationsum, "unit_flags": get_state_css(unit) if unit is not None else [], } storage = get_messages(request) if storage: response["messages"] = [{ "tags": m.tags, "kind": get_message_kind(m.tags), "text": m.message } for m in storage] tags = {m.tags for m in storage} if "error" in tags: response["state"] = "danger" elif "warning" in tags: response["state"] = "warning" elif "info" in tags: response["state"] = "info" return JsonResponse(data=response)
def save_zen(request, project, component, lang): """Save handler for zen mode.""" translation = get_translation(request, project, component, lang) form = TranslationForm(request.user, translation, None, request.POST) unit = None translationsum = '' if not form.is_valid(): show_form_errors(request, form) elif not request.user.has_perm('unit.edit', form.cleaned_data['unit']): messages.error(request, _('Insufficient privileges for saving translations.')) else: unit = form.cleaned_data['unit'] perform_translation(unit, form, request) translationsum = hash_to_checksum(unit.get_target_hash()) response = { 'messages': [], 'state': 'success', 'translationsum': translationsum, 'unit_flags': get_state_css(unit) if unit is not None else [], } storage = get_messages(request) if storage: response['messages'] = [{ 'tags': m.tags, 'text': m.message } for m in storage] tags = {m.tags for m in storage} if 'error' in tags: response['state'] = 'danger' elif 'warning' in tags: response['state'] = 'warning' elif 'info' in tags: response['state'] = 'info' return JsonResponse(data=response)
def get_state_flags(unit): """Return state flags.""" return {'state': ' '.join(get_state_css(unit))}
def get_state_flags(unit): """Return state flags.""" return {"state": " ".join(get_state_css(unit))}