Beispiel #1
0
def add_host_to_contract(request, host_id, contract_id):
    dajax = Dajax()
    host = Host.objects.get(id=host_id)
    contract = Contract.objects.get(id=contract_id)
    contract.hosts.add(host)
    contract.save()
    msg = ""
    div_id = "#img_host_%s" % host_id
    dajax.assign(div_id, 'innerHTML', msg)
    div_id = "#host_%s" % host_id
    dajax.assign(div_id, 'innerHTML', msg)
    return dajax.json()
Beispiel #2
0
def display_valid_contracts(request, host_id):
    dajax = Dajax()
    valid_contracts = Contract.objects.filter(start_date__lte=datetime.today(),
                                              end_date__gte=datetime.today())
    msg = "<strong>Valid contracts :</strong><table>"
    print str(valid_contracts)
    for contract in valid_contracts:
        msg += "<tr class='hosts_expand'><td>%s</td><td>" % contract
        msg += "<span onclick=\"Dajaxice.banquise.web.add_host_to_contract('Dajax.process',{'host_id':%s,'contract_id':%s});\">" % (
            host_id, contract.id)
        msg += "<img src='/media/images/icons/ok.png' height='16' border='0'></span></td></tr>"
    msg += "</table>"
    div_id = "#host_%s" % host_id
    dajax.assign(div_id, 'innerHTML', msg)
    return dajax.json()
Beispiel #3
0
def tag(request, tag, method):
    try:
        ex = Exercise.objects.get(pk=request.session["current_exercise"])
    except Exercise.DoesNotExist:
        print "ERROR -- Exercise not found in ajax.py"
        print "DEBUG {}".format(request.session["current_exercise"])
    if method == "ADD":
        ex.tags.add(tag)
    elif method == "REMOVE":
        ex.tags.remove(tag)
    else:
        print "ERROR -- Unknown method: %s" % method
    dajax = Dajax()
    dajax.assign("#result", "value", "Data saved")
    return dajax.json()
Beispiel #4
0
def exedit(request, key, val):
    # fix key to match the attribute
    key = key.replace("id_", "")
    try:
        ex = Exercise.objects.get(pk=request.session["current_exercise"])
    except Exercise.DoesNotExist:
        print "ERROR -- Exercise not found in ajax.py"
        print "DEBUG {}".format(request.session["current_exercise"])
    setattr(ex, key, val)
    print "SET: {} - {}".format(key, val)
    ex.last_updated = datetime.datetime.now
    ex.save()
    dajax = Dajax()
    dajax.assign("#result", "value", "Data saved")
    return dajax.json()