def location_edit(request, domain, loc_id=None): parent_id = request.GET.get('parent') if loc_id: try: location = Location.get(loc_id) except ResourceNotFound: raise Http404 else: location = Location(domain=domain, parent=parent_id) if request.method == "POST": form = LocationForm(location, request.POST) if form.is_valid(): form.save() messages.success(request, 'Location saved!') return HttpResponseRedirect('%s?%s' % ( reverse('manage_locations', kwargs={'domain': domain}), urllib.urlencode({'selected': form.location._id}) )) else: form = LocationForm(location) context = { 'domain': domain, 'api_root': reverse('api_dispatch_list', kwargs={'domain': domain, 'resource_name': 'location', 'api_name': 'v0.3'}), 'location': location, 'form': form, } return render(request, 'locations/manage/location.html', context)
def _change_group(self, location, group): form = LocationForm(location.sql_location, bound_data={ 'name': location.name, 'data-field-group': group, 'location_type': location.location_type_object, 'parent_id': location.parent_location_id }) form.save()
def _move_location(self, location, new_parent_id): form = LocationForm(location.sql_location, bound_data={ 'name': location.name, 'parent_id': new_parent_id, 'location_type': location.location_type_object, 'data-field-group': location.metadata['group'] }) form.save()
def _change_group(self, location, group): form = LocationForm( location, bound_data={ 'name': location.name, 'data-field-group': group, 'location_type': location.location_type, 'parent_id': location.parent_id } ) form.save()
def _move_location(self, location, new_parent_id): form = LocationForm( location, bound_data={ 'name': location.name, 'parent_id': new_parent_id, 'location_type': location.location_type, 'data-field-group': location.metadata['group'] } ) form.save()
def location_edit(request, domain, loc_id=None): parent_id = request.GET.get('parent') if loc_id: try: location = Location.get(loc_id) except ResourceNotFound: raise Http404() else: location = Location(domain=domain, parent=parent_id) if request.method == "POST": form = LocationForm(location, request.POST) if form.is_valid(): form.save() messages.success(request, 'Location saved!') return HttpResponseRedirect('%s?%s' % ( reverse('manage_locations', kwargs={'domain': domain}), urllib.urlencode({'selected': form.location._id}) )) else: form = LocationForm(location) context = { 'domain': domain, 'api_root': reverse('api_dispatch_list', kwargs={'domain': domain, 'resource_name': 'location', 'api_name': 'v0.3'}), 'location': location, 'hierarchy': location_hierarchy_config(domain), 'form': form, } return render(request, 'locations/manage/location.html', context)
def make_new_location_form(self, name, parent, nikshay_code): return LocationForm( location=SQLLocation(domain=self.domain, parent=parent), bound_data={ 'name': name, 'data-field-nikshay_code': nikshay_code }, user=self.web_user, is_new=True, )
def make_form(domain, parent, data, existing=None): """simulate a POST payload from the location create/edit page""" location = existing or Location(domain=domain, parent=parent) def make_payload(k, v): if hasattr(k, '__iter__'): prefix, propname = k prefix = 'props_%s' % prefix else: prefix, propname = 'main', k return ('%s-%s' % (prefix, propname), v) payload = dict(make_payload(k, v) for k, v in data.iteritems()) return LocationForm(location, payload)
def make_edit_location_form(self, location, data): bound_data = { 'name': location.name, 'site_code': location.site_code, 'data-field-nikshay_code': location.metadata.get('nikshay_code'), 'coordinates': '', 'parent_id': '', 'external_id': '', 'location_type': location.location_type.code, } bound_data.update(data) return LocationForm( location=None, bound_data=bound_data, user=self.web_user, is_new=False, )
def location_form(self): if self.request.method == 'POST': return LocationForm(self.location, self.request.POST) return LocationForm(self.location)
def _move_location(self, location, new_parent_id): form = LocationForm( location, bound_data={'name': location.name, 'parent_id': new_parent_id} ) form.save()