Ejemplo n.º 1
0
def profile(request, artist_id=None, name=None):

    is_sub = False
    is_follower = None
    profiles = []
    user = request.user

    if not artist_id:
        artist = get_object_or_404(Artist, user__id=user.id)
    else:
        artist = get_object_or_404(Artist, id=artist_id)
        try:
            if user.salon:
                if artist.salon == user.salon:
                    is_sub = True
        except:
            is_sub = False

    listings = Listing.objects.filter(artist=artist, status=1)

    if user.is_authenticated():
        is_follower = get_object_or_None(Followers, user=user, artist=artist)

        if request.GET.get('followed', None) == '1' and not is_follower:
            is_follower = Followers.objects.create(artist=artist, user=user)
            start_following(user, artist.user)
        elif request.GET.get('followed', None) == '0' and is_follower:
            follower = Followers.objects.get(artist=artist, user=user)
            follower.delete()
    followers = Followers.objects.select_related().filter(artist=artist)
    followers = list(followers)
    for follower in followers:
        if follower.user.related_with == 'profiles':
            profiles.append(follower.user.profile)
        elif follower.user.related_with == 'artists':
            profiles.append(follower.user.artist)
        else:
            profiles.append(follower.user.salon)

    reviews = Review.objects.filter(artist=artist)
    rate = get_rate(reviews)

    work_time = get_object_or_None(WorkTime, artist=artist)
    return render(
        request, 'artists/profile.html', {
            'artist': artist,
            'listings': listings,
            'reviews': reviews,
            'rate': rate,
            'is_follower': is_follower,
            'is_sub': is_sub,
            'profiles': profiles,
            'work_time': work_time,
        })
Ejemplo n.º 2
0
def profile(request, artist_id=None, name=None):

    is_sub = False
    is_follower = None
    profiles = []
    user = request.user

    if not artist_id:
        artist = get_object_or_404(Artist, user__id=user.id)
    else:
        artist = get_object_or_404(Artist, id=artist_id)
        try:
            if user.salon:
                if artist.salon == user.salon:
                    is_sub = True
        except:
            is_sub = False

    listings = Listing.objects.filter(artist=artist, status=1)

    if user.is_authenticated():
        is_follower = get_object_or_None(Followers, user=user, artist=artist)

        if request.GET.get('followed', None) == '1' and not is_follower:
                is_follower = Followers.objects.create(artist=artist, user=user)
                start_following(user, artist.user)
        elif request.GET.get('followed', None) == '0' and is_follower:
            follower = Followers.objects.get(artist=artist, user=user)
            follower.delete()
    followers = Followers.objects.select_related().filter(artist=artist)
    followers = list(followers)
    for follower in followers:
        if follower.user.related_with == 'profiles':
            profiles.append(follower.user.profile)
        elif follower.user.related_with == 'artists':
            profiles.append(follower.user.artist)
        else:
            profiles.append(follower.user.salon)

    reviews = Review.objects.filter(artist=artist)
    rate = get_rate(reviews)

    work_time = get_object_or_None(WorkTime, artist=artist)
    return render(request, 'artists/profile.html', {
        'artist': artist,
        'listings': listings,
        'reviews': reviews,
        'rate': rate,
        'is_follower': is_follower,
        'is_sub': is_sub,
        'profiles': profiles,
        'work_time': work_time,
    })
Ejemplo n.º 3
0
def profile(request, salon_id=None, name=None):
    if salon_id:
        salon = get_object_or_404(Salon, id=salon_id)
    else:
        user = request.user
        salon = get_object_or_404(Salon, user__id=user.id)

    listings = []

    _artists = Artist.objects.select_related("user").filter(salon=salon, is_activated=True, waiting_for_hired=False)
    artists = [a.id for a in _artists]
    listings = Listing.objects.filter(artist_id__in=artists, status=1)
    reviews = Review.objects.filter(artist_id__in=artists)
    rating = get_rate(reviews)
    return render(
        request,
        "salons/profile.html",
        {"salon": salon, "artists": _artists, "reviews": reviews, "rating": rating, "listings": listings},
    )
Ejemplo n.º 4
0
def profile(request, salon_id=None, name=None):
    if salon_id:
        salon = get_object_or_404(Salon, id=salon_id)
    else:
        user = request.user
        salon = get_object_or_404(Salon, user__id=user.id)

    listings = []

    _artists = Artist.objects.select_related("user").filter(
        salon=salon, is_activated=True, waiting_for_hired=False)
    artists = [a.id for a in _artists]
    listings = Listing.objects.filter(artist_id__in=artists, status=1)
    reviews = Review.objects.filter(artist_id__in=artists)
    rating = get_rate(reviews)
    return render(
        request, 'salons/profile.html', {
            'salon': salon,
            'artists': _artists,
            'reviews': reviews,
            'rating': rating,
            'listings': listings
        })
Ejemplo n.º 5
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})
Ejemplo n.º 6
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
        })
Ejemplo n.º 7
0
 def get_rating(self):
     from glamazer.reviews.models import Review
     reviews = Review.objects.select_related().filter(listing=self)
     rate = get_rate(reviews)
     return rate
Ejemplo n.º 8
0
 def get_rating(self):
     from glamazer.reviews.models import Review
     reviews = Review.objects.select_related().filter(listing=self)
     rate = get_rate(reviews)
     return rate