Example #1
0
def get_counts(request, project, subproject):
    """View for work counts"""
    obj = get_subproject(request, project, subproject)

    if not can_view_reports(request.user, obj.project):
        raise PermissionDenied()

    form = ReportsForm(request.POST)

    if not form.is_valid():
        return redirect(obj)

    data = generate_counts(
        obj,
        form.cleaned_data['start_date'],
        form.cleaned_data['end_date'],
    )

    if form.cleaned_data['style'] == 'json':
        return HttpResponse(json.dumps(data), content_type='application/json')

    if form.cleaned_data['style'] == 'html':
        start = ('<table>\n<tr><th>Email</th><th>Name</th>'
                 '<th>Words</th><th>Count</th></tr>')
        row_start = '<tr>'
        cell_format = u'<td>{0}</td>\n'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        heading = ' '.join(['=' * 25] * 4)
        start = '{0}\n{1:25} {2:25} {3:25} {4:25}\n{0}'.format(
            heading, 'Email', 'Name', 'Words', 'Count')
        row_start = ''
        cell_format = u'{0:25} '
        row_end = ''
        mime = 'text/plain'
        end = heading

    result = []

    result.append(start)

    for item in data:
        result.append(row_start)
        result.append(u'{0}{1}{2}{3}'.format(
            cell_format.format(item['name']),
            cell_format.format(item['email']),
            cell_format.format(item['words']),
            cell_format.format(item['count']),
        ))
        result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #2
0
def get_credits(request, project, subproject):
    """View for credits"""
    obj = get_subproject(request, project, subproject)

    if not can_view_reports(request.user, obj.project):
        raise PermissionDenied()

    form = ReportsForm(request.POST)

    if not form.is_valid():
        return redirect(obj)

    data = generate_credits(
        obj,
        form.cleaned_data['start_date'],
        form.cleaned_data['end_date'],
    )

    if form.cleaned_data['style'] == 'json':
        return JsonResponse(data=data, safe=False)

    if form.cleaned_data['style'] == 'html':
        start = '<table>'
        row_start = '<tr>'
        language_format = '<th>{0}</th>'
        translator_start = '<td><ul>'
        translator_format = '<li><a href="mailto:{0}">{1}</a></li>'
        translator_end = '</ul></td>'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        start = ''
        row_start = ''
        language_format = '* {0}\n'
        translator_start = ''
        translator_format = '    * {1} <{0}>'
        translator_end = ''
        row_end = ''
        mime = 'text/plain'
        end = ''

    result = []

    result.append(start)

    for language in data:
        name, translators = language.popitem()
        result.append(row_start)
        result.append(language_format.format(name))
        result.append(''.join((
            translator_start,
            '\n'.join([translator_format.format(*t) for t in translators]),
            translator_end,
        )))
        result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #3
0
def get_credits(request, project=None, component=None):
    """View for credits."""
    if project is None:
        obj = None
        kwargs = {"translation__pk__gt": 0}
    elif component is None:
        obj = get_project(request, project)
        kwargs = {"translation__component__project": obj}
    else:
        obj = get_component(request, project, component)
        kwargs = {"translation__component": obj}

    form = ReportsForm(request.POST)

    if not form.is_valid():
        show_form_errors(request, form)
        return redirect_param(obj or "home", "#reports")

    data = generate_credits(
        None if request.user.has_perm("reports.view", obj) else request.user,
        form.cleaned_data["start_date"], form.cleaned_data["end_date"],
        **kwargs)

    if form.cleaned_data["style"] == "json":
        return JsonResponse(data=data, safe=False)

    if form.cleaned_data["style"] == "html":
        start = "<table>"
        row_start = "<tr>"
        language_format = "<th>{0}</th>"
        translator_start = "<td><ul>"
        translator_format = '<li><a href="mailto:{0}">{1}</a></li>'
        translator_end = "</ul></td>"
        row_end = "</tr>"
        mime = "text/html"
        end = "</table>"
    else:
        start = ""
        row_start = ""
        language_format = "* {0}\n"
        translator_start = ""
        translator_format = "    * {1} <{0}>"
        translator_end = ""
        row_end = ""
        mime = "text/plain"
        end = ""

    result = []

    result.append(start)

    for language in data:
        name, translators = language.popitem()
        result.append(row_start)
        result.append(language_format.format(name))
        result.append(translator_start + "\n".join(
            translator_format.format(*t)
            for t in translators) + translator_end)
        result.append(row_end)

    result.append(end)

    return HttpResponse("\n".join(result),
                        content_type="{0}; charset=utf-8".format(mime))
Example #4
0
def get_counts(request, project=None, component=None):
    """View for work counts."""
    if project is None:
        obj = None
        kwargs = {}
    elif component is None:
        obj = get_project(request, project)
        kwargs = {"project": obj}
    else:
        obj = get_component(request, project, component)
        kwargs = {"component": obj}

    form = ReportsForm(request.POST)

    if not form.is_valid():
        show_form_errors(request, form)
        return redirect_param(obj or "home", "#reports")

    data = generate_counts(
        None if request.user.has_perm("reports.view", obj) else request.user,
        form.cleaned_data["start_date"], form.cleaned_data["end_date"],
        **kwargs)

    if form.cleaned_data["style"] == "json":
        return JsonResponse(data=data, safe=False)

    headers = (
        "Name",
        "Email",
        "Count total",
        "Source words total",
        "Source chars total",
        "Target words total",
        "Target chars total",
        "Count new",
        "Source words new",
        "Source chars new",
        "Target words new",
        "Target chars new",
        "Count approved",
        "Source words approved",
        "Source chars approved",
        "Target words approved",
        "Target chars approved",
        "Count edited",
        "Source words edited",
        "Source chars edited",
        "Target words edited",
        "Target chars edited",
    )

    if form.cleaned_data["style"] == "html":
        start = HTML_HEADING.format("".join("<th>{0}</th>".format(h)
                                            for h in headers))
        row_start = "<tr>"
        cell_name = cell_count = "<td>{0}</td>\n"
        row_end = "</tr>"
        mime = "text/html"
        end = "</table>"
    else:
        start = "{0}\n{1} {2}\n{0}".format(
            RST_HEADING,
            " ".join("{0:40}".format(h) for h in headers[:2]),
            " ".join("{0:24}".format(h) for h in headers[2:]),
        )
        row_start = ""
        cell_name = "{0:40} "
        cell_count = "{0:24} "
        row_end = ""
        mime = "text/plain"
        end = RST_HEADING

    result = []

    result.append(start)

    for item in data:
        if row_start:
            result.append(row_start)
        result.append(
            cell_name.format(item["name"] or "Anonymous") +
            cell_name.format(item["email"] or "") +
            cell_count.format(item["count"]) +
            cell_count.format(item["words"]) +
            cell_count.format(item["chars"]) +
            cell_count.format(item["t_words"]) +
            cell_count.format(item["t_chars"]) +
            cell_count.format(item["count_new"]) +
            cell_count.format(item["words_new"]) +
            cell_count.format(item["chars_new"]) +
            cell_count.format(item["t_words_new"]) +
            cell_count.format(item["t_chars_new"]) +
            cell_count.format(item["count_approve"]) +
            cell_count.format(item["words_approve"]) +
            cell_count.format(item["chars_approve"]) +
            cell_count.format(item["t_words_approve"]) +
            cell_count.format(item["t_chars_approve"]) +
            cell_count.format(item["count_edit"]) +
            cell_count.format(item["words_edit"]) +
            cell_count.format(item["chars_edit"]) +
            cell_count.format(item["t_words_edit"]) +
            cell_count.format(item["t_chars_edit"]))
        if row_end:
            result.append(row_end)

    result.append(end)

    return HttpResponse("\n".join(result),
                        content_type="{0}; charset=utf-8".format(mime))
Example #5
0
def get_credits(request, project, component):
    """View for credits"""
    obj = get_component(request, project, component)

    if not request.user.has_perm('reports.view', obj):
        raise PermissionDenied()

    form = ReportsForm(request.POST)

    if not form.is_valid():
        show_form_errors(request, form)
        return redirect_param(obj, '#reports')

    data = generate_credits(
        obj,
        form.cleaned_data['start_date'],
        form.cleaned_data['end_date'],
    )

    if form.cleaned_data['style'] == 'json':
        return JsonResponse(data=data, safe=False)

    if form.cleaned_data['style'] == 'html':
        start = '<table>'
        row_start = '<tr>'
        language_format = '<th>{0}</th>'
        translator_start = '<td><ul>'
        translator_format = '<li><a href="mailto:{0}">{1}</a></li>'
        translator_end = '</ul></td>'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        start = ''
        row_start = ''
        language_format = '* {0}\n'
        translator_start = ''
        translator_format = '    * {1} <{0}>'
        translator_end = ''
        row_end = ''
        mime = 'text/plain'
        end = ''

    result = []

    result.append(start)

    for language in data:
        name, translators = language.popitem()
        result.append(row_start)
        result.append(language_format.format(name))
        result.append(
            ''.join((
                translator_start,
                '\n'.join(
                    [translator_format.format(*t) for t in translators]
                ),
                translator_end,
            ))
        )
        result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #6
0
def get_counts(request, project, component):
    """View for work counts"""
    obj = get_component(request, project, component)

    if not request.user.has_perm('reports.view', obj):
        raise PermissionDenied()

    form = ReportsForm(request.POST)

    if not form.is_valid():
        show_form_errors(request, form)
        return redirect_param(obj, '#reports')

    data = generate_counts(
        obj,
        form.cleaned_data['start_date'],
        form.cleaned_data['end_date'],
    )

    if form.cleaned_data['style'] == 'json':
        return JsonResponse(data=data, safe=False)

    headers = (
        'Name',
        'Email',
        'Words total',
        'Count total',
        'Words edited',
        'Count edited',
        'Words new',
        'Count new',
    )

    if form.cleaned_data['style'] == 'html':
        start = HTML_HEADING.format(
            ''.join(['<th>{0}</th>'.format(h) for h in headers])
        )
        row_start = '<tr>'
        cell_name = cell_count = '<td>{0}</td>\n'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        start = '{0}\n{1} {2}\n{0}'.format(
            RST_HEADING,
            ' '.join(['{0:40}'.format(h) for h in headers[:2]]),
            ' '.join(['{0:12}'.format(h) for h in headers[2:]]),
        )
        row_start = ''
        cell_name = '{0:40} '
        cell_count = '{0:12} '
        row_end = ''
        mime = 'text/plain'
        end = RST_HEADING

    result = []

    result.append(start)

    for item in data:
        if row_start:
            result.append(row_start)
        result.append(
            ''.join((
                cell_name.format(item['name']),
                cell_name.format(item['email']),
                cell_count.format(item['words']),
                cell_count.format(item['count']),
                cell_count.format(item['words_new']),
                cell_count.format(item['count_new']),
                cell_count.format(item['words_edit']),
                cell_count.format(item['count_edit']),
            ))
        )
        if row_end:
            result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #7
0
def get_credits(request, project=None, component=None):
    """View for credits"""
    if project is None:
        obj = None
        kwargs = {'translation__pk__gt': 0}
    elif component is None:
        obj = get_project(request, project)
        kwargs = {'translation__component__project': obj}
    else:
        obj = get_component(request, project, component)
        kwargs = {'translation__component': obj}

    form = ReportsForm(request.POST)

    if not form.is_valid():
        show_form_errors(request, form)
        return redirect_param(obj or 'home', '#reports')

    data = generate_credits(
        None if request.user.has_perm('reports.view', obj) else request.user,
        form.cleaned_data['start_date'], form.cleaned_data['end_date'],
        **kwargs)

    if form.cleaned_data['style'] == 'json':
        return JsonResponse(data=data, safe=False)

    if form.cleaned_data['style'] == 'html':
        start = '<table>'
        row_start = '<tr>'
        language_format = '<th>{0}</th>'
        translator_start = '<td><ul>'
        translator_format = '<li><a href="mailto:{0}">{1}</a></li>'
        translator_end = '</ul></td>'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        start = ''
        row_start = ''
        language_format = '* {0}\n'
        translator_start = ''
        translator_format = '    * {1} <{0}>'
        translator_end = ''
        row_end = ''
        mime = 'text/plain'
        end = ''

    result = []

    result.append(start)

    for language in data:
        name, translators = language.popitem()
        result.append(row_start)
        result.append(language_format.format(name))
        result.append(''.join((
            translator_start,
            '\n'.join([translator_format.format(*t) for t in translators]),
            translator_end,
        )))
        result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #8
0
def get_counts(request, project=None, component=None):
    """View for work counts"""
    if project is None:
        obj = None
        kwargs = {}
    elif component is None:
        obj = get_project(request, project)
        kwargs = {'project': obj}
    else:
        obj = get_component(request, project, component)
        kwargs = {'component': obj}

    form = ReportsForm(request.POST)

    if not form.is_valid():
        show_form_errors(request, form)
        return redirect_param(obj or 'home', '#reports')

    data = generate_counts(
        None if request.user.has_perm('reports.view', obj) else request.user,
        form.cleaned_data['start_date'], form.cleaned_data['end_date'],
        **kwargs)

    if form.cleaned_data['style'] == 'json':
        return JsonResponse(data=data, safe=False)

    headers = (
        'Name',
        'Email',
        'Count total',
        'Source words total',
        'Source chars total',
        'Target words total',
        'Target chars total',
        'Count new',
        'Source words new',
        'Source chars new',
        'Target words new',
        'Target chars new',
        'Count approved',
        'Source words approved',
        'Source chars approved',
        'Target words approved',
        'Target chars approved',
        'Count edited',
        'Source words edited',
        'Source chars edited',
        'Target words edited',
        'Target chars edited',
    )

    if form.cleaned_data['style'] == 'html':
        start = HTML_HEADING.format(''.join(
            ['<th>{0}</th>'.format(h) for h in headers]))
        row_start = '<tr>'
        cell_name = cell_count = '<td>{0}</td>\n'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        start = '{0}\n{1} {2}\n{0}'.format(
            RST_HEADING,
            ' '.join(['{0:40}'.format(h) for h in headers[:2]]),
            ' '.join(['{0:24}'.format(h) for h in headers[2:]]),
        )
        row_start = ''
        cell_name = '{0:40} '
        cell_count = '{0:24} '
        row_end = ''
        mime = 'text/plain'
        end = RST_HEADING

    result = []

    result.append(start)

    for item in data:
        if row_start:
            result.append(row_start)
        result.append(''.join((
            cell_name.format(item['name']),
            cell_name.format(item['email']),
            cell_count.format(item['count']),
            cell_count.format(item['words']),
            cell_count.format(item['chars']),
            cell_count.format(item['t_words']),
            cell_count.format(item['t_chars']),
            cell_count.format(item['count_new']),
            cell_count.format(item['words_new']),
            cell_count.format(item['chars_new']),
            cell_count.format(item['t_words_new']),
            cell_count.format(item['t_chars_new']),
            cell_count.format(item['count_approve']),
            cell_count.format(item['words_approve']),
            cell_count.format(item['chars_approve']),
            cell_count.format(item['t_words_approve']),
            cell_count.format(item['t_chars_approve']),
            cell_count.format(item['count_edit']),
            cell_count.format(item['words_edit']),
            cell_count.format(item['chars_edit']),
            cell_count.format(item['t_words_edit']),
            cell_count.format(item['t_chars_edit']),
        )))
        if row_end:
            result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #9
0
def get_counts(request, project, component):
    """View for work counts"""
    obj = get_component(request, project, component)

    if not request.user.has_perm('reports.view', obj):
        raise PermissionDenied()

    form = ReportsForm(request.POST)

    if not form.is_valid():
        show_form_errors(request, form)
        return redirect_param(obj, '#reports')

    data = generate_counts(
        obj,
        form.cleaned_data['start_date'],
        form.cleaned_data['end_date'],
    )

    if form.cleaned_data['style'] == 'json':
        return JsonResponse(data=data, safe=False)

    headers = (
        'Name',
        'Email',
        'Words total',
        'Count total',
        'Words edited',
        'Count edited',
        'Words new',
        'Count new',
    )

    if form.cleaned_data['style'] == 'html':
        start = HTML_HEADING.format(''.join(
            ['<th>{0}</th>'.format(h) for h in headers]))
        row_start = '<tr>'
        cell_name = cell_count = '<td>{0}</td>\n'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        start = '{0}\n{1} {2}\n{0}'.format(
            RST_HEADING,
            ' '.join(['{0:40}'.format(h) for h in headers[:2]]),
            ' '.join(['{0:12}'.format(h) for h in headers[2:]]),
        )
        row_start = ''
        cell_name = '{0:40} '
        cell_count = '{0:12} '
        row_end = ''
        mime = 'text/plain'
        end = RST_HEADING

    result = []

    result.append(start)

    for item in data:
        if row_start:
            result.append(row_start)
        result.append(''.join((
            cell_name.format(item['name']),
            cell_name.format(item['email']),
            cell_count.format(item['words']),
            cell_count.format(item['count']),
            cell_count.format(item['words_new']),
            cell_count.format(item['count_new']),
            cell_count.format(item['words_edit']),
            cell_count.format(item['count_edit']),
        )))
        if row_end:
            result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #10
0
def get_credits(request, project, subproject):
    """View for credits"""
    obj = get_subproject(request, project, subproject)

    if not can_view_reports(request.user, obj.project):
        raise PermissionDenied()

    form = ReportsForm(request.POST)

    if not form.is_valid():
        return redirect(obj)

    data = generate_credits(
        obj,
        form.cleaned_data['start_date'],
        form.cleaned_data['end_date'],
    )

    if form.cleaned_data['style'] == 'json':
        return HttpResponse(
            json.dumps(data),
            content_type='application/json'
        )

    if form.cleaned_data['style'] == 'html':
        start = '<table>'
        row_start = '<tr>'
        language_format = u'<th>{0}</th>'
        translator_start = '<td><ul>'
        translator_format = u'<li><a href="mailto:{0}">{1}</a></li>'
        translator_end = '</ul></td>'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        start = ''
        row_start = ''
        language_format = u'* {0}\n'
        translator_start = ''
        translator_format = u'    * {1} <{0}>'
        translator_end = ''
        row_end = ''
        mime = 'text/plain'
        end = ''

    result = []

    result.append(start)

    for language in data:
        name, translators = language.items()[0]
        result.append(row_start)
        result.append(language_format.format(name))
        result.append(
            u'{0}{1}{2}'.format(
                translator_start,
                '\n'.join(
                    [translator_format.format(*t) for t in translators]
                ),
                translator_end,
            )
        )
        result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )
Example #11
0
def get_counts(request, project, subproject):
    """View for work counts"""
    obj = get_subproject(request, project, subproject)

    if not can_view_reports(request.user, obj.project):
        raise PermissionDenied()

    form = ReportsForm(request.POST)

    if not form.is_valid():
        return redirect(obj)

    data = generate_counts(
        obj,
        form.cleaned_data['start_date'],
        form.cleaned_data['end_date'],
    )

    if form.cleaned_data['style'] == 'json':
        return HttpResponse(
            json.dumps(data),
            content_type='application/json'
        )

    if form.cleaned_data['style'] == 'html':
        start = (
            '<table>\n<tr><th>Email</th><th>Name</th>'
            '<th>Words</th><th>Count</th></tr>'
        )
        row_start = '<tr>'
        cell_format = u'<td>{0}</td>\n'
        row_end = '</tr>'
        mime = 'text/html'
        end = '</table>'
    else:
        heading = ' '.join(['=' * 25] * 4)
        start = '{0}\n{1:25} {2:25} {3:25} {4:25}\n{0}'.format(
            heading,
            'Email',
            'Name',
            'Words',
            'Count'
        )
        row_start = ''
        cell_format = u'{0:25} '
        row_end = ''
        mime = 'text/plain'
        end = heading

    result = []

    result.append(start)

    for item in data:
        result.append(row_start)
        result.append(
            u'{0}{1}{2}{3}'.format(
                cell_format.format(item['name']),
                cell_format.format(item['email']),
                cell_format.format(item['words']),
                cell_format.format(item['count']),
            )
        )
        result.append(row_end)

    result.append(end)

    return HttpResponse(
        '\n'.join(result),
        content_type='{0}; charset=utf-8'.format(mime),
    )