Ejemplo n.º 1
0
def load_recommendations():
    recomm = recommendations.get()
    for user_id, context_product_list in recomm.items():
        buyer = Buyer.objects.get(owner=user_id)
        for context_product in context_product_list:
            product = Product.objects.get(name=context_product)
            recomm_model = Recommendation(buyer=buyer,
                                          product=product,
                                          user_id=user_id,
                                          context_product=context_product)
            recomm_model.save()
Ejemplo n.º 2
0
 def obj_create(self, bundle, **kwargs):
     """
     Creates a new recommendation
     """
     try:
         if bundle.data['replied'] != None:
             try:
                 request_obj = Request.objects.get(id=bundle.data['replied'])
                 request_obj.replied = True
                 request_obj.save()
             except Exception, e:
                 print e
         new_rec = Recommendation(recommendation_from=bundle.data["from"], recommendation_to=bundle.data["to"],relationship=bundle.data["relationship"],project=bundle.data["project"],answer1=bundle.data["answer1"],answer2=bundle.data["answer2"],answer3=bundle.data["answer3"])
         new_rec.save()
         bundle.obj = new_rec
Ejemplo n.º 3
0
    def execute(cls, payload):
        recommender = User.objects.get(phone=payload['recommender_phone'])
        recommendee = User.objects.get(
            username=payload['recommendee_username'])
        is_trusted = recommender.is_trusted_by(recommendee)
        recommendation = Recommendation(recommender=recommender,
                                        recommendee=recommendee,
                                        name=payload['name'],
                                        accepted=is_trusted)

        recommendation.full_clean()
        recommendation.save()

        if is_trusted:
            SmsSender.send_to_user(
                recommendee,
                f"{recommender.username} recommended '{recommendation.name}' to you."
            )
        else:
            SmsSender.send_to_user(
                recommendee,
                f"{recommender.username} recommended '{recommendation.name}' to you. Text back 'r{recommendation.id}' if you would like to add this recommendation and them as a trusted user?"
            )
        return {
            'message':
            f"'{recommendation.name}' was recommended to {recommendee.username}."
        }
Ejemplo n.º 4
0
 def obj_create(self, bundle, **kwargs):
     """
     Creates a new recommendation
     """
     try:
         if bundle.data['replied'] != None:
             try:
                 request_obj = Request.objects.get(
                     id=bundle.data['replied'])
                 request_obj.replied = True
                 request_obj.save()
             except Exception, e:
                 print e
         new_rec = Recommendation(recommendation_from=bundle.data["from"],
                                  recommendation_to=bundle.data["to"],
                                  relationship=bundle.data["relationship"],
                                  project=bundle.data["project"],
                                  answer1=bundle.data["answer1"],
                                  answer2=bundle.data["answer2"],
                                  answer3=bundle.data["answer3"])
         new_rec.save()
         bundle.obj = new_rec
 def create_recommendation_and_save(cls, recommender, recommendee, payload):
     cls.is_trusted = recommender.is_trusted_by(recommendee)
     recommendation = Recommendation(recommender=recommender,
                                     recommendee=recommendee,
                                     name=payload['name'],
                                     accepted=cls.is_trusted)
     recommendation.full_clean()
     recommendation.save()
     return recommendation
Ejemplo n.º 6
0
 def execute(cls, payload):
     user = User.objects.get(phone=payload['phone'])
     recommendation = Recommendation(recommender=user,
                                     recommendee=user,
                                     name=payload['name'],
                                     accepted=True)
     recommendation.full_clean()
     recommendation.save()
     return {'message': f"'{recommendation.name}' was added to your list."}
    def execute(cls, payload):
        user = User.objects.get(phone=payload['phone'])
        recommendation = Recommendation(recommender=user,
                                        recommendee=user,
                                        name=payload['name'],
                                        accepted=True)
        recommendation.full_clean()
        recommendation.save()

        cls.set_recommendation_id_in_session(payload['session'],
                                             recommendation)

        return {
            'message':
            f"'{recommendation.name}' was added to your list. Reply to add context."
        }
Ejemplo n.º 8
0
def mapToModel(rec):
    description = rec['description'][:150] + "..."
    name = rec['name']
    return Recommendation(rec['id'], name, description, getPhoto(name))