@csrf_exempt
def user_system_view(request, template, data, instance=None):
    if request.method == 'POST':
        post_data = request.POST.copy()

        owner, c = models.Owner.objects.get_or_create(
            name=request.POST['owner_name'])

        post_data['owner'] = owner.id

        try:
            os, c = models.OperatingSystem.objects.get_or_create(
                    name=request.POST['js_os_name'],
                    version=request.POST['js_os_version'])
            post_data['operating_system'] = os.id
        except KeyError:
            pass

        try:
            server_model, c = models.ServerModel.objects.get_or_create(
                            vendor=request.POST['js_server_model_vendor'],
                            model=request.POST['js_server_model_model'])
            post_data['server_model'] = server_model.id
        except KeyError:
            pass

        if instance:
            old_owner = instance.owner
            old_serial = instance.serial
            old_asset_tag = instance.asset_tag
            old_notes = instance.notes
        else:
            old_owner = None
            old_serial = None
            old_asset_tag = None
            old_notes = None

        form = forms.UserSystemForm(post_data, instance=instance)
        if form.is_valid():
            saved_instance = form.save()
            if not instance or old_notes != saved_instance.notes:
                if old_notes:
                    models.History(
                        change="Notes changed from %s" % old_notes,
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                if saved_instance.notes:
                    models.History(
                        change="Notes changed to %s" % saved_instance.notes,
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                else:
                    models.History(
                        change="System has no Notes",
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
            if not instance or old_asset_tag != saved_instance.asset_tag:
                if old_asset_tag:
                    models.History(
                        change="Asset Tag changed from %s" % old_asset_tag,
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                if saved_instance.asset_tag:
                    models.History(
                        change="Asset Tag changed to %s" % saved_instance.asset_tag,
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                else:
                    models.History(
                        change="System has no Asset Tag",
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
            if not instance or old_serial != saved_instance.serial:
                if old_serial:
                    models.History(
                        change=old_serial % "Serial changed from %s",
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                if saved_instance.serial:
                    models.History(
                        change="Serial changed to %s" % saved_instance.serial,
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                else:
                    models.History(
                        change="System has no serial",
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
            if not instance or old_owner != saved_instance.owner:
                if old_owner:
                    models.History(
                        change="Owner changed from %s" % old_owner,
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                if saved_instance.owner:
                    models.History(
                        change="Owner changed to %s" % saved_instance.owner,
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
                else:
                    models.History(
                        change="System has no owner",
                        changed_by=get_changed_by(request),
                        system=saved_instance).save()
            return redirect('user-system-list')
    else:
        form = forms.UserSystemForm(instance=instance)

    data['form'] = form
    if settings.USE_LDAP:
        the_owner_list = ldap_lib.get_all_names()
    else:
        the_owner_list = []
    the_owner_list.append("STOCK")
    the_owner_list.append("STOCK-SFO")
    the_owner_list.append("STOCK-MTV")
    the_owner_list.append("STOCK-TOR")
    the_owner_list.append("STOCK-LON")
    the_owner_list.append("STOCK-PAR")
    the_owner_list.append("STOCK-PDX")
    the_owner_list.append("desktop-mtv1")
    the_owner_list.append("desktop-sfo1")
    the_owner_list.append("desktop-tor1")
    the_owner_list.append("desktop-lon1")
    the_owner_list.append("desktop-par1")
    the_owner_list.append("desktop-yvr1")
    the_owner_list.append("Release Engineering")
    data['owner_json'] = json.dumps(the_owner_list)

    #data['owner_json'] = json.dumps(ldap_lib.get_all_names())
    #data['owner_json'].append("Stock")

    return render_to_response(template, data, RequestContext(request))
dataset/ETHPy150Open mozilla/inventory/user_systems/views.py/user_system_view/swapped operands of `%`