Fix GpsCheckin
This commit is contained in:
@ -927,6 +927,9 @@ class GpsCheckin(models.Model):
|
|||||||
event_id = models.BigIntegerField(null=True, blank=True)
|
event_id = models.BigIntegerField(null=True, blank=True)
|
||||||
team_id = models.BigIntegerField(null=True, blank=True)
|
team_id = models.BigIntegerField(null=True, blank=True)
|
||||||
checkpoint_id = models.BigIntegerField(null=True, blank=True)
|
checkpoint_id = models.BigIntegerField(null=True, blank=True)
|
||||||
|
# データベースの実際のフィールドと一致させる
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'rog_gpscheckin'
|
db_table = 'rog_gpscheckin'
|
||||||
@ -935,14 +938,6 @@ class GpsCheckin(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"GPS Checkin {self.id} - {self.zekken}"
|
return f"GPS Checkin {self.id} - {self.zekken}"
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
# 作成時・更新時のタイムスタンプを自動設定
|
|
||||||
from django.utils import timezone
|
|
||||||
if not self.create_at:
|
|
||||||
self.create_at = timezone.now()
|
|
||||||
self.update_at = timezone.now()
|
|
||||||
super().save(*args, **kwargs)
|
|
||||||
|
|
||||||
class RogUser(models.Model):
|
class RogUser(models.Model):
|
||||||
user=models.OneToOneField(CustomUser, on_delete=models.CASCADE)
|
user=models.OneToOneField(CustomUser, on_delete=models.CASCADE)
|
||||||
phone=models.CharField(_('Phone Number'), max_length=55)
|
phone=models.CharField(_('Phone Number'), max_length=55)
|
||||||
|
|||||||
34
rog/views.py
34
rog/views.py
@ -2659,30 +2659,34 @@ def get_checkins(request, *args, **kwargs):
|
|||||||
logger.debug(f"=== event_code is required.")
|
logger.debug(f"=== event_code is required.")
|
||||||
return Response({"error": "event_code is required"}, status=400)
|
return Response({"error": "event_code is required"}, status=400)
|
||||||
|
|
||||||
|
logger.debug(f"=== Searching for zekken={zekken_number}, event_code={event_code}")
|
||||||
|
|
||||||
# チェックインデータの取得とCP情報の結合
|
# チェックインデータの取得とCP情報の結合
|
||||||
checkins = GpsCheckin.objects.filter(
|
checkins = GpsCheckin.objects.filter(
|
||||||
zekken=zekken_number,
|
zekken=zekken_number,
|
||||||
event_code=event_code
|
event_code=event_code
|
||||||
).order_by('serial_number')
|
).order_by('serial_number')
|
||||||
|
|
||||||
|
logger.debug(f"=== Found {checkins.count()} checkins")
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for c in checkins:
|
for c in checkins:
|
||||||
location = Location.objects.filter(cp=c.cp_number,group=event_code).first()
|
location = Location.objects.filter(cp=c.cp_number,group=event_code).first()
|
||||||
if location:
|
|
||||||
formatted_time = None
|
formatted_time = None
|
||||||
if c.create_at:
|
if c.checkin_time:
|
||||||
try:
|
try:
|
||||||
# create_atが文字列の場合はdatetimeに変換
|
# checkin_timeが文字列の場合はdatetimeに変換
|
||||||
if isinstance(c.create_at, str):
|
if isinstance(c.checkin_time, str):
|
||||||
c.create_at = datetime.strptime(c.create_at, '%Y-%m-%d %H:%M:%S')
|
c.checkin_time = datetime.strptime(c.checkin_time, '%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
# JST(+9時間)に変換して時刻フォーマット
|
# JST(+9時間)に変換して時刻フォーマット
|
||||||
jst_time = c.create_at + timedelta(hours=9)
|
jst_time = c.checkin_time + timedelta(hours=9)
|
||||||
formatted_time = jst_time.strftime('%H:%M:%S')
|
formatted_time = jst_time.strftime('%H:%M:%S')
|
||||||
|
|
||||||
except (ValueError, TypeError, AttributeError) as e:
|
except (ValueError, TypeError, AttributeError) as e:
|
||||||
logger.error(f"Error formatting create_at for checkin {c.id}: {str(e)}")
|
logger.error(f"Error formatting checkin_time for checkin {c.id}: {str(e)}")
|
||||||
logger.error(f"Raw create_at value: {c.create_at}")
|
logger.error(f"Raw checkin_time value: {c.checkin_time}")
|
||||||
formatted_time = None
|
formatted_time = None
|
||||||
|
|
||||||
data.append({
|
data.append({
|
||||||
@ -2691,16 +2695,16 @@ def get_checkins(request, *args, **kwargs):
|
|||||||
'cp_number': c.cp_number,
|
'cp_number': c.cp_number,
|
||||||
'sub_loc_id': location.sub_loc_id if location else f"#{c.cp_number}",
|
'sub_loc_id': location.sub_loc_id if location else f"#{c.cp_number}",
|
||||||
'location_name': location.location_name if location else None,
|
'location_name': location.location_name if location else None,
|
||||||
'create_at': formatted_time, #(c.create_at + timedelta(hours=9)).strftime('%H:%M:%S') if c.create_at else None,
|
'create_at': formatted_time, #(c.checkin_time + timedelta(hours=9)).strftime('%H:%M:%S') if c.checkin_time else None,
|
||||||
'validate_location': c.validate_location,
|
'validate_location': True, # デフォルト値として設定
|
||||||
'points': c.points or 0,
|
'points': location.checkin_point if location else 0, # locationから取得
|
||||||
'buy_flag': c.buy_flag,
|
'buy_flag': False, # デフォルト値として設定
|
||||||
'photos': location.photos if location else None,
|
'photos': location.photos if location else None,
|
||||||
'image_address': get_image_url(c.image_address),
|
'image_address': None, # 現在のモデルには存在しない
|
||||||
'receipt_address': get_image_url(c.image_receipt),
|
'receipt_address': None, # 現在のモデルには存在しない
|
||||||
'location_name': location.location_name if location else None,
|
'location_name': location.location_name if location else None,
|
||||||
'checkin_point': location.checkin_point if location else None,
|
'checkin_point': location.checkin_point if location else None,
|
||||||
'buy_point': location.buy_point
|
'buy_point': location.buy_point if location else 0
|
||||||
})
|
})
|
||||||
|
|
||||||
#logger.debug(f"data={data}")
|
#logger.debug(f"data={data}")
|
||||||
|
|||||||
Reference in New Issue
Block a user