Esempio n. 1
0
File: utils.py Progetto: stasm/elmo
def update_svn_all(project):
    source = _read_webpage(project.l10n_repo_url)
    locales = _extract_locales_from_svn(source)
    cur_locales = project.locales.values_list('code', flat=True)
    shared = intersect(locales, cur_locales)

    unavailable_locales = []
    for locale in locales:
        if locale not in shared:
            """
            A locale is in verbatim but not in project locales
            """
            try:
                lobj = Locale.objects.get(code=locale)
            except Locale.DoesNotExist:
                unavailable_locales.append(locale)
            else:
                wlobj = Weblocale(locale=lobj, project=project, in_vcs=True)
                wlobj.save()
        else:
            """
            A locale is both in verbatim and project locales
            """
            wlobj = Weblocale.objects.get(locale__code=locale, project=project)
            wlobj.in_vcs = True
            wlobj.save()
    for locale in cur_locales:
        if locale not in shared:
            """
            A locale is in project locales but is not in verbatim
            """
            wlobj = Weblocale.objects.get(locale__code=locale, project=project)
            wlobj.in_vcs = False
            wlobj.save()
Esempio n. 2
0
def update_svn_all(project):
    source = _read_webpage(project.l10n_repo_url)
    locales = _extract_locales_from_svn(source)
    cur_locales = project.locales.values_list("code", flat=True)
    shared = intersect(locales, cur_locales)

    unavailable_locales = []
    for locale in locales:
        if locale not in shared:
            """
            A locale is in verbatim but not in project locales
            """
            try:
                lobj = Locale.objects.get(code=locale)
            except Locale.DoesNotExist:
                unavailable_locales.append(locale)
            else:
                wlobj = Weblocale(locale=lobj, project=project, in_vcs=True)
                wlobj.save()
        else:
            """
            A locale is both in verbatim and project locales
            """
            wlobj = Weblocale.objects.get(locale__code=locale, project=project)
            wlobj.in_vcs = True
            wlobj.save()
    for locale in cur_locales:
        if locale not in shared:
            """
            A locale is in project locales but is not in verbatim
            """
            wlobj = Weblocale.objects.get(locale__code=locale, project=project)
            wlobj.in_vcs = False
            wlobj.save()
Esempio n. 3
0
def project(request, slug):
    project = get_object_or_404(Project, slug=slug)
    if request.method == 'POST' and not project.is_archived:
        form = AddLocaleForm(request.POST)
        if form.is_valid() and request.user.has_perm('webby.add_weblocale'):
            lcode = form.cleaned_data['locale']
            locale = Locale.objects.get(code=lcode)
            wlobj = Weblocale(locale=locale,
                              project=project,
                              requestee=request.user)
            wlobj.save()
            LogEntry.objects.log_action(
                user_id         = request.user.pk,
                content_type_id = ContentType.objects.get_for_model(wlobj).pk,
                object_id       = wlobj.pk,
                object_repr     = unicode(wlobj),
                action_flag     = ADDITION
            )
            return HttpResponseRedirect('')
        else:
            return HttpResponseRedirect('')
    else:
        form = AddLocaleForm()

    locales = Weblocale.objects.filter(project=project) \
                               .order_by('locale__name')
    new_locales = Locale.objects \
                        .exclude(id__in=project.locales.values_list('id')) \
                        .order_by('code') if not project.is_archived else []

    return render_to_response('webby/project.html',
                              {'project': project,
                               'locales': locales,
                               'new_locales': new_locales,
                               'form': form,
                               'login_form_needs_reload': True,
                               # request needs to be passed explicitly because 
                               # django.core.context_processors.request is not 
                               # enabled by default.  See bug 556270.
                               'request': request,
                              },
                              context_instance=RequestContext(request))
Esempio n. 4
0
def project(request, slug):
    project = get_object_or_404(Project, slug=slug)
    if request.method == 'POST' and not project.is_archived:
        form = AddLocaleForm(request.POST)
        if form.is_valid() and request.user.has_perm('webby.add_weblocale'):
            lcode = form.cleaned_data['locale']
            locale = Locale.objects.get(code=lcode)
            wlobj = Weblocale(locale=locale,
                              project=project,
                              requestee=request.user)
            wlobj.save()
            LogEntry.objects.log_action(
                user_id=request.user.pk,
                content_type_id=ContentType.objects.get_for_model(wlobj).pk,
                object_id=wlobj.pk,
                object_repr=unicode(wlobj),
                action_flag=ADDITION)
            return HttpResponseRedirect('')
        else:
            return HttpResponseRedirect('')
    else:
        form = AddLocaleForm()

    locales = Weblocale.objects.filter(project=project) \
                               .order_by('locale__name')
    new_locales = Locale.objects \
                        .exclude(id__in=project.locales.values_list('id')) \
                        .order_by('code') if not project.is_archived else []

    return render(
        request, 'webby/project.html', {
            'project': project,
            'locales': locales,
            'new_locales': new_locales,
            'form': form,
            'login_form_needs_reload': True,
        })