Beispiel #1
0
def test_create_game(request):
    response = '<html><h3>Creating Sample Data:</h3><p>Player</p><p>Sport</><p>Field</p><p>Game</p>'
    p = Player(name='Sean', password='******')
    p.save()
    s = Sport(name='BasketBall')
    s.save()
    f = Field(name = 'wilson')
    f.save()
    g = Games(creator=p, location=f, when_created = datetime.now(), start_time = datetime.now(), end_time=datetime.now(), private=True, visible=False, sport_type=s)
    g.save()
    response = response + '<p><b>Successful</b></p><h3>Created</h3>'
    response = response + '<p>'+str(p)+'</p>'+'<p>'+str(s)+'</p>'    
    response = response + '<p>'+str(f)+'</p><p>'+str(g)+'</p>'
    return HttpResponse(response, content_type="text/html")
Beispiel #2
0
def create_game(request):
    body = json.loads(request.body)
    time = body['Time']
    time = datetime.datetime.strptime(time, "%A, %B %d, %Y at %I:%M:%S %p")
    time = time + datetime.timedelta(hours=-5)
    end_time = time + datetime.timedelta(hours=1)
    field = body['Location']
    private = body['Private']
    sport = body['Sport']
    creator = body['Username']
    creator_obj = Player.objects.filter(name=creator)[0]
    priv = False
    if private == "True":
      priv = True
    g = Games(creator=creator_obj, location=field, when_created = datetime.datetime.now(), start_time = time, end_time=end_time, private=priv, visible=False, sport_type=sport)
    g.save()
    g.members.add(creator_obj)
    return HttpResponse("Success", content_type="text/plain")