Esempio n. 1
0
 def post(self, request):
     main_user = Account.objects.select_related().get(pk=request.user.pk)
     group = Group.objects.create()
     form = GroupForm(request.POST, instance=group)
     if form.is_valid():
         group.admin.add(main_user)
         group.subscribers.add(main_user)
         form.save()
         group.save()
     return redirect('group', pk=group.pk)
Esempio n. 2
0
def group_add_edit(request, groupid=None):
    if groupid:
        group = get_object_or_404(Group, id=groupid)
        form = GroupForm(request.POST or None, instance=group)
        template = 'group_edit.html'
    else:
        group = None
        form = GroupForm(request.POST or None)
        template = 'group_add.html'

    if form.is_valid():
        group = form.save()
        if groupid:
            messages.success(request,
                             'The group "%s" has been updated.' % group.name)
            AddLogEntry(username=request.user,
                        type='configchange',
                        event='Edited group "%s"' % group.name)
        else:
            messages.success(request,
                             'The group "%s" has been created.' % group.name)
            AddLogEntry(username=request.user,
                        type='configchange',
                        event='Created new group "%s"' % group.name)
        return HttpResponseRedirect(reverse('group_list'))

    return render(request, template, {'form': form, 'group': group})
Esempio n. 3
0
def edit_group(request, group_id=None):
    if request.method == 'POST':
        if group_id is None:
            form = GroupForm(request.POST)
        else:
            edit_group = get_object_or_404(Group, id=group_id)
            form = GroupForm(request.POST, instance=edit_group)
        if form.is_valid():
            form.save()
            return redirect(reverse('group:groups_list', args={}))
    else:
        if group_id is None:
            form = GroupForm()
        else:
            group = get_object_or_404(Group, id=group_id)
            form = GroupForm(instance=group)
        return render(request, 'group/edit_group.html', {
            'form': form,
        })
Esempio n. 4
0
def add(request):

    if request.method == 'POST':
        form = GroupForm(request.POST)

        if form.is_valid():
            form.instance.techname = techify(form.cleaned_data['name'])
            group = form.save()
            return HttpResponseRedirect('/group/view/%s' % group.techname)

    else:
        form = GroupForm()

    return render_to_response('group/add.html', { 'form': form }, context_instance=RequestContext(request))
Esempio n. 5
0
def edit(request, techname):

    group = get_object_or_404(Group, techname=techname)

    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)

        if form.is_valid():
            form.instance.techname = techify(form.cleaned_data['name'])
            group = form.save()
            return HttpResponseRedirect('/group/view/%s/' % group.techname)

    else:
        form = GroupForm(instance=group)

    return render_to_response('group/edit.html', { 'form': form, 'group': group }, context_instance=RequestContext(request))
Esempio n. 6
0
 def post(request):
     form = GroupForm(data=request.POST)
     if form.is_valid():
         group = form.save(commit=False)
         if 'source_lat' in request.POST:
             group.source = Point(float(request.POST['source_lat']),
                                  float(request.POST['source_lon']))
         group.save()
         CreateGroupManager.index_goup(group, request)
         Membership.objects.create(member=request.user,
                                   group=group,
                                   role='ow')
         log.info("user:{} made group:{}".format(request.user.id, group.id))
         return redirect(reverse('group:groups_list'))
     return render(request, "create_group.html", {
         "form": form,
     })
Esempio n. 7
0
def new(request):
    if request.user.has_judge_auth():
        if request.method == 'GET':
            form = GroupForm(
                user=request.user, initial={'owner': request.user})
            return render_index(request, 'group/editGroup.html', {'form': form})
        if request.method == 'POST':
            form = GroupForm(request.POST, initial={'owner': request.user})
            if form.is_valid():
                new_group = form.save()
                logger.info('Group: Create a new group %s!' % new_group.id)
                return HttpResponseRedirect(reverse('group:list'))
            else:
                return render_index(
                    request,
                    'group/editGroup.html', {'form': form})
    else:
        raise PermissionDenied
Esempio n. 8
0
def new(request):

    if request.user.has_judge_auth():
        if request.method == 'GET':
            form = GroupForm()
            return render_index(request,'group/editGroup.html',{'form':form})
        if request.method == 'POST':
            form = GroupForm(request.POST)
            if form.is_valid():
                new_group = form.save()
                logger.info('Group: Create a new group %s!' % new_group.id)
                return HttpResponseRedirect(reverse('group:list'))
            else:
                return render(
                    request,
                    'index/404.html',
                    {'error_message': 'Cannot create group! Info is blank!'})
    else:
        raise PermissionDenied
Esempio n. 9
0
def group_add_edit(request,groupid=None):
    if groupid:
        group = get_object_or_404(Group, id=groupid)
        form = GroupForm(request.POST or None, instance=group)
        template = 'group_edit.html'
    else:
        group = None
        form = GroupForm(request.POST or None)
        template = 'group_add.html'

    if form.is_valid():
        group = form.save()
        if groupid:
            messages.success(request, 'The group "%s" has been updated.' % group.name)
            AddLogEntry(username=request.user, type='configchange', event='Edited group "%s"' % group.name)
        else:
            messages.success(request, 'The group "%s" has been created.' % group.name)
            AddLogEntry(username=request.user, type='configchange', event='Created new group "%s"' % group.name)
        return HttpResponseRedirect(reverse('group_list'))

    return render(request, template, {
        'form': form,
        'group': group
    })
Esempio n. 10
0
 def post(self, request, pk):
     group = Group.objects.select_related().get(pk=pk)
     form = GroupForm(request.POST, instance=group)
     if form.is_valid():
         form.save()
     return redirect('group', pk=group.pk)