@unique_session_or_json_redirect
def district_info(request, planid, district_id):
    """
    Get the comments that are attached to a district.

    Parameters:
        request -- An HttpRequest
        planid -- The plan ID
        district_id -- The district ID, this is the district number in a plan, and NOT the id of a district.
    """
    status = { 'success': False }
    plan = Plan.objects.filter(id=planid)
    if plan.count() == 0:
        status['message'] = _('No plan with that ID was found.')
    else:
        plan = plan[0]

        version = plan.version
        if 'version' in request.REQUEST:
            try:
                version = int(request.REQUEST['version'])
                version = min(plan.version, int(version))
            except:
                pass

        district_id = int(district_id)
        district = plan.get_districts_at_version(version, include_geom=False)
        district = filter(lambda d:d.district_id==district_id, district)

        if request.method == 'POST':
            district = plan.district_set.get(id=request.POST['object_pk'])
            district.short_label = request.POST['district_short'][0:10]
            district.long_label = request.POST['district_long'][0:256]


            if district.version < version:
                # The district version may lag behind the cursor 
                # version if there were no edits for a while. If this 
                # is the case the district must be copied to the 
                # currently edited version.
                district_copy = copy.copy(district)
                district_copy.id = None
                district_copy.version = version

                district_copy.save()

                # clone the characteristics, comments, and tags from 
                # the original district to the copy 
                district_copy.clone_relations_from(district)
                district = district_copy
            else:
                # save the changes to the district -- maybe name change
                district.save()

            has_comment = 'comment' in request.POST and request.POST['comment'] != '' 
            if has_comment:
                # Don't thread comments, keep only the latest and greatest
                ct = ContentType.objects.get(app_label='redistricting',model='district')
                Comment.objects.filter(object_pk = district.id, content_type=ct).delete()
                comment = Comment(
                    object_pk=district.id, 
                    content_type=ct, 
                    site_id=Site.objects.get_current().id, 
                    user_name=request.user.username, 
                    user_email=request.user.email, 
                    comment=request.POST['comment'])
                comment.save()
            else:
                # save this if the label changed
                district.save()

            # Get the tags on this object of this type.
            tset = Tag.objects.get_for_object(district).filter(name__startswith='type')

            # Purge the tags of this same type off the object
            TaggedItem.objects.filter(tag__in=tset, object_id=district.id).delete()

            purge_plan_clear_cache(district, version)

            if len(request.REQUEST.getlist('type[]')) > 0:
                strtags = request.REQUEST.getlist('type[]')
                for strtag in strtags:
                    if strtag == '':
                        continue
                    if strtag.count(' ') > 0:
                        strtag = strtag % '"type=%s"'
                    else:
                        strtag = 'type=%s' % strtag
                    Tag.objects.add_tag(district, strtag)

            status['version'] = version
            status['success'] = True

    return HttpResponse(json.dumps(status), mimetype='application/json')
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/views.py/district_info/swapped operands of `%`