def editor(request, model, language, objects): registry = utils.get_registry() fields = registry[model] default_lang = utils.get_default_language() model_name = u'%s' % model._meta.verbose_name first_unedited_translation = None object_list = [] for object in objects: context_object = get_context_object(model, fields, language, default_lang, object) object_list.append(context_object) if first_unedited_translation is None: for field in context_object['fields']: tr = field['translation'] if not tr.edited: first_unedited_translation = tr break main_page_url = reverse('datatrans_model_list') context = { 'model': model_name, 'objects': object_list, 'original_language': default_lang, 'other_language': language, 'progress': _get_model_stats(model, lambda x: x.filter(language=language)), 'first_unedited': first_unedited_translation, 'translation_main_page_url': main_page_url } return render_to_response('datatrans/model_detail.html', context, context_instance=RequestContext(request))
def _get_model_stats(model, filter=lambda x: x): default_lang = utils.get_default_language() registry = utils.get_registry() keyvalues = filter( KeyValue.objects.for_model(model, registry[model].values()).exclude( language=default_lang).exclude(value="")) total = keyvalues.count() done = keyvalues.filter(edited=True, fuzzy=False).count() return (round(done * 100 / total if total > 0 else 0, 2), done, total)
def selector(request, model, language, objects): fields = utils.get_registry()[model] for object in objects: if needs_translation(model, fields, language, object): object.todo = True context = {'model': model.__name__, 'objects': objects} return render_to_response('datatrans/object_list.html', context, context_instance=RequestContext(request))
def _get_model_entry(slug): app_label, model_slug = slug.split('.') try: ct = ContentType.objects.get(app_label=app_label, model=model_slug) except ContentType.DoesNotExist: raise Http404(u'Content type not found.') model_class = ct.model_class() registry = utils.get_registry() if not model_class in registry: raise Http404(u'No registered model found for given query.') return model_class
def model_list(request): """ Shows an overview of models to translate, along with the fields, languages and progress information. The context structure is defined as follows: context = {'models': [{'languages': [('nl', 'NL', (<percent_done>, <todo>, <total>)), ('fr', 'FR', (<percent_done>, <todo>, <total>))], 'field_names': [u'description'], 'stats': (75, 15, 20), 'slug': u'flags_app.flag', 'model_name': u'flag'}]} """ registry = utils.get_registry() default_lang = utils.get_default_language() languages = [ l for l in settings.DATATRANS3_LANGUAGES if l[0] != default_lang ] models = [{ 'slug': _get_model_slug(model), 'model_name': u'%s' % model._meta.verbose_name, 'field_names': [u'%s' % f.verbose_name for f in registry[model].values()], 'stats': _get_model_stats(model), 'words': count_model_words(model), 'languages': [( l[0], l[1], _get_model_stats(model, filter=lambda x: x.filter(language=l[0])), ) for l in languages], } for model in registry] total_words = sum(m['words'] for m in models) context = {'models': models, 'words': total_words} return render_to_response('datatrans/model_list.html', context)