예제 #1
0
파일: views.py 프로젝트: hilerchyn/seahub
def group_list(request):
    username = request.user.username

    if request.method == "POST":
        """
        Add a new group.
        """
        result = {}
        content_type = "application/json; charset=utf-8"

        form = GroupAddForm(request.POST)
        if form.is_valid():
            group_name = form.cleaned_data["group_name"]

            # Check whether group name is duplicated.
            if request.cloud_mode:
                checked_groups = get_personal_groups_by_user(username)
            else:
                checked_groups = get_personal_groups(-1, -1)
            for g in checked_groups:
                if g.group_name == group_name:
                    result["error"] = _(u"There is already a group with that name.")
                    return HttpResponse(json.dumps(result), status=400, content_type=content_type)

            # Group name is valid, create that group.
            try:
                ccnet_threaded_rpc.create_group(group_name.encode("utf-8"), username)
                return HttpResponse(json.dumps({"success": True}), content_type=content_type)
            except SearpcError, e:
                result["error"] = _(e.msg)
                return HttpResponse(json.dumps(result), status=500, content_type=content_type)
        else:
            return HttpResponseBadRequest(json.dumps(form.errors), content_type=content_type)
예제 #2
0
파일: views.py 프로젝트: TanLian/seahub
def group_add(request):
    """Add a new group"""
    if request.method != 'POST':
        raise Http404

    username = request.user.username
    result = {}
    content_type = 'application/json; charset=utf-8'

    user_can_add_group = request.user.permissions.can_add_group()
    if not user_can_add_group:
            result['error'] = _(u'You do not have permission to create group.')
            return HttpResponse(json.dumps(result), status=403,
                                content_type=content_type)

    # check plan
    num_of_groups = getattr(request.user, 'num_of_groups', -1)
    if num_of_groups > 0:
        current_groups = len(request.user.joined_groups)
        if current_groups > num_of_groups:
            result['error'] = _(u'You can only create %d groups.<a href="http://seafile.com/">Upgrade account.</a>') % num_of_groups
            return HttpResponse(json.dumps(result), status=403,
                                content_type=content_type)

    form = GroupAddForm(request.POST)
    if form.is_valid():
        group_name = form.cleaned_data['group_name']

        # Check whether group name is duplicated.
        org_id = -1
        if is_org_context(request):
            org_id = request.user.org.org_id
            checked_groups = seaserv.get_org_groups_by_user(org_id, username)
        else:
            if request.cloud_mode:
                checked_groups = seaserv.get_personal_groups_by_user(username)
            else:
                checked_groups = get_all_groups(-1, -1)
        for g in checked_groups:
            if g.group_name == group_name:
                result['error'] = _(u'There is already a group with that name.')
                return HttpResponse(json.dumps(result), status=400,
                                    content_type=content_type)

        # Group name is valid, create that group.
        try:
            if org_id > 0:
                create_org_group(org_id, group_name, username)
            else:
                create_group(group_name, username)

            return HttpResponse(json.dumps({'success': True}),
                        content_type=content_type)
        except SearpcError, e:
            result['error'] = _(e.msg)
            return HttpResponse(json.dumps(result), status=500,
                            content_type=content_type)
예제 #3
0
파일: views.py 프로젝트: octomike/seahub
def group_add(request):
    """Add a new group"""
    if request.method != 'POST':
        raise Http404

    username = request.user.username
    result = {}
    content_type = 'application/json; charset=utf-8'

    user_can_add_group = request.user.permissions.can_add_group()
    if not user_can_add_group:
            result['error'] = _(u'You do not have permission to create group.')
            return HttpResponse(json.dumps(result), status=403,
                                content_type=content_type)

    # check plan
    num_of_groups = getattr(request.user, 'num_of_groups', -1)
    if num_of_groups > 0:
        current_groups = len(request.user.joined_groups)
        if current_groups > num_of_groups:
            result['error'] = _(u'You can only create %d groups.<a href="http://seafile.com/">Upgrade account.</a>') % num_of_groups
            return HttpResponse(json.dumps(result), status=403,
                                content_type=content_type)

    form = GroupAddForm(request.POST)
    if form.is_valid():
        group_name = form.cleaned_data['group_name']

        # Check whether group name is duplicated.
        org_id = -1
        if is_org_context(request):
            org_id = request.user.org.org_id
            checked_groups = seaserv.get_org_groups_by_user(org_id, username)
        else:
            if request.cloud_mode:
                checked_groups = seaserv.get_personal_groups_by_user(username)
            else:
                checked_groups = get_all_groups(-1, -1)
        for g in checked_groups:
            if g.group_name == group_name:
                result['error'] = _(u'There is already a group with that name.')
                return HttpResponse(json.dumps(result), status=400,
                                    content_type=content_type)

        # Group name is valid, create that group.
        try:
            if org_id > 0:
                create_org_group(org_id, group_name, username)
            else:
                create_group(group_name, username)

            return HttpResponse(json.dumps({'success': True}),
                        content_type=content_type)
        except SearpcError, e:
            result['error'] = _(e.msg)
            return HttpResponse(json.dumps(result), status=500,
                            content_type=content_type)
예제 #4
0
파일: views.py 프로젝트: scream4ik/students
def group_add(request):

    form = GroupAddForm(request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            form.save()
            return redirect('students.views.index')

    return TemplateResponse(request, 'group_add.html', {'form': form})
예제 #5
0
파일: views.py 프로젝트: scream4ik/students
def group_add(request):
	
	form = GroupAddForm(request.POST or None)
	
	if request.method == 'POST':
		if form.is_valid():
			form.save()
			return redirect('students.views.index')
	
	return TemplateResponse(request, 'group_add.html', {'form': form})
예제 #6
0
def group(action):
    """group
    """
    if action == 'add':
        form = GroupAddForm()
        if form.validate_on_submit():
            name = form.data['name']
            description = form.data['description']
            if GroupCtl.add(current_user.id, name, description):
                flash(u'操作成功', 'success')
            else:
                flash(u'操作失败', 'error')
        kwargs = {'form': form}
        return render_template('customer_group_add.html', **kwargs)
    if action == 'edit':
        group_id = request.args.get('group_id', '')
        group = GroupCtl.get(group_id)
        form = GroupEditForm()
        if group:
            form.group_id.data = group.id
            form.name.data = group.name
            form.description.data = group.description
        kwargs = {'form': form}
        return render_template('customer_group_add.html', **kwargs)
    if action == 'delete':
        group_id = request.args.get('group_id', '')
        group = GroupCtl.delete(group_id)
        if group:
            flash(u'操作成功', 'success')
        else:
            flash(u'操作失败', 'error')
        return redirect(url_for('Common.group', action='list'))
    if action == 'list':
        groups = GroupCtl.get_all()
        owner_dict = {}
        for i in groups:
            try:
                owner_dict[i.owner] = AdminCtl.get(i.owner).name
            except:
                # 如果用户被删除,则AdminCtl.get可能引发异常
                pass
        kwargs = {'groups': groups, 'owner_dict': owner_dict}

        return render_template('customer_group.html', **kwargs)
    return render_template("404.html")
예제 #7
0
def group_create(request):
    logger.debug("group_create called by user %s" % request.user)
    choices = [(None, 'None'),]
    for g in ExtendedGroup.objects.get_parents_for_user(request.user):
        choices.append((g.id, str(g)))
    if request.method == 'POST':
        form = GroupAddForm(request.POST)
        form.fields['parent'].choices = choices
        logger.debug("Received POST request containing form, is valid: %s" % form.is_valid())
        if form.is_valid():
            name = form.cleaned_data['name']
            desc = form.cleaned_data['description']
            hidden = form.cleaned_data['hidden']
            parent_id = form.cleaned_data['parent']
            if parent_id:
                parent = get_object_or_404(ExtendedGroup, id=parent_id)
            else:
                parent = None
            app = form.cleaned_data['applications']
            group, c = Group.objects.get_or_create(name=name)
            if c is False:
                if ExtendedGroup.objects.filter(group=group).exists() is False:
                    if AutoGroup.obkects.filter(group=group).exists() is False:
                        logger.warn("Associating orphaned group %s with new extended group created by %s" % (group, request.user))
                    else:
                        logger.error("User %s attempting to create ExtendedGroup for %s" % (request.user, AutoGroup.objects.get(group=group)))
                        return redirect('groupmanagement.views.group_list')
                else:
                    logger.error("User %s attempting to create duplicate ExtendedGroup for %s" % (request.user, group))
                    return redirect('groupmanagement.views.group_list')
            e = ExtendedGroup(group=group, owner=request.user, description=desc, hidden=hidden, parent=parent, require_application=app)
            e.save()
            logger.info("User %s created group %s" % (request.user, e))
            return redirect('groupmanagement_group_list_management')
    else:
        form = GroupAddForm()
        form.fields['parent'].choices = choices
    context = {
        'form': form,
        'title': 'Create Group',
        'button_text': 'Create',
    }
    return render(request, 'public/form.html', context=context)