示例#1
0
文件: edit.py 项目: mickek/Dieter.pl
def perform_action(request, diet_id, sequence_no):
    """
    Bulk action handler for diet editing, handlers for save and send diet
    """

    day = get_object_or_404(DayPlan, sequence_no = sequence_no, diet__id = diet_id)
    if request.method == 'POST': 
        
        if 'save_day' or 'save_diet' in request.POST:
            sequence_no = int(sequence_no)+1
            
            meals = zip( request.POST.getlist('meal_type'), request.POST.getlist('meal_name'), request.POST.getlist('meal_quantity') )

            for meal in day.meal_set.all(): meal.delete()
            for i, row in enumerate(meals):

                meal_type, meal_name, meal_quantity = row
                quantity, unit_type = parse_quantity(meal_quantity)
                
                if meal_name != '' and meal_type in ['breakfest','brunch','lunch','dinner']:
                    day.meal_set.create( type=meal_type, name=meal_name, quantity=quantity, unit_type = unit_type, sequence_no=i )
                
            day.save()
            
        if 'save_day' in request.POST:
            request.user.message_set.create(message="Zapisano dzień")
            
        if 'save_diet' in request.POST:
            request.user.message_set.create(message="Zapisano dietę")
            return redirect(reverse('patients_list'))
            
        if 'send_diet' in request.POST:
            return redirect(reverse('diet_send_form',kwargs={'diet_id':diet_id}))
            
    return redirect(reverse('edit_diet',kwargs={'diet_id':diet_id, 'day': sequence_no}))
示例#2
0
文件: tests.py 项目: mickek/Dieter.pl
 def test_none(self):
     q, t = parse_quantity("")
     self.assertEquals(q,None)
     self.assertEquals(t,None)
     
     
     
示例#3
0
文件: tests.py 项目: mickek/Dieter.pl
 def test_whitespace(self):
     
     q, t = parse_quantity("1 szklanka")
     self.assertEquals(q,1)
     self.assertEquals(t,"szklanka")
     
     q, t = parse_quantity("2 szklanki")
     self.assertEquals(q,2)
     self.assertEquals(t,"szklanki")
     
     q, t = parse_quantity("2 kromka")
     self.assertEquals(q,2)
     self.assertEquals(t,"kromka")        
     
     q, t = parse_quantity("2 kromki")
     self.assertEquals(q,2)
     self.assertEquals(t,"kromki") 
示例#4
0
文件: tests.py 项目: mickek/Dieter.pl
 def test_polish_letters(self):
     q, t = parse_quantity("5 plasterków")
     self.assertEquals(q,5)
     self.assertEquals(t,"plasterków")
示例#5
0
文件: tests.py 项目: mickek/Dieter.pl
 def test_invalid(self):
     
     q, t = parse_quantity("xyz")
     self.assertEquals(q,None)
     self.assertEquals(t,None)
示例#6
0
文件: tests.py 项目: mickek/Dieter.pl
 def test_floats(self):
     
     q, t = parse_quantity("100.0 g")
     self.assertEquals(q,100)
     self.assertEquals(t,'g')
示例#7
0
文件: tests.py 项目: mickek/Dieter.pl
 def test_just_numbers(self):
     
     q, t = parse_quantity("100")
     self.assertEquals(q,100)
     self.assertEquals(t,None)
示例#8
0
文件: tests.py 项目: mickek/Dieter.pl
 def test_no_whitespace(self):
     
     q, t = parse_quantity("100g")
     self.assertEquals(q,100)
     self.assertEquals(t,"g")