Exemplo n.º 1
0
    def save(self, force_insert=False, force_update=False, **kwargs):
        if self.id:
            super(Followers, self).save(force_insert, force_update)
        else:
            super(Followers, self).save(force_insert, force_update)
            if self.user.related_with == 'profiles':
                link_1 = '/users/profile/' + str(self.user.profile.id)
            elif self.user.related_with == 'artists':
                link_1 = '/artists/profile/' + str(self.user.artist.id)
            else:
                link_1 = '/salons/profile/' + str(self.user.salon.id)

            Notification.objects.create(
                sender=self.user,
                receiver=self.artist.user,
                time=current_time(),
                short_text=NOTIFICATIONS_SHORT[6].format(
                    user=self.user.first_name),
                long_text=NOTIFICATIONS_LONG[6].format(
                    user=self.user.first_name, link_1=link_1),
            )
            kwargs = {}
            kwargs['username'] = self.user.first_name
            kwargs['count'] = Followers.objects.filter(
                artist=self.artist).count()
            kwargs['id'] = self.artist.id
            send_email(case=8, receiver=self.artist.user, **kwargs)
Exemplo n.º 2
0
def send_review_email():
    print("something cool")
    now = current_time()
    # passed_bookings = Booking.objects.select_related("client__user, artist__user").filter(end_time__lt=now, is_mailed=False, status=1).update(is_mailed=True)
    passed_bookings = Booking.objects.all()
    print(passed_bookings)
    for b in passed_bookings:

        token = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(32))
        
        # b.is_mailed = True
        # b.save()
        w = WaitingForFeedback.objects.all()
        for x in w:
            x.delete()

        WaitingForFeedback.objects.create(
            client=b.client,
            artist=b.artist,
            listing=b.listing,
            booking=b,
            token=token
            )

        kwargs = {}
        kwargs['artistname'] = b.artist.user.first_name
        kwargs['token'] = token
        send_email(case=17, receiver=b.client.user, **kwargs)
Exemplo n.º 3
0
def add(request, listing_id):
    listing_id = int(listing_id)
    user = request.user
    listing = Listing.objects.select_related("artist").get(id=listing_id)

    flag = get_object_or_None(Favorite, user=user, listing=listing)

    if not flag:
        listing.likes = listing.likes + 1
        listing.save()
        Favorite.objects.create(user=user, listing=listing)
        Notification.objects.create(
            sender=user,
            receiver=listing.artist.user,
            time=current_time(),
            short_text=NOTIFICATIONS_SHORT[7].format(user=user.first_name),
            long_text=NOTIFICATIONS_LONG[7].format(user=user.first_name,
                                                   listing=listing.title,
                                                   user_id=user.id,
                                                   metadata=listing_id),
        )
    else:
        listing.likes = listing.likes - 1
        listing.save()
        flag.delete()

    return HttpResponseRedirect(
        reverse('listing', kwargs={'listing_id': listing.id}))
Exemplo n.º 4
0
def send_review_email():
    print("something cool")
    now = current_time()
    # passed_bookings = Booking.objects.select_related("client__user, artist__user").filter(end_time__lt=now, is_mailed=False, status=1).update(is_mailed=True)
    passed_bookings = Booking.objects.all()
    print(passed_bookings)
    for b in passed_bookings:

        token = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(32))

        # b.is_mailed = True
        # b.save()
        w = WaitingForFeedback.objects.all()
        for x in w:
            x.delete()

        WaitingForFeedback.objects.create(client=b.client,
                                          artist=b.artist,
                                          listing=b.listing,
                                          booking=b,
                                          token=token)

        kwargs = {}
        kwargs['artistname'] = b.artist.user.first_name
        kwargs['token'] = token
        send_email(case=17, receiver=b.client.user, **kwargs)
Exemplo n.º 5
0
    def do(self):
        now = current_time()
        passed_bookings = Booking.objects.select_related().filter(
            end_time__lt=now, is_mailed=False, status=1)

        for b in passed_bookings:

            token = ''.join(
                random.choice(string.ascii_lowercase + string.digits)
                for x in range(32))

            WaitingForFeedback.objects.create(client=b.client,
                                              artist=b.artist,
                                              listing=b.listing,
                                              booking=b,
                                              token=token)

            full_capture(b.id)

            kwargs = {}
            kwargs['artistname'] = b.artist.user.first_name
            kwargs['token'] = token
            send_email(case=17, receiver=b.client.user, **kwargs)

        Booking.objects.select_related().filter(
            end_time__lt=now, is_mailed=False, status=1).update(is_mailed=True)
Exemplo n.º 6
0
def send_review_email():

    now = current_time()
    passed_bookings = Booking.objects.select_related().filter(end_time__lt=now, review_email=False, status=1)
    bookings_ids = []
    for b in passed_bookings:
        token = "".join(random.choice(string.ascii_lowercase + string.digits) for x in range(32))

        WaitingForFeedback.objects.create(client=b.client, artist=b.artist, listing=b.listing, booking=b, token=token)

        full_capture(b.id)
        bookings_ids.append(b.id)
        kwargs = {}
        kwargs["artistname"] = b.artist.user.first_name
        kwargs["token"] = token
        send_email(case=17, receiver=b.client.user, **kwargs)

    Booking.objects.filter(id__in=bookings_ids).update(status=3, review_email=True)
Exemplo n.º 7
0
    def do(self):
        now = current_time()
        passed_bookings = Booking.objects.select_related().filter(end_time__lt=now, is_mailed=False, status=1)

        for b in passed_bookings:

            token = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(32))

            WaitingForFeedback.objects.create(
                client=b.client,
                artist=b.artist,
                listing=b.listing,
                booking=b,
                token=token
                )

            full_capture(b.id)

            kwargs = {}
            kwargs['artistname'] = b.artist.user.first_name
            kwargs['token'] = token
            send_email(case=17, receiver=b.client.user, **kwargs)

        Booking.objects.select_related().filter(end_time__lt=now, is_mailed=False, status=1).update(is_mailed=True)
Exemplo n.º 8
0
    def save(self, force_insert=False, force_update=False, **kwargs):
        if self.id:
            super(Followers, self).save(force_insert, force_update)
        else:
            super(Followers, self).save(force_insert, force_update)
            if self.user.related_with == 'profiles':
                link_1 = '/users/profile/' + str(self.user.profile.id)
            elif self.user.related_with == 'artists':
                link_1 = '/artists/profile/' + str(self.user.artist.id)
            else:
                link_1 = '/salons/profile/' + str(self.user.salon.id)

            Notification.objects.create(
                            sender = self.user,
                            receiver = self.artist.user,
                            time = current_time(),
                            short_text = NOTIFICATIONS_SHORT[6].format(user=self.user.first_name),
                            long_text = NOTIFICATIONS_LONG[6].format(user=self.user.first_name, link_1=link_1),
                        )
            kwargs = {}
            kwargs['username'] = self.user.first_name
            kwargs['count'] = Followers.objects.filter(artist=self.artist).count()
            kwargs['id'] = self.artist.id
            send_email(case=8, receiver=self.artist.user, **kwargs)
Exemplo n.º 9
0
def add(request, listing_id):
    listing_id = int(listing_id)
    user = request.user
    listing = Listing.objects.select_related("artist").get(id=listing_id)

    flag = get_object_or_None(Favorite, user=user, listing=listing)

    if not flag:
        listing.likes = listing.likes + 1
        listing.save()
        Favorite.objects.create(user=user, listing=listing)
        Notification.objects.create(
                        sender = user, 
                        receiver = listing.artist.user,
                        time = current_time(),
                        short_text = NOTIFICATIONS_SHORT[7].format(user=user.first_name),
                        long_text = NOTIFICATIONS_LONG[7].format(user=user.first_name, listing=listing.title, user_id=user.id, metadata=listing_id),
                    )
    else:
        listing.likes = listing.likes - 1
        listing.save()
        flag.delete()

    return HttpResponseRedirect(reverse('listing', kwargs={'listing_id': listing.id}))
Exemplo n.º 10
0
def show(request, listing_id=None, title=None):

    if listing_id and listing_id.isdigit():
        try:
            listing = Listing.objects.select_related().get(id=int(listing_id))
        except:
            raise Http404
    else:
        raise Http404

    if listing.status == 3:
        raise Http404

    artist = listing.artist

    booked = False
    profile = None
    favorite = False

    ''' In case that the user start the booking '''
    if request.method == 'POST':
        ''' A hook for the case where the user is not logged in '''
        user = request.user
        back_url = request.POST.get("back_url", None)
        if user.is_authenticated() and not back_url:
            client = user.profile
        else:
            email = request.POST.get('email')
            user = get_object_or_None(User, email=email)
            if user:
                client = get_object_or_None(Profile, user=user)
                if client is not None:
                    login_user(request, user)
                else:
                    messages.add_message(request, messages.ERROR,
                        _("This email is already used by a beauty artist or salon. Please submit different email address in order to continue."))
                    return redirect(reverse('listing', kwargs={"listing_id": listing.id}))
            else:
                username = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(16))
                password = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(6))
                new_user = User.objects.create_user(username=username,
                                                    first_name='anonymous',
                                                    email=email,
                                                    password=password,
                                                    related_with="profiles",)
                client = Profile.objects.create(user=new_user, auto_created=True)
                kwargs = {}
                kwargs['password'] = password
                send_email(case=18, receiver=new_user, **kwargs)

        get_time = int(request.POST.get('time'))
        artist_policy = ArtistPolicy.objects.get(artist=artist, status=1)
        dummy_booking = DummyBooking.objects.create(artist=listing.artist,
                                                    listing=listing,
                                                    client=client,
                                                    cancellation_policy=artist_policy.cancellation_policy,
                                                    revenue=listing.price-listing.original_price,
                                                    price=listing.price,
                                                    title=listing.title,
                                                    start_time=get_time,
                                                    end_time=get_time + listing.duration,)

        request.session["dummy_booking_id"] = dummy_booking.id
        request.session["back_url"] = back_url
        return HttpResponseRedirect(reverse('booking_confirm'))

    else:
        ''' Just for reendering the page '''
        try:
            user = request.user
            favorite = get_object_or_None(Favorite, user=user, listing=listing)
            profile = get_object_or_None(Profile, user=user)
        except:
            pass
        # if current visiter is profile and the listing is not in his favorite list, the flag is turned on

        if not favorite and profile:
            favorite = False
        else:
            favorite = True

        # if current visiter is profile, we will give them a chance to book it
        if profile:
            bookings = Booking.objects.filter(client=profile, listing=listing)
            if bookings:
                for b in bookings:
                    if b.end_time > current_time() and b.status in [0, 1]:
                        booked = b.start_time

        hours = ['8:00 AM', '8:30 AM', '9:00 AM', '9:30 AM', '10:00 AM', '10:30 AM', '11:00 AM', '11:30 AM', '12:00 PM', '12:30 PM', '13:00 PM', '13:30 PM', '14:00 PM', '14:30 PM', '15:00 PM', '15:30 PM', '16:00 PM', '16:30 PM', '17:00 PM', '17:30 PM', '18:00 PM', '18:30 PM', '19:00 PM', '19:30 PM']
        artist_policy = ArtistPolicy.objects.get(artist=artist, status=1)
        tags = ListingTags.objects.select_related("tags").filter(listing=listing)
        tags = [t.tags.tag for t in tags]

        reviews = Review.objects.select_related().filter(listing=listing)
        reviews = list(reviews)
        rate = get_rate(reviews)
        artist_reviews = Review.objects.select_related().filter(artist=artist)
        artist_reviews = list(artist_reviews)
        artist_rate = get_rate(artist_reviews)

        current_date = time.strftime("%Y-%m-%d")

        listing_view, created = ListingView.objects.get_or_create(listing=listing, date=current_date)
        listing_view.views = listing_view.views + 1
        listing_view.save()

    return render(request, 'listings/details.html', {'listing': listing,
                                                     'artist': artist,
                                                     'reviews': reviews,
                                                     'rate': rate,
                                                     'artist_rate': artist_rate,
                                                     'favorite': favorite,
                                                     'hours': hours,
                                                     'booked': booked,
                                                     'policy': artist_policy,
                                                     'tags': tags})
Exemplo n.º 11
0
def show(request, listing_id=None, title=None):

    if listing_id and listing_id.isdigit():
        try:
            listing = Listing.objects.select_related().get(id=int(listing_id))
        except:
            raise Http404
    else:
        raise Http404

    if listing.status == 3:
        raise Http404

    artist = listing.artist

    booked = False
    profile = None
    favorite = False
    ''' In case that the user start the booking '''
    if request.method == 'POST':
        ''' A hook for the case where the user is not logged in '''
        user = request.user
        back_url = request.POST.get("back_url", None)
        if user.is_authenticated() and not back_url:
            client = user.profile
        else:
            email = request.POST.get('email')
            user = get_object_or_None(User, email=email)
            if user:
                client = get_object_or_None(Profile, user=user)
                if client is not None:
                    login_user(request, user)
                else:
                    messages.add_message(
                        request, messages.ERROR,
                        _("This email is already used by a beauty artist or salon. Please submit different email address in order to continue."
                          ))
                    return redirect(
                        reverse('listing', kwargs={"listing_id": listing.id}))
            else:
                username = ''.join(
                    random.choice(string.ascii_lowercase + string.digits)
                    for x in range(16))
                password = ''.join(
                    random.choice(string.ascii_lowercase + string.digits)
                    for x in range(6))
                new_user = User.objects.create_user(
                    username=username,
                    first_name='anonymous',
                    email=email,
                    password=password,
                    related_with="profiles",
                )
                client = Profile.objects.create(user=new_user,
                                                auto_created=True)
                kwargs = {}
                kwargs['password'] = password
                send_email(case=18, receiver=new_user, **kwargs)

        get_time = int(request.POST.get('time'))
        artist_policy = ArtistPolicy.objects.get(artist=artist, status=1)
        dummy_booking = DummyBooking.objects.create(
            artist=listing.artist,
            listing=listing,
            client=client,
            cancellation_policy=artist_policy.cancellation_policy,
            revenue=listing.price - listing.original_price,
            price=listing.price,
            title=listing.title,
            start_time=get_time,
            end_time=get_time + listing.duration,
        )

        request.session["dummy_booking_id"] = dummy_booking.id
        request.session["back_url"] = back_url
        return HttpResponseRedirect(reverse('booking_confirm'))

    else:
        ''' Just for reendering the page '''
        try:
            user = request.user
            favorite = get_object_or_None(Favorite, user=user, listing=listing)
            profile = get_object_or_None(Profile, user=user)
        except:
            pass
        # if current visiter is profile and the listing is not in his favorite list, the flag is turned on

        if not favorite and profile:
            favorite = False
        else:
            favorite = True

        # if current visiter is profile, we will give them a chance to book it
        if profile:
            bookings = Booking.objects.filter(client=profile, listing=listing)
            if bookings:
                for b in bookings:
                    if b.end_time > current_time() and b.status in [0, 1]:
                        booked = b.start_time

        hours = [
            '8:00 AM', '8:30 AM', '9:00 AM', '9:30 AM', '10:00 AM', '10:30 AM',
            '11:00 AM', '11:30 AM', '12:00 PM', '12:30 PM', '13:00 PM',
            '13:30 PM', '14:00 PM', '14:30 PM', '15:00 PM', '15:30 PM',
            '16:00 PM', '16:30 PM', '17:00 PM', '17:30 PM', '18:00 PM',
            '18:30 PM', '19:00 PM', '19:30 PM'
        ]
        artist_policy = ArtistPolicy.objects.get(artist=artist, status=1)
        tags = ListingTags.objects.select_related("tags").filter(
            listing=listing)
        tags = [t.tags.tag for t in tags]

        reviews = Review.objects.select_related().filter(listing=listing)
        reviews = list(reviews)
        rate = get_rate(reviews)
        artist_reviews = Review.objects.select_related().filter(artist=artist)
        artist_reviews = list(artist_reviews)
        artist_rate = get_rate(artist_reviews)

        current_date = time.strftime("%Y-%m-%d")

        listing_view, created = ListingView.objects.get_or_create(
            listing=listing, date=current_date)
        listing_view.views = listing_view.views + 1
        listing_view.save()

    return render(
        request, 'listings/details.html', {
            'listing': listing,
            'artist': artist,
            'reviews': reviews,
            'rate': rate,
            'artist_rate': artist_rate,
            'favorite': favorite,
            'hours': hours,
            'booked': booked,
            'policy': artist_policy,
            'tags': tags
        })
Exemplo n.º 12
0
    def save(self, force_insert=False, force_update=False, **kwargs):
        es = ElasticSearch(ELASTIC_SEARCH_URL)
        if self.id:
            location = self.get_location()
            location_es = "{0},{1}".format(location.y, location.x)
            es.update('glamazer', 'modelresult', 'listings.listing.{0}'.format(self.id),
                script="ctx._source.listing_id = listing;" +
                "ctx._source.artist_id = artist;" +
                "ctx._source.artist_avatar = artist_avatar;" +
                "ctx._source.title = title;" +
                "ctx._source.location = location;" +
                "ctx._source.description = description;" +
                "ctx._source.get_picture = get_picture;" +
                "ctx._source.metadata = metadata;" +
                "ctx._source.price = price;" +
                "ctx._source.likes = likes;" +
                "ctx._source.comments = comments;" +
                "ctx._source.tags = tags;" +
                "ctx._source.status = status;" +
                "ctx._source.style = style;" +
                "ctx._source.rating = rating",
                params={
                    'listing':self.id, 
                    'artist':self.get_artist_id(),
                    'artist_avatar':self.get_artist_avatar(),
                    'title':self.title,
                    'location':location_es,
                    'description':self.description, 
                    'get_picture':self.get_picture(),
                    'metadata':self.metadata,
                    'price':self.price,
                    'likes':self.likes,
                    'comments':self.comments,
                    'tags':self.get_tags(),
                    'status':self.status,
                    'style':self.get_style(),
                    'rating':self.get_rating()
                    })
            super(Listing, self).save(force_insert, force_update)
        else:
            super(Listing, self).save(force_insert, force_update)

            artist_user = self.artist.user
            artist_name = artist_user.first_name
            followers = Followers.objects.select_related().filter(artist=self.artist)
            for follower in followers:
                Notification.objects.create(
                    sender = artist_user,
                    receiver = follower.user,
                    time = current_time(),
                    short_text = NOTIFICATIONS_SHORT[10].format(artist=artist_name),
                    long_text = NOTIFICATIONS_LONG[10].format(artist=artist_name, listing=self.title, user_id=self.artist_id, metadata=self.id),
                )

            location = self.get_location()
            location_es = "{0},{1}".format(location.y, location.x)
            es.index('glamazer', 'modelresult', 
                {
                    'listing_id': self.id,
                    'artist_id': self.artist_id,
                    'artist_avatar':self.get_artist_avatar(),
                    'title': self.title,
                    'location': location_es,
                    'description': self.description,
                    'get_picture': self.get_picture(),
                    'metadata': self.metadata,
                    'price': self.price,
                    'likes': self.likes,
                    'comments':self.comments,
                    'tags': self.get_tags(),
                    'status':self.status,
                    'style':self.get_style(),
                    'rating':self.get_rating()
                }, id='listings.listing.{0}'.format(self.id))
            es.refresh('glamazer')
Exemplo n.º 13
0
def delete_artist(request, artist_id):
    artist = Artist.objects.select_related("salon").get(id=int(artist_id))
    listings = Listing.objects.filter(artist=artist)
    # the current time in seconds, so we can filter the booking by this
    now = current_time()
    bookings = Booking.objects.select_related("artist", "artist__user", "client__user", "listing").filter(
        artist=artist, start_time__gt=now, status__in=[0, 1]
    )

    # select all artist, assigned to this salon
    init_artists = Artist.objects.select_related("user").filter(~Q(id=artist.id), salon=artist.salon)

    # If the salon have artists, and the artist have listings and bookings
    if listings and bookings and init_artists:
        data = []
        # for each booking, we should find the artist which are available... not a easy one to do
        for b in bookings:
            weekday = int(strftime("%w", gmtime(b.start_time)))
            # for each booking, we will have specific group of artists, which will be able to take the booking
            artist_to_submit = []
            # we need only the ids of the artists, os we can easiely and fast search for them
            artists = [a.id for a in init_artists]

            # check if the artist work in this day. Currently we'll ignore the fact that the time could be not in his worktime
            days = ["mon_start", "tues_start", "wed_start", "thurs_start", "fri_start", "sat_start", "sun_start"]
            kwargs = {days[weekday]: -1}
            work_time = WorkTime.objects.filter(artist_id__in=artists).exclude(**kwargs)
            artists = [a.artist_id for a in work_time]

            # check if he is busy, during the time of the booking
            busy_hours = Busy.objects.filter(artist_id__in=artists).exclude(
                Q(end_time__lt=b.start_time) | Q(start_time__gt=b.end_time)
            )

            sub_artists = [a.artist_id for a in busy_hours]
            artists = [a for a in artists if a not in sub_artists]
            # check for other booking during this time
            temp_booking = Booking.objects.filter(artist_id__in=artists).exclude(
                Q(end_time__lt=b.start_time) | Q(start_time__gt=b.end_time)
            )

            sub_artists = [a.artist_id for a in temp_booking]
            artists = [a for a in artists if a not in sub_artists]

            artists = Artist.objects.select_related("user").filter(id__in=artists)
            for a in artists:
                artist_to_submit.append(a)
            data.append({"data": b, "artists": artist_to_submit[:]})

        return render(request, "salons/delete_artist.html", {"artist": artist, "bookings": data})

    # If the artist doesn't have any bookings
    else:
        for l in listings:
            l.status = 2
            l.save()

        salon_user = artist.salon.user
        artist.salon = None
        artist.save()
        user = artist.user
        messages.add_message(
            request, messages.INFO, _("{0} is removed successfully from your salon.").format(user.first_name)
        )
        accept_suspend_request(user, salon_user)
        return HttpResponseRedirect(reverse("salons_artists"))
Exemplo n.º 14
0
    def save(self, force_insert=False, force_update=False, old_status=None, **kwargs):
        if self.id:
            cancelled_by = self.cancelled_by
            super(Booking, self).save(force_insert, force_update)
            print("start_function", cancelled_by, old_status, self.status)
            if cancelled_by == 1 and not old_status == self.status:
                """The real tricky moment here is the notation for nb 1 - the booking is approved, 2 - rejected, 3 declined"""
                notificated_user = self.client.user
                artist_user = self.artist.user
                if self.status == 1:
                    nb = 1
                    cr = CancellationRate.objects.get(artist=self.artist)
                    cr.approved += 1
                    cr.save()
                elif self.status == 2:
                    if old_status == 0:
                        nb = 2
                    else:
                        nb = 3
                        cr = CancellationRate.objects.get(artist=self.artist)
                        cr.cancelled += 1
                        cr.save()

                Notification.objects.create(
                    sender=artist_user,
                    receiver=notificated_user,
                    time=current_time(),
                    short_text=NOTIFICATIONS_SHORT[nb].format(artist=artist_user.first_name),
                    long_text=NOTIFICATIONS_LONG[nb].format(
                        artist=artist_user.first_name,
                        listing=self.listing.title,
                        user_id=self.artist_id,
                        metadata=self.listing_id,
                    ),
                )

                kwargs = {}

                if nb == 1:
                    kwargs["listing"] = self.listing
                    kwargs["artistname"] = self.artist.user.first_name
                    kwargs["when"] = self.start_time
                    send_email(case=12, receiver=notificated_user, **kwargs)
                elif nb == 2:
                    kwargs["artistname"] = self.artist.user.first_name
                    send_email(case=13, receiver=notificated_user, **kwargs)
                elif nb == 3:
                    kwargs["artistname"] = self.artist.user.first_name
                    kwargs["when"] = self.start_time
                    kwargs["listing_id"] = self.listing_id
                    send_email(case=13, receiver=notificated_user, **kwargs)

            elif cancelled_by == 2 and not old_status == self.status:

                profile_user = self.client.user
                artist_user = self.artist.user
                Notification.objects.create(
                    sender=profile_user,
                    receiver=artist_user,
                    time=current_time(),
                    short_text=NOTIFICATIONS_SHORT[4].format(user=profile_user.first_name),
                    long_text=NOTIFICATIONS_LONG[4].format(
                        user=profile_user.first_name,
                        listing=self.listing.title,
                        user_id=self.client_id,
                        metadata=self.listing_id,
                    ),
                )

                kwargs = {}
                # when user cancel an apoinment
                if old_status == 2:
                    delta_time = self.start_time - current_time()
                    kwargs["username"] = profile_user.first_name
                    kwargs["when"] = self.start_time
                    kwargs["day_before"] = round(delta_time / 86400)
                    if delta_time > 150000:
                        send_email(case=14, receiver=artist_user, **kwargs)
                    else:
                        send_email(case=15, receiver=artist_user, **kwargs)
        else:
            super(Booking, self).save(force_insert, force_update)
            user = self.client.user
            Notification.objects.create(
                sender=user,
                receiver=self.artist.user,
                time=current_time(),
                short_text=NOTIFICATIONS_SHORT[0].format(user=user.first_name),
                long_text=NOTIFICATIONS_LONG[0].format(
                    user=user.first_name, listing=self.title, user_id=self.client_id, metadata=self.listing_id
                ),
            )
            kwargs = {}
            kwargs["listing"] = self.listing
            kwargs["username"] = user.first_name
            send_email(case=10, receiver=self.artist.user, **kwargs)
Exemplo n.º 15
0
    def save(self,
             force_insert=False,
             force_update=False,
             old_status=None,
             **kwargs):
        if self.id:
            cancelled_by = self.cancelled_by
            super(Booking, self).save(force_insert, force_update)
            print("start_function", cancelled_by, old_status, self.status)
            if cancelled_by == 1 and not old_status == self.status:
                '''The real tricky moment here is the notation for nb 1 - the booking is approved, 2 - rejected, 3 declined'''
                notificated_user = self.client.user
                artist_user = self.artist.user
                if self.status == 1:
                    nb = 1
                    cr = CancellationRate.objects.get(artist=self.artist)
                    cr.approved += 1
                    cr.save()
                elif self.status == 2:
                    if old_status == 0:
                        nb = 2
                    else:
                        nb = 3
                        cr = CancellationRate.objects.get(artist=self.artist)
                        cr.cancelled += 1
                        cr.save()

                Notification.objects.create(
                    sender=artist_user,
                    receiver=notificated_user,
                    time=current_time(),
                    short_text=NOTIFICATIONS_SHORT[nb].format(
                        artist=artist_user.first_name),
                    long_text=NOTIFICATIONS_LONG[nb].format(
                        artist=artist_user.first_name,
                        listing=self.listing.title,
                        user_id=self.artist_id,
                        metadata=self.listing_id),
                )

                kwargs = {}

                if nb == 1:
                    kwargs['listing'] = self.listing
                    kwargs['artistname'] = self.artist.user.first_name
                    kwargs['when'] = self.start_time
                    send_email(case=12, receiver=notificated_user, **kwargs)
                elif nb == 2:
                    kwargs['artistname'] = self.artist.user.first_name
                    send_email(case=13, receiver=notificated_user, **kwargs)
                elif nb == 3:
                    kwargs['artistname'] = self.artist.user.first_name
                    kwargs['when'] = self.start_time
                    kwargs['listing_id'] = self.listing_id
                    send_email(case=13, receiver=notificated_user, **kwargs)

            elif cancelled_by == 2 and not old_status == self.status:

                profile_user = self.client.user
                artist_user = self.artist.user
                Notification.objects.create(
                    sender=profile_user,
                    receiver=artist_user,
                    time=current_time(),
                    short_text=NOTIFICATIONS_SHORT[4].format(
                        user=profile_user.first_name),
                    long_text=NOTIFICATIONS_LONG[4].format(
                        user=profile_user.first_name,
                        listing=self.listing.title,
                        user_id=self.client_id,
                        metadata=self.listing_id),
                )

                kwargs = {}
                # when user cancel an apoinment
                if old_status == 2:
                    delta_time = self.start_time - current_time()
                    kwargs['username'] = profile_user.first_name
                    kwargs['when'] = self.start_time
                    kwargs['day_before'] = round(delta_time / 86400)
                    if delta_time > 150000:
                        send_email(case=14, receiver=artist_user, **kwargs)
                    else:
                        send_email(case=15, receiver=artist_user, **kwargs)
        else:
            super(Booking, self).save(force_insert, force_update)
            user = self.client.user
            Notification.objects.create(
                sender=user,
                receiver=self.artist.user,
                time=current_time(),
                short_text=NOTIFICATIONS_SHORT[0].format(user=user.first_name),
                long_text=NOTIFICATIONS_LONG[0].format(
                    user=user.first_name,
                    listing=self.title,
                    user_id=self.client_id,
                    metadata=self.listing_id),
            )
            kwargs = {}
            kwargs['listing'] = self.listing
            kwargs['username'] = user.first_name
            send_email(case=10, receiver=self.artist.user, **kwargs)
Exemplo n.º 16
0
def delete_artist(request, artist_id):
    artist = Artist.objects.select_related("salon").get(id=int(artist_id))
    listings = Listing.objects.filter(artist=artist)
    # the current time in seconds, so we can filter the booking by this
    now = current_time()
    bookings = Booking.objects.select_related(
        'artist', 'artist__user', 'client__user',
        'listing').filter(artist=artist, start_time__gt=now, status__in=[0, 1])

    # select all artist, assigned to this salon
    init_artists = Artist.objects.select_related('user').filter(
        ~Q(id=artist.id), salon=artist.salon)

    # If the salon have artists, and the artist have listings and bookings
    if listings and bookings and init_artists:
        data = []
        # for each booking, we should find the artist which are available... not a easy one to do
        for b in bookings:
            weekday = int(strftime('%w', gmtime(b.start_time)))
            # for each booking, we will have specific group of artists, which will be able to take the booking
            artist_to_submit = []
            # we need only the ids of the artists, os we can easiely and fast search for them
            artists = [a.id for a in init_artists]

            # check if the artist work in this day. Currently we'll ignore the fact that the time could be not in his worktime
            days = [
                'mon_start', 'tues_start', 'wed_start', 'thurs_start',
                'fri_start', 'sat_start', 'sun_start'
            ]
            kwargs = {days[weekday]: -1}
            work_time = WorkTime.objects.filter(artist_id__in=artists).exclude(
                **kwargs)
            artists = [a.artist_id for a in work_time]

            # check if he is busy, during the time of the booking
            busy_hours = Busy.objects.filter(artist_id__in=artists).exclude(
                Q(end_time__lt=b.start_time) | Q(start_time__gt=b.end_time))

            sub_artists = [a.artist_id for a in busy_hours]
            artists = [a for a in artists if a not in sub_artists]
            # check for other booking during this time
            temp_booking = Booking.objects.filter(
                artist_id__in=artists).exclude(
                    Q(end_time__lt=b.start_time)
                    | Q(start_time__gt=b.end_time))

            sub_artists = [a.artist_id for a in temp_booking]
            artists = [a for a in artists if a not in sub_artists]

            artists = Artist.objects.select_related("user").filter(
                id__in=artists)
            for a in artists:
                artist_to_submit.append(a)
            data.append({"data": b, "artists": artist_to_submit[:]})

        return render(request, 'salons/delete_artist.html', {
            "artist": artist,
            "bookings": data
        })


# If the artist doesn't have any bookings
    else:
        for l in listings:
            l.status = 2
            l.save()

        salon_user = artist.salon.user
        artist.salon = None
        artist.save()
        user = artist.user
        messages.add_message(
            request, messages.INFO,
            _('{0} is removed successfully from your salon.').format(
                user.first_name))
        accept_suspend_request(user, salon_user)
        return HttpResponseRedirect(reverse('salons_artists'))