Пример #1
0
def order(request):
    """
        Order items

        :param POST['items']: the item id's of ordered items (list in string format)
        :param POST['table']: the table number where customer sits
    """
    #if request.user.is_authenticated():
    u = request.user
    #u = User.objects.get(id=2)
    tc = TableCode.objects.filter(code=request.POST['table']).latest('date')
    o = Order(user=u, table=tc)    
    o.save()
    #logger.debug("posted items %s"%request.POST['items'])

    for i in eval(request.POST['items']):
        m = MenuItem.objects.get(id=i)
        r = MenuItemReview(item=m, rating=0, comment="Please let us know how you liked this dish.")
        r.save()
        o.items.add(r)
    o.save()
    o.last_update()

    return JSONHttpResponse({'result':'1'})
Пример #2
0
from legals.models import Order, MenuItem, MenuItemReview, TableCode, Experiment
from django.contrib.auth.models import User
import datetime

e = Experiment.objects.get(id=1)
t = TableCode(code='abcd', experiment = e, date=datetime.date.today())
t.save()

t = TableCode.objects.filter(code='abcd')[0]

michael = User.objects.get(id=2)
o = Order(user=michael, table=t)
o.save()

# these items have a price that is not fixed
for i in [59,52]:
    m = MenuItem.objects.get(id=i)
    r = MenuItemReview(item=m, rating=5, comment="This was soo delicious")
    r.save()
    o.items.add(r)
o.save()

o = Order(user=michael, table=t)
o.save()

for i in [25,15,45]:
    m = MenuItem.objects.get(id=i)
    r = MenuItemReview(item=m, rating=5, comment="This was soo delicious")
    r.save()
    o.items.add(r)
o.save()
Пример #3
0
def login_mobile(request):
    """
        POST method that is used to login

        :url: /legals/m/login/

        :param POST['lat']: latitude
        :param POST['lon']: longitude 
        :param POST['udid']: udid
        :param POST['email']: email address
        :param POST['pin']: pin number
        :param POST['table']: table code
    """

    # needed to load header icon 
    header = "legals"
    restaurant = Store.objects.get(id=1)

    if request.method == "POST":
        email = request.POST['email']
        pin = hashlib.sha224(request.POST['pin']).hexdigest()
        user = authenticate(email=email, pin=pin)
        lat = float(request.POST.get('lat',"0.0"))
        lon = float(request.POST.get('lon',"0.0"))
    
        if user is not None:
            # valid user
            login(request, user)
            logger.debug( "User %s authenticated and logged in with table code: %s "%(email, request.POST['table']) )

            # check table code
            table = TableCode.objects.check_code(request.POST['table'])
            if table is None:
                # if table code is not usable
                logger.debug( "Table code is not valid: %s"%request.POST['table'] )
                event = EventBasic(user=user, 
                                experiment=user.experiment,
                                action=EventBasic.LOGIN_OUTSIDE, 
                                latitude=lat,
                                longitude=lon,
                                comment="Invalid table code: %s"%request.POST.get('table','no table code entered'))
                event.save()
                #just display plain menu
                #return HttpResponseRedirect("/legals/m/categories/0/")
                return render_to_response( "legals/i/login.html",
                    {
                        'header': header,
                        'error': 'Table Code is Invalid',
                        'restaurant': restaurant,
                        'lat': lat,
                        'lon': lon,
                        'email': email,
                        'pin': request.POST.get("pin",""),
                    },
                    context_instance=RequestContext(request))

            ################################
            # You are logged in successfully
            ################################
            logger.debug( "Using table code %s"%table.code )
            # Create an Order
            order = Order(user=user, table=table)
            order.save()
            event = EventBasic(user=user, 
                            order=order,
                            experiment=table.experiment,
                            table_code=table,
                            action=EventBasic.LOGIN_VALID, 
                            latitude=lat,
                            longitude=lon)
            event.save()
            # register iphone
            if 'udid' in request.POST:
                p, created = iPhone.objects.get_or_create(user=user)
                p.udid = request.POST['udid']
                p.save()
 
            return HttpResponseRedirect("/legals/m/categories/%d/"%order.id)
        else:
            # not a valid user
            event = EventAccess(udid=request.POST['udid'], 
                            bad=True, 
                            latitude=lat,
                            longitude=lon)
            event.save()
            return render_to_response( "legals/i/login.html",
                {
                    'header': header,
                    'error': 'Email or PIN did not validate',
                    'restaurant': restaurant,
                    'lat': lat,
                    'lon': lon,
                    'email': email,
                    'tablecode': request.POST.get('table', "")
                },
                context_instance=RequestContext(request))
    else:
        # not a valid URL
        return render_to_response("legals/i/login.html",
                {
                    'header': header,
                    'error': 'Invalid URL',
                    'restaurant': restaurant,
                    'lat': '',
                    'lon': '',
                    'email': email,
                    'pin': request.POST.get("pin", ""),
                    'tablecode': request.POST.get('table', ""),
                },
                context_instance=RequestContext(request))