def check_user_form(request, project): obj = get_project(request, project) if not can_manage_acl(request.user, obj): raise PermissionDenied() form = UserManageForm(request.POST) if form.is_valid(): return obj, form else: for error in form.errors: for message in form.errors[error]: messages.error(request, message) return obj, None
def check_user_form(request, project): obj = get_project(request, project) if not can_manage_acl(request.user, obj): raise PermissionDenied() form = UserManageForm(request.POST) if form.is_valid(): return obj, form else: for error in form.errors: for message in form.errors[error]: messages.error(request, message) return obj, None
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_url': urlencode({'project': obj.slug}), 'add_user_form': UserManageForm(), })
def manage_access(request, project): """User management view.""" obj = get_project(request, project) if not request.user.has_perm('project.permissions', obj): raise PermissionDenied() if request.user.has_perm('billing:project.permissions', obj): access_form = ProjectAccessForm(instance=obj) else: access_form = DisabledProjectAccessForm(instance=obj) return render( request, 'manage-access.html', { 'object': obj, 'project': obj, 'groups': Group.objects.for_project(obj), 'all_users': User.objects.for_project(obj), 'add_user_form': UserManageForm(), 'invite_user_form': InviteUserForm(), 'access_form': access_form, }, )
def manage_access(request, project): """User management view.""" obj = get_project(request, project) if not request.user.has_perm("project.permissions", obj): raise PermissionDenied() groups = obj.defined_groups.order() for group in groups: group.edit_form = SimpleGroupForm(instance=group, auto_id=f"id_group_{group.id}_%s") users = (User.objects.filter( groups__in=groups).distinct().order().prefetch_related( Prefetch( "groups", queryset=groups, to_attr="project_groups", ), )) for user in users: user.group_edit_form = ProjectUserGroupForm( obj, initial={ "user": user.username, "groups": user.project_groups }, auto_id=f"id_user_{user.id}_%s", ) return render( request, "trans/project-access.html", { "object": obj, "project": obj, "project_tokens": obj.projecttoken_set.all(), "groups": groups, "all_users": users, "blocked_users": obj.userblock_set.select_related("user"), "add_user_form": UserManageForm(), "create_project_token_form": ProjectTokenCreateForm(obj), "create_team_form": SimpleGroupForm(initial={"language_selection": SELECTION_ALL}), "block_user_form": UserBlockForm(initial={"user": request.GET.get("block_user")}), "invite_user_form": InviteUserForm(), "ssh_key": get_key_data(), }, )
def show_project(request, project): obj = get_project(request, project) dict_langs = Language.objects.filter(dictionary__project=obj).annotate( Count('dictionary')) if request.method == 'POST' and can_edit_project(request.user, obj): settings_form = ProjectSettingsForm(request.POST, instance=obj) if settings_form.is_valid(): settings_form.save() messages.success(request, _('Settings saved')) return redirect(obj) else: messages.error( request, _('Invalid settings, please check the form for errors!')) else: settings_form = ProjectSettingsForm(instance=obj) last_changes = Change.objects.for_project(obj)[:10] language_stats = sort_unicode(get_per_language_stats(obj), lambda tup: force_text(tup[0])) language_stats = [(tup[0], translation_percent(tup[1], tup[2]), translation_percent(tup[3], tup[4])) for tup in language_stats] return render( request, 'project.html', { 'object': obj, 'project': obj, 'dicts': dict_langs, 'last_changes': last_changes, 'last_changes_url': urlencode({'project': obj.slug}), 'add_user_form': UserManageForm(), 'settings_form': settings_form, 'language_stats': language_stats, 'unit_count': Unit.objects.filter(translation__subproject__project=obj).count(), 'words_count': obj.get_total_words(), 'language_count': Language.objects.filter( translation__subproject__project=obj).distinct().count(), 'strings_count': obj.get_total(), 'source_words_count': obj.get_source_words(), })
def check_user_form(request, project, verbose=False): """Check project permission and UserManageForm. This is simple helper to perform needed validation for all user management views. """ obj = get_project(request, project) if not can_manage_acl(request.user, obj): raise PermissionDenied() form = UserManageForm(request.POST) if form.is_valid(): return obj, form elif verbose: for error in form.errors: for message in form.errors[error]: messages.error(request, message) return obj, None
def check_user_form(request, project, verbose=False): """Check project permission and UserManageForm. This is simple helper to perform needed validation for all user management views. """ obj = get_project(request, project) if not can_manage_acl(request.user, obj): raise PermissionDenied() form = UserManageForm(request.POST) if form.is_valid(): return obj, form elif verbose: for error in form.errors: for message in form.errors[error]: messages.error(request, message) return obj, None
def check_user_form(request, project, verbose=False): """Check project permission and UserManageForm. This is simple helper to perform needed validation for all user management views. """ obj = get_project(request, project) if (not request.user.has_perm('project.permissions', obj) or obj.access_control == obj.ACCESS_CUSTOM): raise PermissionDenied() form = UserManageForm(request.POST) if form.is_valid(): return obj, form if verbose: for error in form.errors: for message in form.errors[error]: messages.error(request, message) return obj, None
def check_user_form(request, project, verbose=False): """Check project permission and UserManageForm. This is simple helper to perform needed validation for all user management views. """ obj = get_project(request, project) if (not request.user.has_perm('project.permissions', obj) or obj.access_control == obj.ACCESS_CUSTOM): raise PermissionDenied() form = UserManageForm(request.POST) if form.is_valid(): return obj, form elif verbose: for error in form.errors: for message in form.errors[error]: messages.error(request, message) return obj, None
def manage_access(request, project): """User management view.""" obj = get_project(request, project) if not can_manage_acl(request.user, obj): raise PermissionDenied() return render( request, 'manage-access.html', { 'object': obj, 'project': obj, 'groups': obj.all_groups(), 'add_user_form': UserManageForm(), })
def show_project(request, project): obj = get_project(request, project) dict_langs = Dictionary.objects.filter(project=obj).values_list( 'language', flat=True).distinct() if request.method == 'POST' and can_edit_project(request.user, obj): settings_form = ProjectSettingsForm(request.POST, instance=obj) if settings_form.is_valid(): settings_form.save() messages.success(request, _('Settings saved')) return redirect(obj) else: messages.error( request, _('Invalid settings, please check the form for errors!')) else: settings_form = ProjectSettingsForm(instance=obj) 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] language_stats = sort_unicode(get_per_language_stats(obj), lambda tup: force_text(tup[0])) language_stats = [(tup[0], translation_percent(tup[1], tup[2])) for tup in language_stats] return render( request, 'project.html', { 'object': obj, 'project': obj, 'dicts': dicts, 'last_changes': last_changes, 'last_changes_url': urlencode({'project': obj.slug}), 'add_user_form': UserManageForm(), 'settings_form': settings_form, 'language_stats': language_stats, })
def manage_access(request, project): """User management view.""" obj = get_project(request, project) if not request.user.has_perm('project.permissions', obj): raise PermissionDenied() return render( request, 'manage-access.html', { 'object': obj, 'project': obj, 'groups': Group.objects.for_project(obj), 'all_users': User.objects.for_project(obj), 'add_user_form': UserManageForm(), 'invite_user_form': InviteUserForm(), }, )
def manage_access(request, project): """User management view.""" obj = get_project(request, project) if not request.user.has_perm("project.permissions", obj): raise PermissionDenied() return render( request, "manage-access.html", { "object": obj, "project": obj, "groups": Group.objects.for_project(obj), "all_users": User.objects.for_project(obj), "add_user_form": UserManageForm(), "invite_user_form": InviteUserForm(), }, )
def manage_access(request, project): """User management view.""" obj = get_project(request, project) if not can_manage_acl(request.user, obj): raise PermissionDenied() if can_edit_access_control(request.user, obj): access_form = ProjectAccessForm(instance=obj) else: access_form = DisabledProjectAccessForm(instance=obj) return render( request, 'manage-access.html', { 'object': obj, 'project': obj, 'groups': obj.all_groups(), 'add_user_form': UserManageForm(), 'access_form': access_form, })
def manage_access(request, project): """User management view.""" obj = get_project(request, project) if not request.user.has_perm("project.permissions", obj): raise PermissionDenied() return render( request, "manage-access.html", { "object": obj, "project": obj, "groups": Group.objects.for_project(obj), "all_users": User.objects.for_project(obj), "blocked_users": obj.userblock_set.select_related("user"), "add_user_form": UserManageForm(), "block_user_form": UserBlockForm( initial={"user": request.GET.get("block_user")} ), "invite_user_form": InviteUserForm(), "ssh_key": get_key_data(), }, )