Esempio n. 1
0
def edit_group(grupo):
	# grupo = Grupo.objects.get_or_404(nombre=grupo)
	grupo = Grupo.objects.get_or_create(nombre=grupo,defaults={'horario': 'Sin definir'})
	grupo_id=grupo[0].id
	# if len(grupo[0].horario)<1:
	# 	grupo[0].horario = 'Sin definir'
	# user_json=usuario
	# uuu = [{'nombre':'nombre','username':'username'}]
	# post = Usuario.objects.get_or_404(username=username)
	form = GroupForm(request.form,grupo[0])
	if request.method == 'POST':
		if form.validate() == False:
			flash('Todos los campos son necesarios.')
			return render_template('usuarios/groups.html', form=form, data_type="Grupos", action="Editar")
		else:
			# flash('Valores por defecto.')
			g=Grupo.objects.get(id=grupo_id)
			g.update(set__nombre=form.nombre.data)
			g.update(set__horario=form.horario.data)
			# grupo[0].nombre=form.nombre.data
			# grupo[0].horario=form.horario.data
			# grupo[0].save()
			# return render_template('usuarios/groups.html', form=form, data_type="Grupos", action="Editar")
			grupos = Grupo.objects.all()
			return render_template ('usuarios/groups.html', grupos=grupos, action="Listar")
			# return render_template('grupos.html')
 
	elif request.method == 'GET':
		return render_template('usuarios/groups.html', form=form, data_type="Grupos", action="Editar")
Esempio n. 2
0
def edit_group(request, id):
    group = get_object_or_404(Group, id=id)
    try:
        group_title = models.GroupTitle.objects.get(group=group)
    except models.GroupTitle.DoesNotExist:
        group_title = None

    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        group_title_form = GroupTitleForm(request.POST, prefix='gtf', instance=group_title)
        if form.is_valid() and group_title_form.is_valid():
            group = form.save(commit=False)

            if form.cleaned_data['permissions']:
                group.permissions = form.cleaned_data['permissions']
            else:
                group.permissions.clear()

            group.save()

            if not group_title:
                group_title = group_title_form.save(commit=False)
                group_title.group = group
                group_title.save()
            else:
                group_title_form.save()
            return redirect('accounts:administration:groups_list')
    else:
        form = GroupForm(instance=group)
        group_title_form = GroupTitleForm(prefix='gtf', instance=group_title)
    return render(request, 'accounts/administration/edit_group.html', {
        'form': form,
        'group_title_form': group_title_form
    })
Esempio n. 3
0
def addGroup():

  if 'email' not in session:
    return redirect(url_for('signin'))

  user = Smarketer.query.filter_by(username = session['email']).first()

  if user is None:
    return redirect(url_for('signin'))
  else:
    form = GroupForm()

    if request.method == 'POST':
      if form.validate() == False:
        return render_template('addGroup.html', form=form)
      else:
	totalTitle = form.groupTitle.data + " - " + form.groupID.data
        newGroup = Group(form.groupID.data, totalTitle)
        db.session.add(newGroup)
        db.session.commit()

	form.groupID.data = ""
	form.groupTitle.data = ""
        return render_template('addGroup.html', form=form, success=True)

    elif request.method == 'GET':
      return render_template('addGroup.html', form=form)
Esempio n. 4
0
def new_group(request):
    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            group_code = helper.post_request("https://a6.cfapps.io/groups", {})
            groupID = json.loads(group_code)['groupId']
            group = Group.objects.create(code=groupID, name=form.cleaned_data['name'])
            group.save()
            #Create a new subscription for group
            url = "https://a6.cfapps.io/subscriptions"
            payload = {}
            payload['groupId'] = group.code
            payload['insights'] = [
                "home.window.open",
                "home.window.closed",
                "home.garage.open",
                "home.garage.closed",
                "home.smoke.alarm_on",
                "home.smoke.alarm_off",
                "home.smoke.alarm_battery_low",
                "home.fire.alarm_on",
                "home.fire.alarm_off",
                "home.water.sensor.alarm_on",
                "home.water.sensor.alarm_off",
                "vehicle.trip.arrived",
                "vehicle.health.arrived"]
            payload['webhookUrl'] = 'https://homesensing.cfapps.io/callback'
            result = helper.post_request(url, payload)
            print result
            return HttpResponseRedirect("/index")
    else:
        form = GroupForm()
    return render_to_response('new_group.html', { 'form' : form }, context_instance=RequestContext(request))
Esempio n. 5
0
def group_create(request):
    """
    create a form a user can use to create a custom group, on POST save this group to the database
    and automatically add the creator to the said group as a manager.
    """
    nav_selected = "communities"
    if request.method == "POST":
        form = GroupForm(request.POST, request.FILES)
        if form.is_valid():
            group = form.save()
            GroupUsers.objects.create(group=group, user=request.user, is_manager=True)
            Stream.objects.get(slug="community-create").enqueue(content_object=group, start=group.created)
            Record.objects.create_record(request.user, 'group_create', group)
            badge_cache.possibly_award_badge('created_a_community', user=request.user)
            messages.success(request, _("%(group)s has been created.") % {
                    'group': group})
            return redirect("group_detail", group_slug=group.slug)
    else:
        form = GroupForm()
    return render_to_response("groups/group_create.html", {
        "form": form,
        "site": Site.objects.get_current(),
        "nav_selected": nav_selected,
        'external_group': False,
    }, context_instance=RequestContext(request))
Esempio n. 6
0
def groups(group_id=None):
    form = GroupForm(request.form)
    if request.method == 'POST':
        if not form.validate():
            pass
        else:
            pass
    return render_template('groups.html', user=get_user(), form=form)
Esempio n. 7
0
def save_new_group(request):

    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            group = Group()
            group.name = form.cleaned_data['name']
            group.max_loan_days = form.cleaned_data['max_loan_days']
            group.save()

    return HttpResponseRedirect('/webconf/couchauth/')
Esempio n. 8
0
def create_group(request):
    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('accounts:administration:groups_list')
    else:
        form = GroupForm()
    return render(request, 'accounts/administration/create_group.html', {
        'form': form
    })
Esempio n. 9
0
def save_new_group(request):

    if request.method == 'POST':

        form = GroupForm(request.POST)
        if form.is_valid():

            group = Group()
            group.name = form.cleaned_data['name']
            group.save()

    return HttpResponseRedirect('/webconf/aclsmanager/show_groups/')
Esempio n. 10
0
def save_group(request, group_id):
    try:
        group = Group.objects.get(id=group_id)
    except Group.DoesNotExist:
        return HttpResponseRedirect('/webconf/aclsmanager/show_groups/')

    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():
            group.name = form.cleaned_data['name']
            group.save()

    return HttpResponseRedirect('/webconf/aclsmanager/show_groups/')
Esempio n. 11
0
def add_group(request):
    
    if request.method == 'POST':
        groupForm = GroupForm(request.POST)
        if groupForm.is_valid():
            group = groupForm.save()
            request.user.message_set.create(message=_('Group created'))
            return redirect('picket-admin-users')
    else:
        groupForm = GroupForm()
    
    return direct_to_template(request, 'picket/admin/group_add.html',
        {'group_form': groupForm,})
Esempio n. 12
0
def groups():
    form = GroupForm()
    if form.validate_on_submit():
        group_id = form.id.data
        if group_id:
            group = models.Group.query.get(group_id)
            group.name = form.name.data
        else:
            group = models.Group(name=form.name.data)
            db.session.add(group)
        db.session.commit()
        flash('The group was successffully saved.', 'success')
        return redirect(url_for('groups'))
    groups = models.Group.query.all()
    return render_template('groups.html', form=form, groups=groups)
Esempio n. 13
0
def add_group(request):
    context = {}

    if request.method == "POST":
        form = GroupForm(request.POST)
        if form.is_valid():
            group = form.save(commit=False)
            group.added_by = request.user
            group.save()
            return HttpResponseRedirect("/group/%s" % group.id)
    else:
        form = GroupForm()

    context["form"] = form
    return r2r(request, "add_group", context)
Esempio n. 14
0
def edit_group(request, groupId):
    
    group = get_object_or_404(Group, id=groupId)
    
    if request.method == 'POST':
        groupForm = GroupForm(request.POST, instance=group)
        if groupForm.is_valid():
            group = groupForm.save()
            request.user.message_set.create(message=_('Group updated'))
            return redirect('picket-admin-users')
    else:
        groupForm = GroupForm(instance=group)
    
    return direct_to_template(request, 'picket/admin/group_edit.html',
        {'group_form': groupForm,})
Esempio n. 15
0
def group_add(request):
    temp_name = "cmdb/cmdb-header.html"
    if request.method == "POST":
        group_form = GroupForm(request.POST)
        if group_form.is_valid():
            group_form.save()
            tips = u"增加成功!"
            display_control = ""
        else:
            tips = u"增加失败!"
            display_control = ""
        return render(request, "cmdb/group_base.html", locals())
    else:
        display_control = "none"
        group_form = GroupForm()
        return render(request, "cmdb/group_base.html", locals())
Esempio n. 16
0
def edit_group(request, group_id):
    context = {}
    group = Group.objects.get(pk=group_id)

    if not request.user.is_staff and request.user.email != group.added_by.email:
        return HttpResponseRedirect("/group/%s" % group_id)

    if request.method == "POST":
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/group/%s" % group_id)
    else:
        form = GroupForm(instance=group)

    context["form"] = form
    return r2r(request, "edit_group", context)
Esempio n. 17
0
 def post(self, request, format=None, *args, **kwargs):
     if format == 'html' or format == None:
         form = GroupForm(request.POST)
         if form.is_valid():
             group = form.save(commit=False)
             group.creator = request.user
             group.save()
             group.members.add(request.user)
             group.save()
             return redirect('/groups/' + str(group.id))
     elif format == 'json':
         serializer = GroupSerializer(data=request.DATA)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data, status=status.HTTP_201_CREATED)
         else:
             return Response(serializer.errors)
Esempio n. 18
0
def edit_group(request, group_id):
    projects = Project.objects.all()
    print(request.POST)
    try:
        group = ReportGroup.objects.get(pk=group_id)
    except Exception as e:
        print("Exception: " + str(e))
    try:
        members = GroupMember.objects.filter(group=group)
    except Exception as e:
        print("Exception: " + str(e))
    try:
        users = User.objects.all()
        user_list = []
        for user in users:
            keep = True
            for member in members:
                if member.user == user:
                    keep = False
            if keep:
                user_list.append(user)

    except Exception as e:
        print("Exception: " + str(e))
    if request.method == 'POST':
        try:
            form = GroupForm(request.POST, instance=group)
            added_members = request.POST.getlist('new_members')
            removed_members = request.POST.getlist('del_members')
            if form.is_valid():
                group = form.save()
                for member in added_members:
                    temp = User.objects.get(pk=member)
                    new_member = GroupMember(group=group, user=temp)
                    new_member.save()
                for member in removed_members:
                    temp = User.objects.get(pk=member)
                    old_member = GroupMember.objects.get(user=temp, group=group)
                    old_member.delete()
                return redirect('daily_reports.views.request_report_summary')
        except Exception as e:
            print(e)
    else:
        form = GroupForm(instance=group)
    return render_to_response('daily_reports/edit_report_group.html', {'members': members, 'users': user_list, 'form': form, 'projects': projects, 'group': group}, context_instance=RequestContext(request))
Esempio n. 19
0
def group_add(request, response_format='html'):
    "Group add"

    if request.POST:
        if 'cancel' not in request.POST:
            form = GroupForm(request.POST)
            if form.is_valid():
                group = form.save()
                return HttpResponseRedirect(reverse('core_admin_group_view', args=[group.id]))
        else:
            return HttpResponseRedirect(reverse('core_admin_index_groups'))

    else:
        form = GroupForm()

    return render_to_response('core/administration/group_add',
                              {'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 20
0
def create_group(request):
    if request.method == 'POST':
        form = GroupForm(request.POST)
        group_title_form = GroupTitleForm(request.POST, prefix='gtf')
        if form.is_valid() and group_title_form.is_valid():
            group = form.save(commit=False)
            group.save()
            group_title = group_title_form.save(commit=False)
            group_title.group = group
            group_title.save()
            return redirect('accounts:administration:groups_list')
    else:
        form = GroupForm()
        group_title_form = GroupTitleForm(prefix='gtf')
    return render(request, 'accounts/administration/create_group.html', {
        'form': form,
        'group_title_form': group_title_form
    })
Esempio n. 21
0
def save_group(request, group_id):
    if request.method == 'POST':
        form = GroupForm(request.POST)
        if form.is_valid():

            try:
                group = Group.get(group_id)
            except:
                return HttpResponseRedirect('/webconf/couchauth/show_groups/')

            users = request.POST.getlist('users')
            group.update_users(users)
            if group.name != form.cleaned_data['name']:
                group.name = form.cleaned_data['name']
                group.save()


    return HttpResponseRedirect('/webconf/couchauth/show_groups/')
Esempio n. 22
0
def group_edit(request, group_id):
    project = HostGroup.objects.get(id=group_id)
    temp_name = "cmdb/cmdb-header.html"
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=project)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('group'))
    else:
        form = GroupForm(instance=project)
    display_control = "none"
    results = {
        'group_form': form,
        'group_id': group_id,
        'request': request,
        'temp_name': temp_name,
        'display_control': display_control,
    }
    return render(request, 'cmdb/group_base.html', results)
Esempio n. 23
0
def set_organization_group(request, org_url, group_role=""):
    organization = request.organization
    #get or create revelant organization group
    try:
        organizationgroup = OrganizationGroup.objects.filter(
            role__exact=group_role,
            org=organization)[0]
    except IndexError:
        organizationgroup = None

    if not organizationgroup:
        role_name = dict(OrganizationGroup.GROUP_ROLES)[group_role]
        group_name = u"%s %s" % (organization.name, role_name)
        group = Group.objects.get_or_create(name=group_name)
        organizationgroup = OrganizationGroup.objects.create(
            role=group_role,
            group=group[0],
            org=organization)

    form = GroupForm(
        request.POST or None,
        instance=organizationgroup.group)
    form.fields["users"].queryset = organization.staff_group.user_set.all()

    if form.is_valid():
        group = form.save()
        # store reference to group in organization
        setattr(organization, group_role, group)
        organization.save()
        return redirect("organization", (org_url,))

    return render(
        request,
        "organizations/edit_group.html",
        dict(
            form=form,
            org=organization,
            group=organizationgroup.group,
            group_types=organizationgroup.GROUP_ROLES,
            org_url=org_url
        ),
    )
Esempio n. 24
0
def setup_report_group(request):
    projects = Project.objects.all()
    users = User.objects.all()
    if request.method == 'POST':
        try:
            group = ReportGroup()
            form = GroupForm(request.POST, instance=group)
            members = request.POST.getlist('users')
            if form.is_valid():
                group = form.save()
                for member in members:
                    temp = User.objects.get(username=member)
                    new_member = GroupMember(group=group, user=temp)
                    new_member.save()
                return redirect('daily_reports.views.request_report_summary')
        except Exception as e:
            print("Exception: " + str(e))
    else:
        form = GroupForm()
    return render_to_response('daily_reports/report_group_form.html', {'users': users, 'projects': projects, 'form': form}, context_instance=RequestContext(request))
Esempio n. 25
0
def group_edit(request, group_id, response_format='html'):
    "Group edit"

    group = get_object_or_404(Group, pk=group_id)

    if request.POST:
        if 'cancel' not in request.POST:
            form = GroupForm(request.POST, instance=group)
            if form.is_valid():
                group = form.save()
                return HttpResponseRedirect(reverse('core_admin_group_view', args=[group.id]))
        else:
            return HttpResponseRedirect(reverse('core_admin_group_view', args=[group.id]))
    else:
        form = GroupForm(instance=group)

    return render_to_response('core/administration/group_edit',
                              {'group': group,
                               'form': form},
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 26
0
def edit_group(request, id):
    group = get_object_or_404(Group, id=id)
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            group = form.save(commit=False)

            if form.cleaned_data['permissions']:
                group.permissions = form.cleaned_data['permissions']
            else:
                group.permissions.clear()

            group.save()
            return redirect('accounts:administration:groups_list')
    else:
        form = GroupForm(instance=group)

    return render(request, 'accounts/administration/edit_group.html', {
        'form': form
    })
Esempio n. 27
0
def create_group():
    if g.user.max_groups():
        flash(gettext('How many groups do you need to be in? Only 5 for you :)'))
        return redirect(url_for('index'))
    form = GroupForm()
    if form.validate_on_submit():
        group = Group(group_name = form.group_name.data,
            about_group = form.about_group.data,
            public = form.public.data)
        db.session.add(group)
        db.session.commit()
        # Create group, add creator to admin and user list.
        db.session.add(group.add_admin(g.user))
        db.session.add(group.add_user(g.user))
        db.session.commit()
        flash('Welcome to your new group!  Now add some friends!')
        return redirect(url_for('group', group_id = group.id))
    return render_template('group_form.html',
        title = 'Create Group',
        form = form)
Esempio n. 28
0
def group_edit(request, group_slug):
    nav_selected = "communities"
    group = get_object_or_404(Group, slug=group_slug, is_geo_group=False)
    if not group.is_user_manager(request.user):
        return forbidden(request)

    if group.is_external_link_only:
        return _group_external_link_only_edit(request, group)

    external_group = False
    if request.method == "POST":
        if "change_group" in request.POST:
            group_form = GroupForm(request.POST, request.FILES, instance=group)
            if group_form.is_valid():
                group = group_form.save()
                messages.success(request, _("%(group)s has been updated.") % {'group': group})
                return redirect("group_edit", group_slug=group.slug)
            else:
                membership_form = MembershipForm(group=group)
                discussions_form = DiscussionSettingsForm(instance=group)
        if "discussion_settings" in request.POST:
            discussions_form = DiscussionSettingsForm(request.POST, instance=group)
            if discussions_form.is_valid():
                group = discussions_form.save()
                messages.success(request, _("%(group)s has been updated.") % {'group': group})
                return redirect("group_edit", group_slug=group.slug)
            else:
                membership_form = MembershipForm(group=group)
                group_form = GroupForm(instance=group)
        elif "delete_group" in request.POST:
            group.delete()
            messages.success(request, _("%(group)s has been deleted.") % {'group': group})
            return redirect("group_list")
        elif "change_membership" in request.POST:
            membership_form = MembershipForm(group=group, data=request.POST)
            if membership_form.is_valid():
                membership_form.save()
                if group.is_user_manager(request.user):
                    messages.success(request, _("%(group)s's memberships have been updated.") % {
                            'group': group})
                    return render_to_response("groups/group_edit.html", locals(), 
                                              context_instance=RequestContext(request))
                else:
                    messages.success(request,
                                     _("You no longer have permissions to edit %(group)s") % {
                                'group': group})
                    return redirect("group_detail", group_slug=group.slug)
            else:
                group_form = GroupForm(instance=group)
                discussions_form = DiscussionSettingsForm(instance=group)
        else:
            messages.error(request, _("No action specified."))
    else:
        group_form = GroupForm(instance=group)
        membership_form = MembershipForm(group=group)
        discussions_form = DiscussionSettingsForm(instance=group)
    site = Site.objects.get_current()
    requesters = group.requesters_to_grant_or_deny(request.user)
    return render_to_response("groups/group_edit.html", locals(), 
                              context_instance=RequestContext(request))
Esempio n. 29
0
def show_group(request, group_id):
    try:
        group = Group.get(group_id)
    except:
        return HttpResponseRedirect('/webconf/couchauth/show_groups/')

    form = GroupForm(instance=group)
    if form.is_valid():
        group = Group()
        group.name = form.cleaned_data['name']
        group.max_loan_days = form.cleaned_data['max_loan_days']
        group.save()
    form_url = "/webconf/couchauth/save_group/%s/" % group_id
    context = { 'form': form,
                'form_title': 'Editar Grupo',
                'group': group,
                'form_url': form_url,
                }
    return render_to_response('webconf/couchauth/form_group.html',
                              context,
                              context_instance=RequestContext(request)
                              )
Esempio n. 30
0
def	TmcData6(request):


    if CheckAccess(request,'2') != 'OK':
	return render_to_response("tmc/notaccess/tmc.html")


    ## --- Номер заявки ---
    try:
	tmc_id = request.GET['tmc_id']
	request.session['tmc_id'] = tmc_id
    except:
	pass

    try:
	tmc_id = request.session['tmc_id']
    except:
	return HttpResponseRedirect("/tmc")


    if request.method == 'POST':
	form = GroupForm(request.POST)
	if form.is_valid():
	    comment = form.cleaned_data['comment']
	    group = form.cleaned_data['group']
	    ChangeTmcGroup(GetUserKod(request),tmc_id,comment,group)



    d = GetTmcData(tmc_id)
    data = GetGroupHistory(tmc_id)

    form = GroupForm(None)

    s =GetLastStatus(tmc_id)

    c = RequestContext(request,{'d':d,'form':form,'data':data,'s':s})
    c.update(csrf(request))
    return render_to_response("tmc/tmcdata6.html",c)