Exemplo n.º 1
0
def smoke(request):
    """User smokes"""
    # check if packs are in parameters to fill fields with actual packs
    packs = Paquet.objects.filter(user=request.user, display=True)
    context = {'packs': packs}
    tz_offset = get_client_offset(request)
    update_dt_user_model_field(request.user, tz_offset)

    if packs:
        smoke_form = SmokeForm(request.user, tz_offset)
        if request.method == 'POST':
            smoke_form = SmokeForm(request.user, tz_offset, request.POST)
            if smoke_form.is_valid():
                smoky = SmokeManager(request.user, smoke_form.cleaned_data,
                                     tz_offset)
                smoky.create_conso_cig()
                return redirect('QuitSoonApp:today')
        context['smoke_form'] = smoke_form

    smoke_conso = ConsoCig.objects.filter(
        user=request.user).order_by('-datetime_cig')
    context['smoke'] = smoke_conso
    context['nb_smoke_today'] = smoke_conso.filter(
        datetime_cig__date=timezone.now().date()).count()
    if smoke_conso:
        last = smoke_conso.latest('datetime_cig').datetime_cig
        context['lastsmoke'] = get_delta_last_event(last)
    return render(request, 'QuitSoonApp/smoke.html', context)
Exemplo n.º 2
0
 def test_get_conso_cig_new_conso(self):
     """test SmokeManager.conso_cig method after creation object with new conso data"""
     smoke = SmokeManager(self.usertest, self.new_datas_ind)
     smoke.create_conso_cig()
     self.assertEqual(
         smoke.get_conso_cig,
         ConsoCig.objects.get(
             user=self.usertest,
             datetime_cig=smoke.datetime_cig,
             paquet=smoke.get_pack,
             given=smoke.given,
         ))
Exemplo n.º 3
0
 def test_create_conso_cig(self):
     """test SmokeManager.create_conso_cig method with new conso data"""
     smoke = SmokeManager(self.usertest, self.new_datas_ind)
     smoke.create_conso_cig()
     new_smoke = ConsoCig.objects.filter(user=self.usertest,
                                         datetime_cig=datetime.datetime(
                                             2020,
                                             5,
                                             17,
                                             13,
                                             15,
                                             tzinfo=pytz.utc),
                                         paquet=self.db_pack_ind,
                                         given=False)
     self.assertTrue(new_smoke.exists())
     self.assertEqual(smoke.get_pack.id, self.db_pack_ind.id)
Exemplo n.º 4
0
 def test_create_conso_cig_given(self):
     """ test SmokeManager.create_conso_cig method with given=True """
     new_datas_given_cig = {
         'date_smoke': datetime.date(2020, 7, 15),
         'time_smoke': datetime.time(20, 15),
         'ind_pack_field': self.db_pack_ind.id,
         'rol_pack_field': self.db_pack_rol.id,
         'given_field': True,
     }
     smoke = SmokeManager(self.usertest, new_datas_given_cig)
     smoke.create_conso_cig()
     self.assertEqual(smoke.get_pack, None)
     new_given_smoke = ConsoCig.objects.filter(
         user=self.usertest,
         datetime_cig=datetime.datetime(2020,
                                        7,
                                        15,
                                        20,
                                        15,
                                        tzinfo=pytz.utc),
         paquet=None,
         given=True)
     self.assertTrue(new_given_smoke.exists())
Exemplo n.º 5
0
 def test_create_conso_cig_datas_id_smoke(self):
     """test SmokeManager.create_conso_cig method with id_smoke in request"""
     smoke = SmokeManager(self.usertest, self.old_smoke_ind_data)
     self.assertEqual(smoke.create_conso_cig(), None)