Update Machine to be tied to a User, not a string
This commit is contained in:
1 parent
2917b90784
commit
b295842066
5 files changed
+14
-15
No files matched your search
+2
-2
@@ -50,7 +50,7 @@ class Profile(Model):
|
||||
|
||||
class Machine(Model):
|
||||
|
||||
owner = CharField(max_length=64)
|
||||
user = ForeignKey(User, PROTECT, related_name='owner')
|
||||
osname = CharField(max_length=128)
|
||||
threads = IntegerField(default=0)
|
||||
mnps = FloatField(default=0.00)
|
||||
@@ -58,7 +58,7 @@ class Machine(Model):
|
||||
workload = ForeignKey('Test', PROTECT, related_name='workload', default=1)
|
||||
|
||||
def __str__(self):
|
||||
return '{0}-{1} ({2})'.format(self.owner, self.osname, self.id)
|
||||
return '{0}-{1} ({2})'.format(self.user.username, self.osname, self.id)
|
||||
|
||||
class Result(Model):
|
||||
|
||||
|
||||
+5
-6
@@ -75,7 +75,7 @@ def getMachineStatus(username=None):
|
||||
machines = getRecentMachines()
|
||||
|
||||
if username != None:
|
||||
machines = machines.filter(owner=username)
|
||||
machines = machines.filter(user__username=username)
|
||||
|
||||
return "{0} Machines ".format(len(machines)) + \
|
||||
"{0} Threads ".format(sum([f.threads for f in machines])) + \
|
||||
@@ -251,7 +251,7 @@ def createNewTest(request):
|
||||
return test, None
|
||||
|
||||
|
||||
def getMachine(machineid, owner, osname, threads):
|
||||
def getMachine(machineid, user, osname, threads):
|
||||
|
||||
try: # Create a new or fetch an existing Machine
|
||||
if machineid == 'None': machine = Machine()
|
||||
@@ -260,11 +260,11 @@ def getMachine(machineid, owner, osname, threads):
|
||||
|
||||
# Verify that the fetched Machine matches
|
||||
if machineid != 'None':
|
||||
if machine.owner != owner: return 'Bad Machine'
|
||||
if machine.user != user: return 'Bad Machine'
|
||||
if machine.osname != osname: return 'Bad Machine'
|
||||
|
||||
# Update the Machine's running status
|
||||
machine.owner = owner ; machine.osname = osname
|
||||
machine.user = user ; machine.osname = osname
|
||||
machine.threads = int(threads) ; machine.mnps = 0.00
|
||||
return machine
|
||||
|
||||
@@ -282,12 +282,11 @@ def getWorkload(user, request):
|
||||
|
||||
# Extract worker information
|
||||
machineid = request.POST['machineid']
|
||||
owner = request.POST['username' ]
|
||||
osname = request.POST['osname' ]
|
||||
threads = request.POST['threads' ]
|
||||
|
||||
# If we don't get a Machine back, there was an error
|
||||
machine = getMachine(machineid, owner, osname, threads)
|
||||
machine = getMachine(machineid, user, osname, threads)
|
||||
if type(machine) == str: return machine
|
||||
machine.save()
|
||||
|
||||
|
||||
+4
-4
@@ -491,7 +491,7 @@ def clientWrongBench(request):
|
||||
|
||||
# Verify the Machine belongs to the User
|
||||
machine = Machine.objects.get(id=int(request.POST['machineid']))
|
||||
if machine.owner != user.username: return HttpResponse('Bad Machine')
|
||||
if machine.user != user: return HttpResponse('Bad Machine')
|
||||
|
||||
# Find and stop the test with the bad bench
|
||||
test = Test.objects.get(id=int(request.POST['testid']))
|
||||
@@ -533,7 +533,7 @@ def clientSubmitNPS(request):
|
||||
|
||||
# Verify the Machine belongs to the User
|
||||
machine = Machine.objects.get(id=int(request.POST['machineid']))
|
||||
if machine.owner != user.username: return HttpResponse('Bad Machine')
|
||||
if machine.user != user: return HttpResponse('Bad Machine')
|
||||
|
||||
# Update the NPS and return 'None' to signal no errors
|
||||
machine.mnps = float(request.POST['nps']) / 1e6; machine.save()
|
||||
@@ -559,7 +559,7 @@ def clientSubmitError(request):
|
||||
|
||||
# Verify the Machine belongs to the User
|
||||
machine = Machine.objects.get(id=int(request.POST['machineid']))
|
||||
if machine.owner != user.username: return HttpResponse('Bad Machine')
|
||||
if machine.user != user: return HttpResponse('Bad Machine')
|
||||
|
||||
# Log the Error into the Events table
|
||||
LogEvent.objects.create(
|
||||
@@ -581,7 +581,7 @@ def clientSubmitResults(request):
|
||||
|
||||
# Verify the Machine belongs to the User
|
||||
machine = Machine.objects.get(id=int(request.POST['machineid']))
|
||||
if machine.owner != user.username: return HttpResponse('Bad Machine')
|
||||
if machine.user != user: return HttpResponse('Bad Machine')
|
||||
|
||||
# updateTest() will return 'None' or 'Stop'
|
||||
return HttpResponse(OpenBench.utils.updateTest(request, user))
|
||||
@@ -19,8 +19,8 @@
|
||||
{% for machine in machines %}
|
||||
<tr>
|
||||
<td class="numeric">{{machine.id}}</td>
|
||||
<td>{{machine.owner}}</td>
|
||||
<td>{{machine.osname}}</td>
|
||||
<td>{{machine.user.username}}</td>
|
||||
<td>{{machine.osname|truncatewords:1|slice:":-4"}}</td>
|
||||
<td>{{machine.updated|date:'Y-m-d H:i'}}</td>
|
||||
<td> <a href="/test/{{machine.workload.id}}">{{machine.workload.dev.name|prettyName}}</a></td>
|
||||
<td class="numeric">{{machine.threads}}</td>
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
{% for result in results %}
|
||||
<tr>
|
||||
<td>{{result.machine.id}}</td>
|
||||
<td>{{result.machine.owner|slice:"6"}}</td>
|
||||
<td>{{result.machine.user.username|slice:"6"}}</td>
|
||||
<td>{{result.machine.osname|truncatewords:1|slice:":-4"}}</td>
|
||||
<td>{{result.updated|date:'Y-m-d H:i'}}</td>
|
||||
<td class="numeric">{{result.games}}</td>
|
||||
|
||||
Reference in new issue
Block a user