Ejemplo n.º 1
0
def register():
    content = request.get_json()
    register = Register(**content)

    #1. check email
    if not register.check_email():
        return (jsonify({'error': 'Not valid email address.'}), 400)
    if len(Restaurant.objects(email=content['email'])):
        return (jsonify({'error': 'Email is alredy in used.'}), 400)
    #2. check password
    check_password = register.check_password()
    if check_password:
        return (jsonify({'error': check_password}), 400)
    #3. hash password
    res = Restaurant(**content)
    res.set_password(content['pwd'])
    register.send_email()
    #4. save
    try:
        res.save()
    except Exception as e:
        return (jsonify({
            'error':
            "There is an error at the database. Please try later..."
        }), 500)

    content.pop('pwd', None)
    return (jsonify(content), 200)
 def test_sqlrepo_query_internal(self):
     restaurant_object = Restaurant(**fixtures.SINGLE_QUERY_RESULT)
     restaurant_object.save()
     result = self.sqlrepo._query(params=fixtures.PARAMS,
                                  first=True,
                                  as_dict=True)
     self.assertEqual(result, fixtures.SINGLE_QUERY_RESULT)
Ejemplo n.º 3
0
    def save(self, commit=True):
        restaurant = Restaurant()

        restaurant.nom = self.cleaned_data["nom"]
        restaurant.adresse = self.cleaned_data["adresse"]
        restaurant.telephone = self.cleaned_data["telephone"]
        restaurant.restaurateur = self.cleaned_data["restaurateur"]

        restaurant.save()

        return restaurant
Ejemplo n.º 4
0
    def save(self, commit=True):
        restaurant = Restaurant()
		
        restaurant.nom = self.cleaned_data["nom"]
        restaurant.adresse = self.cleaned_data["adresse"]
        restaurant.telephone = self.cleaned_data["telephone"]
        restaurant.restaurateur = self.cleaned_data["restaurateur"]
		
        restaurant.save()

        return restaurant
Ejemplo n.º 5
0
def add_delivery(request):
    pprint("Are we getting here?")
    message = ""
     
    if (request.user.is_authenticated and request.method == "POST"):
        # Get POST Vars, hopefully we can get Postamtes to open their API
        # So I can get access to this shit.
        # That's not gonna happen though.
        _name = request.POST.get('name')
        _address = request.POST.get('address')
        _time = request.POST.get('time')
        _wait = request.POST.get('wait')
        _distance = request.POST.get('distance')
        _base = float(request.POST.get('base'))
        _tip = float(request.POST.get('tip'))
        
        # Update Our Restaurant Table
        try:
            r = Restaurant.objects.get(name=_name)
            message = "Delivery Already Added, updating"

            _total_tips = 0 if _tip <= 0 else 1
            r.total_tips += _total_tips
            r.total_tip_amount += _tip

            r.total_earnings += _base
            r.total_deliveries += 1
            r.save()


        except Restaurant.DoesNotExist:
            _total_tips = 0 if _tip <= 0 else 1
            r = Restaurant(name=_name, total_earnings=_base, total_tips=_total_tips, total_tip_amount=_tip)
            r.save()

        pprint(r)
        message = "Delivery Added To Database"

        # Update Our Delivery Table
        d = Delivery(
            user_id=request.user.id,
            restaurant=r,
            service="POSTMATES",
            address=_address,
            time_accepted=_time,
            wait_time=_wait,
            distance=_distance,
            base_earning=_base,
            tip=_tip
        )

        d.save()
        
    return render(request, "add.html", {"message": message})
Ejemplo n.º 6
0
def new(request):
    user = request.user if request.user.is_authenticated() else None
    if not user.lunchprofile.can_create_restaurants:
        return HttpResponseForbidden

    data = json.loads(request.BODY)
    restaurant = Restaurant(name=data['name'])

    try:
        restaurant.save()
    except:
        return HttpResponseBadRequest

    return HttpResponse('OK')
Ejemplo n.º 7
0
    def post(self, request, *args, **kwargs):
        restaurant = Restaurant(owner=self.request.user,
                                name=request.data['name'],
                                country=request.data['country'],
                                street=request.data['street'],
                                city=request.data['city'],
                                phone=request.data['phone'])
        restaurant.save()
        if request.data['category']:

            result = Category.objects.filter(
                name__icontains=request.data['category'])

            if result:
                for category in result:
                    restaurant.m2m_restaurant_cat.add(category)
            else:
                category = Category(name=request.data['category'])
                category.save()
                restaurant.m2m_restaurant_cat.add(category)

        return Response(status=200)
Ejemplo n.º 8
0
 def perform_create(self, serializer):
     restaurant = Restaurant(restaurant=self.request.restaurant,
                             **serializer.validated_data)
     restaurant.save()
Ejemplo n.º 9
0
    def restaurant_parsing(self, restaurant_results, restaurant_info_results,
                           list_info, avgrating_results):
        # top - info
        name = restaurant_results['name']
        min_order_price = restaurant_results['min_order_amount']
        methods = []
        for method in restaurant_results['payment_methods']:
            if method == "creditcard":
                methods.append("신용카드")
                methods.append("현금")
            elif method == "online":
                methods.append("요기서결제")

        payment_methods = methods
        try:
            discount = restaurant_results['discounts']['additional'][
                'delivery']['amount']
        except KeyError:
            discount = 0
        delivery_charge = restaurant_results.get('delivery_fee')
        res_lat = restaurant_results['lat']
        res_lng = restaurant_results['lng']
        restaurant_image = restaurant_results['logo_url']
        restaurant_back_image = restaurant_results['background_url']
        categories = restaurant_results['categories']

        # bottom - info
        notification = restaurant_info_results['introduction_by_owner'].get('introduction_text') \
            if restaurant_info_results.get('introduction_by_owner') else ''
        s = restaurant_info_results['opening_time_description'].split(' - ')
        opening_time = datetime.strptime(s[0], '%H:%M')
        closing_time = datetime.strptime(s[1], '%H:%M')
        tel_number = restaurant_info_results['phone']
        address = restaurant_info_results['address']
        business_name = restaurant_info_results['crmdata']['company_name']
        company_registration_number = restaurant_info_results['crmdata'][
            'company_number']
        origin_information = restaurant_info_results['country_origin']

        representative_menus = list_info['representative_menus']

        average = avgrating_results['average']
        average_delivery = avgrating_results['average_delivery']
        average_quantity = avgrating_results['average_quantity']
        average_taste = avgrating_results['average_taste']

        try:
            delivery_time = int(
                restaurant_results['estimated_delivery_time'].split('~')[0])
        except:
            delivery_time = 30

        restaurant = Restaurant(
            name=name,
            notification=notification,
            opening_time=opening_time,
            closing_time=closing_time,
            tel_number=tel_number,
            address=address,
            min_order_price=min_order_price,
            payment_methods=payment_methods,
            business_name=business_name,
            company_registration_number=company_registration_number,
            origin_information=origin_information,
            delivery_discount=discount,
            delivery_charge=delivery_charge,
            delivery_time=delivery_time,
            lat=res_lat,
            lng=res_lng,
            categories=categories,
            representative_menus=representative_menus,

            # 평균 평점
            average_rating=average,
            average_taste=average_taste,
            average_delivery=average_delivery,
            average_amount=average_quantity,
        )
        restaurant.save()

        tags = list_info.get('keywords')
        if tags:
            restaurant.tags.add(*tags.split())

        if restaurant_image:
            restaurant.image.save(*self.save_img('https://www.yogiyo.co.kr' +
                                                 restaurant_image))
        if restaurant_back_image:
            restaurant.back_image.save(*self.save_img(restaurant_back_image))
        return restaurant