Beispiel #1
0
 def save(self, *args, **kwargs):
     self.slug = slugify(self.name)
     from app.notifications.models import Notification
     try:
         if not Notification.objects.filter(brand=self.obj).exists():
             Notification(brand=self,
                          notification_type=Notification.NEW_BRAND_ADDED)
     except:
         pass
     super(Brand, self).save(*args, **kwargs)
Beispiel #2
0
 def save(self, *args, **kwargs):
     self.slug = slugify(self.name)
     notify = kwargs.get('notify', None)
     if notify:
         if not Notification.objects.filter(
                 model=self,
                 notification_type=Notification.NEW_MODEL_ADDED).exists():
             Notification(model=self,
                          brand=self.brand,
                          notification_type=Notification.NEW_MODEL_ADDED)
     super(Model, self).save(*args, **kwargs)
Beispiel #3
0
 def notify_client_paid_for_at(self, shop, client, cashierman):
     if self.user.profile.shop == shop and not self.user == cashierman:
         try:
             if self.user.groups.all(
             )[0] in Notification.CLIENT_GROUPS_TO_NOTIFY:
                 Notification(
                     notification_type=Notification.CLIENT_PAID_FOR_AT,
                     shop=shop,
                     client=client,
                     to_user=cashierman).save()
         except:
             pass
Beispiel #4
0
 def notify_client_status_changed(self, shop, client, changer):
     if self.user.profile.shop == shop:
         try:
             if self.user.groups.all(
             )[0] in Notification.CLIENT_GROUPS_TO_NOTIFY:
                 Notification(
                     notification_type=Notification.CLIENT_STATUS_CHANGED,
                     shop=shop,
                     client=client,
                     to_user=changer).save()
         except:
             pass
Beispiel #5
0
def private_message(payload):
    message = payload['message']

    # verify recipient can receive message from sender by checking blocks and likes
    parent = aliased(Like, name="parent")
    child = aliased(Like, name="child")
    can_message = db.session.query(User.id) \
      .outerjoin(Block, \
        ((session['user_id'] == Block.blocked_id) & \
         (payload['user_id'] == Block.blocked_by_id)) | \
        ((session['user_id'] == Block.blocked_by_id) & \
          (payload['user_id'] == Block.blocked_id))) \
      .filter(Block.blocked_id == None, User.id == payload['user_id']) \
      .join(parent, ((session['user_id'] == parent.liked_id) & (payload['user_id'] == parent.liked_by_id))) \
      .filter(session['user_id'] == parent.liked_id) \
      .join(child, \
       (child.liked_id == parent.liked_by_id) & \
       (child.liked_by_id == parent.liked_id)) \
      .first()

    if can_message and can_message[0] == int(payload['user_id']):
        Chat.save_message(sent_by_id=session['user_id'],
                          received_by_id=payload['user_id'],
                          message=message,
                          message_time=payload['timestamp'])

        notification = Notification.query.filter_by(
            owner_id=payload['user_id'],
            sent_by_id=payload['sender'],
            event_id=5).first()
        if not notification:
            Notification.create_notification(payload['user_id'],
                                             payload['sender'], 5,
                                             datetime.now())
        else:
            notification.update_notification()

        if users.get(payload['user_id']):
            recipient_session_id = users[payload['user_id']]
            emit('new_private_message', payload, room=recipient_session_id)
Beispiel #6
0
 def notify_new_client_review(self, shop, client):
     Notification(notification_type=Notification.NEW_CLIENT_REVIEW,
                  shop=shop,
                  client=client).save()
Beispiel #7
0
 def notify_order_delivery_time_close(self, server, order):
     Notification(
         notification_type=Notification.ORDER_DELIVERY_TIME_IS_CLOSE,
         server=server,
         server_order=order).save()
Beispiel #8
0
 def notify_order_delivered(self, server, order, shop):
     Notification(notification_type=Notification.ORDER_DELIVERED,
                  shop=shop,
                  server=server,
                  server_order=order).save()
Beispiel #9
0
 def notify_shop_by_admin(self, shop, message):
     Notification(notification_type=Notification.ADMIN_NOTIF,
                  shop=shop,
                  message=message).save()
Beispiel #10
0
 def notify_server_by_admin(self, server, message):
     Notification(notification_type=Notification.ADMIN_NOTIF,
                  server=server,
                  message=message).save()
Beispiel #11
0
 def notify_server_for_new_order(self, server, shop, order):
     Notification(notification_type=Notification.NEW_ORDER,
                  shop=shop,
                  server=server,
                  server_order=order)
Beispiel #12
0
 def notifiy_order_cancelled(self, server, shop, order):
     Notification(notification_type=Notification.ORDER_CANCELLED,
                  shop=shop,
                  server=server,
                  server_order=order).save()
Beispiel #13
0
def like_user():
    try:
        if request.json['liked_id'].isdigit() is False:
            return "error"
        liked_id = int(request.json['liked_id'])
        exists = Like.query.filter_by(liked_id=liked_id,
                                      liked_by_id=session['user_id']).first()
        timestamp = datetime.now()

        if not exists:  #Like
            like = Like.like_user(liked_id=liked_id,
                                  liked_by_id=session['user_id'])
            mutual_like = Like.query.filter_by(liked_id=session['user_id'],
                                               liked_by_id=liked_id).first()
            if mutual_like:
                notification = Notification.query.filter_by(
                    owner_id=liked_id,
                    sent_by_id=session['user_id'],
                    event_id=3).first()
                if not notification:
                    Notification.create_notification(liked_id,
                                                     session['user_id'], 3,
                                                     timestamp)
                    mutual = Notification.query.filter_by(
                        owner_id=session['user_id'],
                        sent_by_id=liked_id,
                        event_id=3).first()
                    if not mutual:
                        Notification.create_notification(
                            session['user_id'], liked_id, 3, timestamp)
                    else:
                        mutual.update_notification()
                    opposite = Notification.query.filter_by(
                        owner_id=liked_id,
                        sent_by_id=session['user_id'],
                        event_id=4).first()
                    if opposite:
                        opposite.remove_notification()
                else:
                    notification.update_notification()
                    mutual = Notification.query.filter_by(
                        owner_id=session['user_id'],
                        sent_by_id=liked_id,
                        event_id=3).first()
                    if not mutual:
                        Notification.create_notification(
                            session['user_id'], liked_id, 3, timestamp)
                    else:
                        mutual.update_notification()
                    opposite = Notification.query.filter_by(
                        owner_id=liked_id,
                        sent_by_id=session['user_id'],
                        event_id=4).first()
                    if opposite:
                        opposite.remove_notification()
            else:
                notification = Notification.query.filter_by(
                    owner_id=liked_id,
                    sent_by_id=session['user_id'],
                    event_id=2).first()
                if not notification:
                    Notification.create_notification(liked_id,
                                                     session['user_id'], 2,
                                                     timestamp)
                    opposite = Notification.query.filter_by(
                        owner_id=liked_id,
                        sent_by_id=session['user_id'],
                        event_id=4).first()
                    if opposite:
                        opposite.remove_notification()
                else:
                    notification.update_notification()
            if mutual_like:
                return jsonify(like_result="Unlike", chat=True)
            return jsonify(like_result="Unlike", chat=False)
        else:  #Unlike
            notification = Notification.query.filter_by(
                owner_id=liked_id, sent_by_id=session['user_id'],
                event_id=4).first()  #Someone unliked
            if not notification:
                Notification.create_notification(liked_id, session['user_id'],
                                                 4, timestamp)
                opposite = Notification.query.filter_by(
                    owner_id=liked_id,
                    sent_by_id=session['user_id'],
                    event_id=2).first()
                if opposite:
                    opposite.remove_notification()
                opposite = Notification.query.filter_by(
                    owner_id=liked_id,
                    sent_by_id=session['user_id'],
                    event_id=3).first()
                if opposite:
                    opposite.remove_notification()
                    opposite = Notification.query.filter_by(
                        owner_id=session['user_id'],
                        sent_by_id=liked_id,
                        event_id=3).first()
                    opposite.remove_notification()
            else:
                notification.update_notification()
                opposite = Notification.query.filter_by(
                    owner_id=liked_id,
                    sent_by_id=session['user_id'],
                    event_id=2).first()
                if opposite:
                    opposite.remove_notification()
                opposite = Notification.query.filter_by(
                    owner_id=liked_id,
                    sent_by_id=session['user_id'],
                    event_id=3).first()
                if opposite:
                    opposite.remove_notification()
                    opposite = Notification.query.filter_by(
                        owner_id=session['user_id'],
                        sent_by_id=liked_id,
                        event_id=3).first()
                    opposite.remove_notification()
            exists.remove_like()
            return jsonify(like_result="Like", chat=False)
    except:
        return "error"
Beispiel #14
0
 def notify_declined_transaction(self, server, payment):
     Notification(notification_type=Notification.TRANSACTION_DECLINED,
                  shop=shop,
                  payment=payment).save()
Beispiel #15
0
 def notify_no_server_response_server(self, order, server, ticket):
     Notification(notification_type=Notification.NO_SERVER_RESPONSE_SERVER,
                  server_order=order,
                  server=server,
                  ticket=ticket)
Beispiel #16
0
 def notify_no_server_response_shop(self, order, shop, ticket):
     Notification(notification_type=Notification.NO_SERVER_RESPONSE_SHOP,
                  server_order=order,
                  shop=shop,
                  ticket=ticket).save()
Beispiel #17
0
 def notify_admin_response(self, shop, server, ticket):
     Notification(notification_type=Notification.ADMIN_RESPONSE,
                  shop=shop,
                  server=server,
                  ticket=ticket).save()
Beispiel #18
0
 def notify_server_response(self, shop, server, ticket):
     Notification(notification_type=Notification.SERVER_RESPONSE,
                  shop=shop,
                  server=server,
                  ticket=ticket).save()
Beispiel #19
0
 def notify_new_ticket(self, shop, server, ticket):
     Notification(notification_type=Notification.NEW_TICKET,
                  shop=shop,
                  server=server,
                  ticket=ticket).save()
Beispiel #20
0
 def notify_new_shop_review(self, server, shop):
     Notification(notification_type=Notification.NEW_SHOP_REVIEW,
                  shop=shop,
                  server=server).save()
Beispiel #21
0
 def notify_new_brand(self, brand):
     Notification(notification_type=Notification.NEW_BRAND_ADDED,
                  brand=brand).save()
Beispiel #22
0
 def notify_client_has_to_review(self, shop, client):
     Notification(notification_type=Notification.CLIENT_HAS_TO_REVIEW,
                  shop=shop,
                  client=client).save()
Beispiel #23
0
 def notify_new_model(self, model):
     Notification(notification_type=Notification.NEW_MODEL_ADDED,
                  model=model).save()
Beispiel #24
0
 def notify_accepted_transaction(self, server, payment=False):
     Notification(notification_type=Notification.ACCEPTED_TRANSACTION,
                  server=server).save()
Beispiel #25
0
 def notify_order_delivery_time_exceeded(self, server, shop, order):
     Notification(
         notification_type=Notification.ORDER_DELIVERY_TIME_EXCEEDED,
         shop=shop,
         server=server,
         server_order=order).save()