Commit 1a1e0835 by Joosep L

final

parent 40ce2c02
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-22 15:29
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0004_auto_20170519_1156'),
]
operations = [
migrations.RemoveField(
model_name='conversation',
name='created_by',
),
migrations.RemoveField(
model_name='conversation',
name='user_game',
),
migrations.RemoveField(
model_name='message',
name='conversation',
),
migrations.RemoveField(
model_name='usergame',
name='user_role',
),
migrations.AddField(
model_name='message',
name='user_game',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='api.UserGame'),
preserve_default=False,
),
migrations.AlterField(
model_name='game',
name='location_name',
field=models.CharField(blank=True, max_length=200, null=True),
),
migrations.DeleteModel(
name='Conversation',
),
migrations.DeleteModel(
name='UserRole',
),
]
...@@ -31,7 +31,7 @@ class Game(models.Model): ...@@ -31,7 +31,7 @@ class Game(models.Model):
start_time = models.DateTimeField(blank=True, null=True) start_time = models.DateTimeField(blank=True, null=True)
max_duration = models.IntegerField(blank=True, null=True) max_duration = models.IntegerField(blank=True, null=True)
end_time = models.DateTimeField(blank=True, null=True) end_time = models.DateTimeField(blank=True, null=True)
location_name = models.CharField(max_length=200, unique=True, blank=True, null=True) location_name = models.CharField(max_length=200, blank=True, null=True)
created_at = models.DateTimeField(default=datetime.now) created_at = models.DateTimeField(default=datetime.now)
def __str__(self): def __str__(self):
...@@ -158,4 +158,4 @@ class Bounds(models.Model): ...@@ -158,4 +158,4 @@ class Bounds(models.Model):
game = models.ForeignKey(Game, on_delete=models.CASCADE) game = models.ForeignKey(Game, on_delete=models.CASCADE)
notification_text = models.CharField(max_length=200) notification_text = models.CharField(max_length=200)
mpoly = geomodels.MultiPolygonField() mpoly = geomodels.MultiPolygonField()
created_at = models.DateTimeField(default=datetime.now) created_at = models.DateTimeField(default=datetime.now)
\ No newline at end of file
...@@ -73,3 +73,9 @@ class BoundSerializer(serializers.ModelSerializer): ...@@ -73,3 +73,9 @@ class BoundSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Bounds model = Bounds
fields = ('id', 'notification_text') fields = ('id', 'notification_text')
class CheckInSerializer(serializers.ModelSerializer):
class Meta:
model = CheckIn
fields = ('id', 'lat', 'lon', 'created_at', 'current_point')
...@@ -18,5 +18,7 @@ urlpatterns = [ ...@@ -18,5 +18,7 @@ urlpatterns = [
url(r'game/checkin', views.PostCheckIn), url(r'game/checkin', views.PostCheckIn),
url(r'game/addanswer', views.PostAnswer), url(r'game/addanswer', views.PostAnswer),
url(r'game/message', views.PostMessage), url(r'game/message', views.PostMessage),
url(r'game/stats', views.GetCheckIns),
] ]
...@@ -61,6 +61,22 @@ def StartGame(request): ...@@ -61,6 +61,22 @@ def StartGame(request):
return HttpResponse(status=400) return HttpResponse(status=400)
@api_view(['GET'])
def GetCheckIns(request):
try:
user_id = request.GET.get('user_id')
game_id = request.GET.get('game_id')
user_game = UserGame.objects.filter(user__id=user_id, game__id=game_id)
checkins = CheckIn.objects.filter(user_game=user_game[0])
json = []
for check in checkins:
serializer = CheckInSerializer(check)
json.append(serializer.data)
return JsonResponse(json, status=status.HTTP_200_OK, safe=False)
except:
return HttpResponse(status=400)
class GetUsersGames(generics.ListAPIView): class GetUsersGames(generics.ListAPIView):
queryset = UserGame.objects.all() queryset = UserGame.objects.all()
serializer_class = UserGameSerializer serializer_class = UserGameSerializer
......
...@@ -84,14 +84,13 @@ WSGI_APPLICATION = 'thesis.wsgi.application' ...@@ -84,14 +84,13 @@ WSGI_APPLICATION = 'thesis.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis', 'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'scavengerhunt', 'NAME': 'andmebaasinimi',
'USER': 'tipikas', 'USER': 'kasutajanimi',
'PASSWORD': 'Tipikas2017', 'PASSWORD': 'parool',
'HOST': '127.0.0.1', 'HOST': '127.0.0.1',
'PORT': '5432', 'PORT': '5432',
} }
} }
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment