def CreatePageContent(self): ''' Update details and show form. ''' if self.request.method == 'POST': if self.isAdd: self.groupservice, created = GroupService.objects.get_or_create(group=self.group, service=self.service) else: GroupServiceProperty.objects.filter(groupservice = self.groupservice).delete() serviceproperties = ServiceProperty.objects.filter(service=self.groupservice.service).order_by('id') for serviceproperty in serviceproperties: if serviceproperty.type == "LOC": f = LocationPropertyForm(self.request.POST, prefix=serviceproperty.id) else: f = GenericPropertyForm(self.request.POST, prefix=serviceproperty.id) if f.is_valid(): if len(f.cleaned_data['value']) > 0: newgsp = GroupServiceProperty(groupservice=self.groupservice, serviceproperty=serviceproperty, value=f.cleaned_data['value']) newgsp.save() return HttpResponseRedirect(reverse('MyPidge.Groups.views.EditServices', args=[str(self.group.id)])) serviceproperties = ServiceProperty.objects.filter(service=self.service).order_by('id') form = "" for serviceproperty in serviceproperties: value="" if not self.isAdd: try: gsp = GroupServiceProperty.objects.get(groupservice=self.groupservice, serviceproperty=serviceproperty) value = gsp.value except (GroupServiceProperty.DoesNotExist, MultipleObjectsReturned): pass if serviceproperty.type == "LOC": f = LocationPropertyForm({str(serviceproperty.id) + '-value': value}, prefix = serviceproperty.id) else: f = GenericPropertyForm({str(serviceproperty.id) + '-value': value}, prefix = serviceproperty.id) form += "<p><label>" + serviceproperty.name + ":</label> " + unicode(f['value']) + "</p>" return render_to_response("groups-manage-edit-service", {'breadcrumb': self.breadcrumb, 'activetab': 'Groups', 'service': self.service, 'group':self.group, 'serviceproperties': serviceproperties, 'form': form})
def CreatePageContent(self): ''' Save Service model data and show form. ''' if self.request.method == 'POST': try: if not 'serviceid' in self.request.POST: raise MyPidgeException service = Service.objects.get(id=self.request.POST['serviceid']) gs = GroupService(group=self.group, service=service) gs.save() numsp = self.request.POST['numberserviceprops'] flags['no_property'] = True # Do for each property for indx in range(0, int(numsp)): try: if not (self.request.POST['prop' + str(indx)] and self.request.POST['value' + str(indx)]): raise MyPidgeException propid = int(self.request.POST['prop' + str(indx)]) sp = ServiceProperty.objects.get(id=propid) gsp = GroupServiceProperty(serviceproperty=sp, groupservice=gs, value=self.request.POST['value'+str(indx)]) gsp.save() # We've set at least one property value flags['no_property'] = False except (ServiceProperty.DoesNotExist, MyPidgeException): pass if flags['no_property']: # If we've not set any properties, then we must be deleting gs.delete() else: flags['added_service'] = True except (Service.DoesNotExist, MyPidgeException): pass gsps = GroupServiceProperty.objects.filter(groupservice__group=self.group, groupservice__active=True).order_by('groupservice') services = Service.objects.filter(all_can_create=True) return render_to_response("groups-manage-edit-services", {'breadcrumb': self.breadcrumb, 'activetab':'Groups', 'groupserviceproperties': gsps, 'services': services, 'flags': self.flags, 'group': self.group})