Пример #1
0
    def save_game(self, place_id, percentaje):
        try:

            data = []
            profile = Profile.objects.get(user=self.request.user)
            place = Place.objects.get(pk=place_id)
            history_plays = HistoryPlay.objects.get(
                profile=profile,
                place=place
            )
            if percentaje == 100:
                history_plays.status = HistoryPlay.STATUS_COMPLETE
                history_plays.progress = 100
                step = int(history_plays.place.step)
                step = step +1
                place = Place.objects.get(step=step)
                next_play = HistoryPlay()
                next_play.profile = profile
                next_play.place = place
                next_play.progress = 0
                next_play.save()
            if history_plays.progress < percentaje:
                history_plays.progress = percentaje
            history_plays.save()

            data.append({
                'response':'OK',
            })
        except:
            data.append({
                'response':'ERROR',
            })
        return data
Пример #2
0
 def create_default_data(self, profile):
     try:
         place = Place.objects.get(step=1)
         history_play = HistoryPlay()
         history_play.place = place
         history_play.profile = profile
         history_play.progress = 0
         history_play.save()
     except:
         print('no default data')