def bookings(request): user = request.user artist = Artist.objects.get(user=user) bookings = Booking.objects.select_related().filter(artist=artist) if request.method == 'POST': sn = request.POST.get('sn',None) sn_approve = request.POST.get('sn_approve', None) if sn: b = Booking.objects.get(id=int(sn)) old_status = b.status b.status = 2 b.cancelled_by = 1 b.save(old_status) void_authorization(b.id) elif sn_approve: b = Booking.objects.get(id=int(sn_approve)) old_status = b.status b.status = 1 b.cancelled_by = 1 b.save(old_status) return redirect(reverse("artists_bookings")) bookings = paginator(request, bookings, 10) return render(request, 'artists/bookings.html', {"bookings": bookings})
def show_notifications(request): user_id = request.user.id query = ''' SELECT n.id, COALESCE(profile.avatar, artist.avatar) AS avatar, n.long_text AS text, n.time AS time, n.is_readed AS is_readed FROM notifications_notification as n INNER JOIN auth_user AS _user ON n.sender_id = _user.id LEFT JOIN users_profile AS profile ON _user.id = profile.id LEFT JOIN artists_artist AS artist ON _user.id = artist.id LEFT JOIN salons_salon AS salon ON _user.id = salon.id WHERE n.receiver_id = %s ''' cursor = connection.cursor() cursor.execute(query, [user_id]) notifications = dictfetchall(cursor) _notifications = [] for n in notifications: n["avatar"] = MEDIA_ROOT + n["avatar"][7:] if n["avatar"] else "" _notifications.append(n["id"]) _notifications = Notification.objects.filter(id__in=_notifications).update( is_readed=True) notifications = paginator(request, notifications, 10) return render(request, 'notifications/notifications.html', {'notifications': notifications})
def show_notifications(request): user_id = request.user.id query = ''' SELECT n.id, COALESCE(profile.avatar, artist.avatar) AS avatar, n.long_text AS text, n.time AS time, n.is_readed AS is_readed FROM notifications_notification as n INNER JOIN auth_user AS _user ON n.sender_id = _user.id LEFT JOIN users_profile AS profile ON _user.id = profile.id LEFT JOIN artists_artist AS artist ON _user.id = artist.id LEFT JOIN salons_salon AS salon ON _user.id = salon.id WHERE n.receiver_id = %s ''' cursor = connection.cursor() cursor.execute(query, [user_id]) notifications = dictfetchall(cursor) _notifications = [] for n in notifications: n["avatar"] = MEDIA_ROOT + n["avatar"][7:] if n["avatar"] else "" _notifications.append(n["id"]) _notifications = Notification.objects.filter(id__in = _notifications).update(is_readed=True) notifications = paginator(request, notifications, 10) return render(request, 'notifications/notifications.html', {'notifications': notifications})
def bookings(request): user = request.user salon = Salon.objects.get(user=user) artists = Artist.objects.filter(salon=salon) bookings = Booking.objects.select_related().filter(artist__in=artists).order_by("start_time").reverse() if request.method == "POST": sn = request.POST.get("sn", None) sn_approve = request.POST.get("sn_approve", None) if sn: b = Booking.objects.get(id=int(sn)) old_status = b.status b.status = 2 b.cancelled_by = 1 b.save(old_status) elif sn_approve: b = Booking.objects.get(id=int(sn_approve)) old_status = b.status b.status = 1 b.cancelled_by = 1 b.save(old_status) return redirect(reverse("salons_bookings")) bookings = paginator(request, bookings, 10) return render(request, "salons/bookings.html", {"bookings": bookings})
def bookings(request): user = request.user salon = Salon.objects.get(user=user) artists = Artist.objects.filter(salon=salon) bookings = Booking.objects.select_related().filter( artist__in=artists).order_by('start_time').reverse() if request.method == 'POST': sn = request.POST.get('sn', None) sn_approve = request.POST.get('sn_approve', None) if sn: b = Booking.objects.get(id=int(sn)) old_status = b.status b.status = 2 b.cancelled_by = 1 b.save(old_status) elif sn_approve: b = Booking.objects.get(id=int(sn_approve)) old_status = b.status b.status = 1 b.cancelled_by = 1 b.save(old_status) return redirect(reverse('salons_bookings')) bookings = paginator(request, bookings, 10) return render(request, 'salons/bookings.html', {"bookings": bookings})
def bookings(request): if request.method == 'POST': sn = request.POST.get('sn', None) is_sanction = request.POST.get('cancellation_policy', None) print("is_sanction", is_sanction) if sn and not is_sanction: b = Booking.objects.get(id=int(sn)) old_status = int(b.status) b.status = 2 b.cancelled_by = 2 b.save(old_status) void_authorization(b.id) elif sn and is_sanction: b = Booking.objects.get(id=int(sn)) old_status = int(b.status) b.status = 2 b.cancelled_by = 2 b.save(old_status) partially_capture(b.id) return redirect(reverse("users_bookings")) user_id = request.user.id profile = Profile.objects.select_related().get(user_id=user_id) temp_bookings = Booking.objects.select_related().filter( client=profile).order_by('-start_time') bookings = [] for t in temp_bookings: booking = {} booking["id"] = t.id booking["title"] = t.title booking["listing_id"] = t.listing_id booking["artist_id"] = t.artist_id booking["artist_avatar"] = t.artist.get_avatar() booking["artist_name"] = t.artist.user.first_name booking["price"] = t.price booking["currency"] = t.artist.currency booking["status"] = t.get_status() booking["start_time"] = t.start_time booking["listing"] = t.listing.get_picture() booking["days_before"] = t.cancellation_policy.days_before booking["percent"] = t.cancellation_policy.percent booking["dialog"] = 1 if t.status == 1 else 0 bookings.append(booking) bookings = paginator(request, bookings, 10) return render(request, 'user/bookings.html', {"bookings": bookings})
def bookings(request): if request.method == 'POST': sn = request.POST.get('sn', None) is_sanction = request.POST.get('cancellation_policy', None) print("is_sanction", is_sanction) if sn and not is_sanction: b = Booking.objects.get(id=int(sn)) old_status = int(b.status) b.status = 2 b.cancelled_by = 2 b.save(old_status) void_authorization(b.id) elif sn and is_sanction: b = Booking.objects.get(id=int(sn)) old_status = int(b.status) b.status = 2 b.cancelled_by = 2 b.save(old_status) partially_capture(b.id) return redirect(reverse("users_bookings")) user_id = request.user.id profile = Profile.objects.select_related().get(user_id=user_id) temp_bookings = Booking.objects.select_related().filter(client=profile).order_by('-start_time') bookings = [] for t in temp_bookings: booking = {} booking["id"] = t.id booking["title"] = t.title booking["listing_id"] = t.listing_id booking["artist_id"] = t.artist_id booking["artist_avatar"] = t.artist.get_avatar() booking["artist_name"] = t.artist.user.first_name booking["price"] = t.price booking["currency"] = t.artist.currency booking["status"] = t.get_status() booking["start_time"] = t.start_time booking["listing"] = t.listing.get_picture() booking["days_before"] = t.cancellation_policy.days_before booking["percent"] = t.cancellation_policy.percent booking["dialog"] = 1 if t.status == 1 else 0 bookings.append(booking) bookings = paginator(request, bookings, 10) return render(request, 'user/bookings.html', {"bookings": bookings})
def show_notifications(request): user = request.user receiver_id = user.id query = ''' SELECT n.id, COALESCE(profile.avatar, artist.avatar, salon.avatar) AS avatar, n.long_text AS text, n.time AS time, n.is_readed AS is_readed, n.sender_id AS sender_id FROM notifications_notification as n INNER JOIN auth_user AS _user ON n.sender_id = _user.id LEFT JOIN users_profile AS profile ON _user.id = profile.user_id LEFT JOIN artists_artist AS artist ON _user.id = artist.user_id LEFT JOIN salons_salon AS salon ON _user.id = salon.user_id WHERE n.receiver_id = %s ORDER BY n.id DESC ''' if user.related_with == 'salons': receiver_id = user.salon.id query = ''' SELECT DISTINCT (n.id), COALESCE(profile.avatar, artist.avatar, salon.avatar) AS avatar, n.long_text AS text, n.time AS time, n.is_readed AS is_readed, n.sender_id AS sender_id FROM salons_salon AS s INNER JOIN artists_artist AS a ON s.id = a.salon_id INNER JOIN auth_user AS u ON (a.user_id = u.id) OR (u.id = ''' + str( user.id) + ''') INNER JOIN notifications_notification AS n ON n.receiver_id = u.id LEFT JOIN users_profile AS profile ON n.sender_id = profile.user_id LEFT JOIN artists_artist AS artist ON n.sender_id = artist.user_id LEFT JOIN salons_salon AS salon ON n.sender_id = salon.user_id WHERE s.id = %s ORDER BY n.id DESC ''' cursor = connection.cursor() cursor.execute(query, [receiver_id]) notifications = dictfetchall(cursor) _notifications = [] for n in notifications: n["avatar"] = MEDIA_ROOT + n["avatar"][7:] if n["avatar"] else "" _notifications.append(n["id"]) _notifications = Notification.objects.filter(id__in=_notifications).update( is_readed=True) notifications = paginator(request, notifications, 10) return render(request, 'notifications/notifications.html', {'notifications': notifications})
def show_notifications(request): user = request.user receiver_id = user.id query = ''' SELECT n.id, COALESCE(profile.avatar, artist.avatar, salon.avatar) AS avatar, n.long_text AS text, n.time AS time, n.is_readed AS is_readed, n.sender_id AS sender_id FROM notifications_notification as n INNER JOIN auth_user AS _user ON n.sender_id = _user.id LEFT JOIN users_profile AS profile ON _user.id = profile.user_id LEFT JOIN artists_artist AS artist ON _user.id = artist.user_id LEFT JOIN salons_salon AS salon ON _user.id = salon.user_id WHERE n.receiver_id = %s ORDER BY n.id DESC ''' if user.related_with == 'salons': receiver_id = user.salon.id query = ''' SELECT DISTINCT (n.id), COALESCE(profile.avatar, artist.avatar, salon.avatar) AS avatar, n.long_text AS text, n.time AS time, n.is_readed AS is_readed, n.sender_id AS sender_id FROM salons_salon AS s INNER JOIN artists_artist AS a ON s.id = a.salon_id INNER JOIN auth_user AS u ON (a.user_id = u.id) OR (u.id = '''+str(user.id)+''') INNER JOIN notifications_notification AS n ON n.receiver_id = u.id LEFT JOIN users_profile AS profile ON n.sender_id = profile.user_id LEFT JOIN artists_artist AS artist ON n.sender_id = artist.user_id LEFT JOIN salons_salon AS salon ON n.sender_id = salon.user_id WHERE s.id = %s ORDER BY n.id DESC ''' cursor = connection.cursor() cursor.execute(query, [receiver_id]) notifications = dictfetchall(cursor) _notifications = [] for n in notifications: n["avatar"] = MEDIA_ROOT + n["avatar"][7:] if n["avatar"] else "" _notifications.append(n["id"]) _notifications = Notification.objects.filter(id__in=_notifications).update(is_readed=True) notifications = paginator(request, notifications, 10) return render(request, 'notifications/notifications.html', {'notifications': notifications})