Exemple #1
0
def add_user(request, project):
    obj = get_project(request, project)

    form = AddUserForm(request.POST)

    if not obj.enable_acl:
        messages.error(request, _('ACL not enabled for this project!'))
    elif form.is_valid():
        try:
            user = User.objects.get(
                Q(username=form.cleaned_data['name'])
                | Q(email=form.cleaned_data['name']))
            obj.add_user(user)
            messages.success(request,
                             _('User has been added to this project.'))
        except User.DoesNotExist:
            messages.error(request, _('No matching user found!'))
        except User.MultipleObjectsReturned:
            messages.error(request, _('More users matched!'))
    else:
        messages.error(request, _('Invalid user specified!'))

    return redirect_param(
        'project',
        '#acl',
        project=obj.slug,
    )
Exemple #2
0
def add_user(request, project):
    obj = get_project(request, project)

    form = AddUserForm(request.POST)

    if not obj.enable_acl:
        messages.error(request, _('ACL not enabled for this project!'))
    elif form.is_valid():
        try:
            user = User.objects.get(
                Q(username=form.cleaned_data['name']) |
                Q(email=form.cleaned_data['name'])
            )
            obj.add_user(user)
            messages.success(
                request, _('User has been added to this project.')
            )
        except User.DoesNotExist:
            messages.error(request, _('No matching user found!'))
        except User.MultipleObjectsReturned:
            messages.error(request, _('More users matched!'))
    else:
        messages.error(request, _('Invalid user specified!'))

    return redirect_param(
        'project',
        '#acl',
        project=obj.slug,
    )
Exemple #3
0
def delete_user(request, project):
    obj = get_project(request, project)

    form = AddUserForm(request.POST)

    if form.is_valid():
        try:
            user = User.objects.get(
                username=form.cleaned_data['name']
            )
            obj.remove_user(user)
            messages.success(
                request, _('User has been removed from this project.')
            )
        except User.DoesNotExist:
            messages.error(request, _('No matching user found!'))
        except User.MultipleObjectsReturned:
            messages.error(request, _('More users matched!'))
    else:
        messages.error(request, _('Invalid user specified!'))

    return redirect_param(
        'project',
        '#acl',
        project=obj.slug,
    )
Exemple #4
0
def delete_user(request, project):
    obj = get_project(request, project)

    form = AddUserForm(request.POST)

    if form.is_valid():
        try:
            user = User.objects.get(username=form.cleaned_data['name'])
            obj.remove_user(user)
            messages.success(request,
                             _('User has been removed from this project.'))
        except User.DoesNotExist:
            messages.error(request, _('No matching user found!'))
        except User.MultipleObjectsReturned:
            messages.error(request, _('More users matched!'))
    else:
        messages.error(request, _('Invalid user specified!'))

    return redirect_param(
        'project',
        '#acl',
        project=obj.slug,
    )
Exemple #5
0
def show_project(request, project):
    obj = get_project(request, project)

    dict_langs = Dictionary.objects.filter(
        project=obj
    ).values_list(
        'language', flat=True
    ).distinct()

    dicts = []
    for language in Language.objects.filter(id__in=dict_langs):
        dicts.append(
            {
                'language': language,
                'count': Dictionary.objects.filter(
                    language=language,
                    project=obj
                ).count(),
            }
        )

    last_changes = Change.objects.prefetch().filter(
        Q(translation__subproject__project=obj) |
        Q(dictionary__project=obj)
    )[:10]

    return render(
        request,
        'project.html',
        {
            'object': obj,
            'project': obj,
            'dicts': dicts,
            'last_changes': last_changes,
            'last_changes_rss': reverse(
                'rss-project',
                kwargs={'project': obj.slug}
            ),
            'last_changes_url': urlencode(
                {'project': obj.slug}
            ),
            'add_user_form': AddUserForm(),
        }
    )