示例#1
0
def view_orderconfirm(request,ordercofirm_template):
    order_information = []
    restaurant_alias = _request_param_post(request,'ralias')
    from restaurants.models import Restaurant
    restaurant = Restaurant.objects.get(alias=restaurant_alias)
    item_ids = _request_param_post(request,'item_ids').split(',')
    item_ids_quantity = _cleanquantity(item_ids)
    menu_items = []
    from restaurants.models import RestaurantMenuItem
    foodscost = 0
    vat_charges = 0
    for item_id in item_ids_quantity.keys():
        menuitem = RestaurantMenuItem.objects.get(id=item_id)
        foodscost+=item_ids_quantity[item_id]*menuitem.cost
        order_information.append({'menuitem':menuitem, 'quantity':item_ids_quantity[item_id],'netcost':item_ids_quantity[item_id]*menuitem.cost})
    vat_percentage = settings.VAT_PERCENTAGE
    vat_percentage_display = vat_percentage*100
    foodscost = foodscost.__float__()
    vat_charges = foodscost*vat_percentage
    service_charge = settings.RESTAURANTFOOD_SERVICE_CHARE
    total_bill = foodscost+vat_charges+service_charge
    from datetime import datetime,timedelta
    time_now = datetime.now()
    min_time = datetime(day=datetime.today().day, month=datetime.today().month, year=datetime.today().year, hour=settings.DELIVERY_TIMINGS_START_HOUR,minute=0,second=0)
    max_time = datetime(day=datetime.today().day, month=datetime.today().month, year=datetime.today().year, hour=settings.DELIVERY_TIMINGS_END_HOUR,minute=0,second=0)
    hours = [1,2,3,4,5,6,7,8,9,10,11,12,13]
    available_hours = []
    for hour in hours:
        if (time_now+timedelta(hours=hour)) <= max_time:
            available_hours.append(hour)
    if available_hours:
        food_deliverytime = time_now+timedelta(hours=available_hours[0])
    return response(ordercofirm_template,locals(),request)
示例#2
0
def view_makeorder(request):
    try:
        response_dict = {}
        totalbill = _request_param_post(request,'totalbill')
        ordered_items = _clean_ordered_items_ids_quantity(_request_param_post(request,'ordered_items_ids_quantity'))
        deliverytime = _clean_time(_request_param_post(request,'deliverytime'))
        userprofile = request.user.get_profile()
        from users.models import UserOrder
        order = UserOrder.objects.create_userorder(userprofile=userprofile, deliverytime=deliverytime, menuitems=ordered_items, totalcost=totalbill)
        response_dict['id'] = order.id
        response_dict['code'] = order.code
        response_dict['status'] = '200'
    except Exception,e:
        from utils.emailer import mail_admins
        mail_admins(e,locals())
        print 'Exception:%s' % e.__str__()
        response_dict['id'] = None
        response_dict['code'] = None
        response_dict['status'] = '500'
示例#3
0
def view_save_todaysfood(request):
    if request.method == 'POST':
        fooditem_name = _request_param_post(request,'today_food')
        from restaurants.models import FoodItem
        fooditem = FoodItem.objects.create_fooditem(name=fooditem_name)
        from users.models import UserHomeFood
        userfood = UserHomeFood.objects.create_userfood(userprofile=request.user.get_profile(),fooditem=fooditem)
        from django.template.defaultfilters import date
        from datetime import datetime
        return HttpResponse('<div id="food_%s_%s_%s">%s at %s</div>' % (fooditem.created_on.day,fooditem.created_on.month,fooditem.created_on.year,fooditem.name,date(fooditem.created_on,"f A jS N Y")))
示例#4
0
def _process_restfood_account_information(userprofile,request,account_template):
    password = _request_param_post(request, 'password')
    mobile = _request_param_post(request, 'mobile')
    office_place = _request_param_post(request, 'office_place')
    office_landmark = _request_param_post(request, 'office_landmark')
    office_area = _request_param_post(request, 'office_area')
    office_zip = _request_param_post(request, 'office_zip')
    from users.forms import AccountForm
    accountform = AccountForm({'mobile':mobile,'password':password,
                               'home_place':userprofile.source.place,'home_landmark':userprofile.source.landmark,'home_area':userprofile.source.area,'home_zip':userprofile.source.zip,
                               'office_place':office_place,'office_landmark':office_landmark,'office_area':office_area,'office_zip':office_zip})
    if not accountform.is_valid():
        _add_errormsg(request, 'Please valid information in all the required fields')
        return response(account_template,locals(),request)
    password = accountform.cleaned_data.get('password')
    print 'password:%s' % password
    userprofile.set_password(password)
    print 'password reset done'
    mobile = accountform.cleaned_data.get('mobile')
    userprofile.mobile = mobile
    userprofile.save()
    office_place = accountform.cleaned_data.get('office_place')
    office_landmark = accountform.cleaned_data.get('office_landmark')
    office_area = accountform.cleaned_data.get('office_area')
    office_zip = accountform.cleaned_data.get('office_zip')
    userprofile.set_destination_address(destination_place=office_place,destination_area=office_area,destination_landmark=office_landmark,destination_zip=office_zip)
    _add_successmsg(request, 'Account Information saved Successfully')
    return response(account_template,locals(),request)
示例#5
0
def view_register(request, homefood_registration_template, restaurantfood_registration_template, messfood_registration_template):
    if request.method != 'POST':
        return HttpResponseRedirect('/')
    service_type = _request_param_post(request, 'service_type')
    if not service_type:
        return HttpResponseRedirect('/')
    if service_type == 'homefood':
        return _proceed_to_homefood_registration(request, homefood_registration_template)
    elif service_type == 'restaurantfood':
        return _proceed_to_restaurantfood_registration(request, restaurantfood_registration_template)
    elif service_type == 'messfood':
        return _proceed_to_messfood_registration(request, messfood_registration_template)
    return HttpResponseRedirect('/')
示例#6
0
def view_checkemail(request):
    remail = _request_param_post(request, 'remail')
    if not remail:
        from users.messages import ICON_CROSS, INVALID_EMAIL_ADDRESS_ERROR_MESSAGE
        return HttpResponse('%s%s' % (ICON_CROSS, INVALID_EMAIL_ADDRESS_ERROR_MESSAGE))
    from django.forms.fields import email_re
    if not email_re.search(remail.strip().lower()):
        from users.messages import ICON_CROSS, INVALID_EMAIL_ADDRESS_ERROR_MESSAGE
        return HttpResponse('%s%s' % (ICON_CROSS, INVALID_EMAIL_ADDRESS_ERROR_MESSAGE))
    from users.models import UserProfile
    if UserProfile.objects.filter(email=remail):
        from users.messages import ICON_CROSS, EMAIL_ADDRESS_ALREADY_TAKEN_ERROR_MESSAGE
        return HttpResponse('%s%s' % (ICON_CROSS, EMAIL_ADDRESS_ALREADY_TAKEN_ERROR_MESSAGE))
    else:
        from users.messages import ICON_SUCESS, VALID_EMAIL_ADDRESS_MESSAGE
        return HttpResponse('%s%s' % (ICON_SUCESS, VALID_EMAIL_ADDRESS_MESSAGE))
示例#7
0
def view_computedeliverytime(request,deliverytime_template):
    hours = _request_param_post(request,'hours')
    delivery_time = None
    from datetime import datetime,timedelta
    delivery_time = datetime.now()+timedelta(hours=int(hours))
    return response(deliverytime_template,locals(),request)