Esempio n. 1
0
def allergies(request, order_id):
    """
        Display allergy information
       
        :url: /legals/m/allergies/{{ order_id }}/
    """
    header = "legals"
    restaurant = Store.objects.get(id=1)

    if int(order_id) == 0:
        exp_id = 1
        event=EventSpecial(user=request.user,
                    experiment=Experiment.objects.get(id=exp_id),
                    category=EventSpecial.ALLERGIES)  
    else:
        ord = Order.objects.get(id=order_id)

        event=EventSpecial(user=request.user,
                    order=ord,
                    experiment=ord.table.experiment,
                    category=EventSpecial.ALLERGIES)  
    event.save()

    return render_to_response( "legals/i/allergies.html",
        {
            'header': header,
            'restaurant': restaurant,
            'order_id': int(order_id)
        },
        context_instance=RequestContext(request))
Esempio n. 2
0
def view_chefs_choices(request, order_id):
    """
        Display the Chef's choices

        :url: /legals/m/chef/choices/(?P<order_id>\d+)/
    """
    menu_data = [] 
    header = "legals"
    restaurant = Store.objects.get(id=1)

    if int(order_id) == 0:
        exp_id = 1
        event=EventSpecial(user=request.user,
                    experiment=Experiment.objects.get(id=exp_id),
                    category=EventSpecial.CHEFS)  
    else:
        ord = Order.objects.get(id=order_id)
        exp_id = ord.table.experiment.id 
        event=EventSpecial(user=request.user,
                    order=Order.objects.get(id=order_id),
                    experiment=Experiment.objects.get(id=exp_id),
                    category=EventSpecial.CHEFS)  
    event.save()

    choices = ChefChoice.objects.filter(item__active=True)
    for c in choices:
        i_data = {}
        i_data['item'] = c.item.get_json()

        menu_data.append(i_data)

    return render_to_response( "legals/i/chefchoices.html",
            {
            'header': header,
            'restaurant': restaurant,
            'menu_data': menu_data,
            'order_id': int(order_id)
            },
            context_instance=RequestContext(request))
Esempio n. 3
0
def view_friends_choices(request, order_id):
    """
        Display friend's choices

        :url: /legals/m/friend/choices/(?P<order_id>\d+)/

        :rtype: JSON
        ::

            [
                {
                    'item': item.get_json(),
                    'friends': 'Calvin, Ilya,...',
                    'anonymous': '15 people ordered',
                },
                {
                    'item': item.get_json(),
                    'friends': 'Calvin, Ilya,...',
                    'anonymous': '15 people ordered',
                }

            ]

            
    """

    u = request.user

    if int(order_id) == 0:
        exp_id = 1
        event=EventSpecial(user=u,
                    experiment=Experiment.objects.get(id=exp_id),
                    category=EventSpecial.FRIENDS)  
    else:
        ord = Order.objects.get(id=order_id)
        exp_id = ord.table.experiment.id 
        event=EventSpecial(user=u,
                    order=Order.objects.get(id=order_id),
                    experiment=Experiment.objects.get(id=exp_id),
                    category=EventSpecial.FRIENDS)  
    event.save()

    header = "legals"
    restaurant = Store.objects.get(id=1)
    category = {'name':"Friend's Choices",
                'description': "What your friend's have tried",
                'id': "friends" }

    # get friends of user
    fb_id = u.facebook_profile.facebook_id
    friends = Friends.objects.get(facebook_id=fb_id).friends.values_list('facebook_id', flat=True)
    
    # get those items that friends have ordered
    i_data={}
    orders = Order.objects.filter(user__facebook_profile__facebook_id__in=friends)
    for o in orders:
        if o.num_items() > 0:
            for r in o.items.all():
                if exp_id == 1:
                    if r.item.id not in i_data:
                        i_data[r.item.id] = {'item':r.item.get_json()}
                elif exp_id in [2,4,5]:
                    # 2: friends
                    # 4: friends anonymous 
                    # 5: intervention

                    if r.item.id not in i_data:
                        anonymous_label = ''
                        numordered = r.item.menuitemreview_set.count()
                        if numordered == 1: 
                            anonymous_label = '1 person ordered'
                        elif numordered > 1:
                            anonymous_label = '%d people ordered'%numordered

                        i_data[r.item.id] = {'item':r.item.get_json(), 'friends':set(), 
                                                'anonymous':anonymous_label}
                        i_data[r.item.id]['friends'].add(o.user.first_name)
                    else:
                        # friends that ordered the item
                        i_data[r.item.id]['friends'].add(o.user.first_name)
                elif exp_id == 3:
                    # popularity 
                    if r.item.id not in i_data:
                        anonymous_label = ''

                        numordered = r.item.menuitemreview_set.all().exclude(legals_ordered__user=u).count()
                        if numordered == 1: 
                            anonymous_label = '1 person ordered'
                        elif numordered > 1:
                            anonymous_label = '%d people ordered'%numordered

                        i_data[r.item.id] = {'item':r.item.get_json(), 'friends':set(), 
                                                'anonymous':anonymous_label}

    if exp_id in [2,4,5]:
        for key,val in i_data.items(): 
            # arrange labels
            numfriends = len(val['friends'])
            i = 0
            label = ''
            for f in val['friends']: 
                i += 1 
                if i == 3 and numfriends > 3:
                    label += f + ', ...'
                    # if there are more than three people, just show
                    # that there are more
                    break
                elif i == numfriends:
                    label += f 
                else:
                    label += f + ', '

            i_data[key]['friend_label']=label 

    return render_to_response( "legals/i/category.html",
            {
            'header': header,
            'restaurant': restaurant,
            'category': category,
            'menu_data': i_data,
            'exp_id': int(exp_id),
            'friend_experiment':[2,4,5],
            'order_id': int(order_id)
            },
            context_instance=RequestContext(request))