Exemplo n.º 1
0
def remove_group(request, id):
    try:
        selected_item = Group.objects.get(pk=id)
        selected_item.delete()
        form = GroupForm()
    except Group.DoesNotExist:
        raise Http404("This item not exist.")
    groups = Group.objects.all()
    return HttpResponseRedirect('/group')
Exemplo n.º 2
0
def update_group(request, id):
	data = {}
	try:
		selected_item = Group.objects.get(pk=id)
		form = GroupForm(instance=selected_item)
	except Group.DoesNotExist:
		raise Http404("This item not exist.")
	if request.method == 'POST':
		form = GroupForm(request.POST or None, instance=selected_item)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/group')
	groups = Group.objects.all()
	data['id'] = id
	data['groups'] = groups
	data['form'] = form
	return render(
		request,
		'home/group.html',
		data
	)
Exemplo n.º 3
0
def update_group(request, id):
    data = {}
    try:
        selected_item = Group.objects.get(pk=id)
        form = GroupForm(instance=selected_item)
    except Group.DoesNotExist:
        raise Http404("This item not exist.")
    if request.method == 'POST':
        form = GroupForm(request.POST or None, instance=selected_item)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/group')
    groups = Group.objects.all()
    data['id'] = id
    data['groups'] = groups
    data['form'] = form
    return render(request, 'home/group.html', data)
Exemplo n.º 4
0
def group(request):
    s = request.session.get('users_id', None)
    if not s:
        return HttpResponseRedirect('/auth')
    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            newdoc = Group()
            newdoc.users_id = request.POST['users']
            newdoc.name = request.POST['name']
            request.session['users_id'] = newdoc.users_id
            newdoc = form.save(commit=False)
            newdoc.save()
            form.save_m2m()
            return HttpResponseRedirect('/group')
    else:
        form = GroupForm()
    groups = Group.objects.all()
    return render_to_response('home/group.html', {
        'groups': groups,
        'form': form
    },
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def group(request):
	s = request.session.get('users_id', None)
	if not s:
		return HttpResponseRedirect('/auth')
	if request.method == 'POST':
		form = GroupForm(request.POST)
		if form.is_valid():
			newdoc = Group()
			newdoc.users_id = request.POST['users']
			newdoc.name = request.POST['name']
			request.session['users_id'] = newdoc.users_id
			newdoc = form.save(commit=False)
			newdoc.save()
			form.save_m2m()
			return HttpResponseRedirect('/group')
	else:
		form = GroupForm()
	groups = Group.objects.all()
	return render_to_response(
		'home/group.html',
		{'groups': groups, 'form': form},
		context_instance=RequestContext(request)
	)