예제 #1
0
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)
예제 #2
0
 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()
예제 #3
0
 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()
예제 #4
0
 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()
예제 #5
0
 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()
예제 #6
0
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)
예제 #7
0
 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,
     )
예제 #8
0
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)
예제 #9
0
 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,
     )
예제 #10
0
 def location_form(self):
     if self.request.method == 'POST':
         return LocationForm(self.location, self.request.POST)
     return LocationForm(self.location)
예제 #11
0
 def _move_location(self, location, new_parent_id):
     form = LocationForm(
         location,
         bound_data={'name': location.name, 'parent_id': new_parent_id}
     )
     form.save()