Exemplo n.º 1
0
def facebook_login(request):
    data = request.POST
    is_user = get_object_or_None(User, email=data['email'])
    if is_user:
        if is_user.first_name == "anonymous":
            is_user.first_name = data['name']
            is_user.facebook_id = data['facebook_id']
            is_user.save()
            profile = is_user.profile
            hash_name = ''.join(
                random.choice(string.ascii_lowercase + string.digits)
                for x in range(10))
            path = MEDIA_URL + 'users/' + str(
                profile.id) + '/avatar/' + hash_name + '.jpeg'
            full_path = MEDIA_ROOT + 'users/' + str(
                profile.id) + '/avatar/' + hash_name + '.jpeg'
            d = os.path.dirname(full_path)
            if not os.path.exists(d):
                os.makedirs(d)
            else:
                shutil.rmtree(d)
                os.makedirs(d)
            urllib.request.urlretrieve(data['avatar'], full_path)
            profile.avatar = path
            profile.save()
            login_user(request, is_user)
        else:
            login_user(request, is_user)

        return HttpResponse(simplejson.dumps("COMPLETE"),
                            content_type="application/json")
    else:
        raise Exception("Not registered")
Exemplo n.º 2
0
def facebook_login(request):
    data = request.POST
    is_user = get_object_or_None(User, email=data['email'])
    if is_user:
        if is_user.first_name == "anonymous":
            is_user.first_name = data['name']
            is_user.facebook_id =  data['facebook_id']
            is_user.save()
            profile = is_user.profile
            hash_name = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(10))
            path = MEDIA_URL + 'users/' + str(profile.id) + '/avatar/' + hash_name + '.jpeg'
            full_path = MEDIA_ROOT + 'users/' + str(profile.id) + '/avatar/' + hash_name + '.jpeg'
            d = os.path.dirname(full_path)
            if not os.path.exists(d):
                os.makedirs(d)
            else:
                shutil.rmtree(d)
                os.makedirs(d)
            urllib.request.urlretrieve(data['avatar'], full_path)
            profile.avatar = path
            profile.save()
            login_user(request, is_user)
        else:
            login_user(request, is_user)


        return HttpResponse(simplejson.dumps("COMPLETE"), content_type="application/json")
    else:
        raise Exception("Not registered")
Exemplo n.º 3
0
def receive_review(request, email_token):
    token = get_object_or_404(WaitingForFeedback, token=email_token)

    if request.method == 'POST':
        data = request.POST
        text = data['text']
        rate = data['rate']
        r = Review.objects.create(client_id=token.client_id,
                                  artist_id=token.artist_id,
                                  listing_id=token.listing_id,
                                  booking_id=token.booking_id,
                                  rating=rate,
                                  text=text)
        r.save()

        listing = token.listing
        print(type(listing.comments))
        listing.comments = int(listing.comments) + 1
        listing.save()

        token.delete()
        return redirect("/")

    profile = token.client
    # token.delete()
    artist = token.artist
    login_user(request, profile.user)

    return render(request, 'review/receive.html', {'artist': artist})
Exemplo n.º 4
0
def receive_review(request, email_token):
    token = get_object_or_404(WaitingForFeedback, token=email_token)

    if request.method == 'POST':
        data = request.POST
        text = data['text']
        rate = data['rate']
        r = Review.objects.create(
            client_id=token.client_id,
            artist_id=token.artist_id,
            listing_id=token.listing_id,
            booking_id=token.booking_id,
            rating=rate,
            text=text
            )
        r.save()
        user_review(token.client.user, token.artist, token.listing)
        listing = token.listing
        listing.comments = int(listing.comments) + 1
        listing.save()

        token.delete()
        return redirect("/")

    profile = token.client
    # token.delete()
    artist = token.artist
    login_user(request, profile.user)

    return render(request, 'review/receive.html', {'artist': artist})
Exemplo n.º 5
0
def facebook_registration(request):
    data = request.POST

    password = "".join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))

    is_user = get_object_or_None(User, email=data["email"])

    if not is_user:
        username = "".join(random.choice(string.ascii_lowercase + string.digits) for x in range(16))
        new_user = User.objects.create_user(
            username=username, first_name=data["name"], email=data["email"], password=password, related_with="salons"
        )
        salon = Salon.objects.create(user=new_user, facebook_id=data["facebook_id"], step=2)
        ReceiverAccount.objects.create(user=new_user, paypal_email=new_user.email)

        hash_name = "".join(random.choice(string.ascii_lowercase + string.digits) for x in range(10))
        path = "/" + MEDIA_FOLDER + "/salons/" + str(salon.id) + "/avatar/" + hash_name + ".jpeg"
        full_path = MEDIA_ROOT + "salons/" + str(salon.id) + "/avatar/" + hash_name + ".jpeg"
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data["avatar"], full_path)

        salon.avatar = path
        salon.save()

        welcome(None, new_user, password)

        login_user(request, new_user)
    else:
        raise Exception(_("Not registered"))
Exemplo n.º 6
0
def facebook_registration(request):
    data = request.POST

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

    is_user = get_object_or_None(User, email=data['email'])
    if not is_user:
        username = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(16))
        new_user = User.objects.create_user(username=username,
                                            first_name=data['name'],
                                            email=data['email'],
                                            password=password,
                                            related_with="profiles")
        profile = Profile.objects.create(user=new_user, facebook_id=data['facebook_id'], is_activated=True)

        hash_name = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(10))
        path = '/' + MEDIA_FOLDER + '/users/' + str(profile.id) + '/avatar/' + hash_name + '.jpeg'
        full_path = MEDIA_ROOT + 'users/' + str(profile.id) + '/avatar/' + hash_name + '.jpeg'
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data['avatar'], full_path)

        profile.avatar = path
        profile.save()
        kwargs = {}
        kwargs['password'] = password
        welcome(None, new_user, password)

        login_user(request, new_user)
    else:
        raise Exception("Not registered")
Exemplo n.º 7
0
def confirmation(request, email_token):
    token = get_object_or_404(ConfirmationToken, email_token=email_token)

    if token:
        profile = token.user.profile

        if not profile.is_activated:
            profile.is_activated = True
            profile.save()
            token.delete()
            login_user(request, profile.user)
            return HttpResponseRedirect(reverse('user_settings'))

    return HttpResponseRedirect(reverse('home'))
Exemplo n.º 8
0
def confirmation(request, email_token):
    token = get_object_or_404(ConfirmationToken, email_token=email_token)

    if token:
        profile = token.user.profile

        if not profile.is_activated:
            profile.is_activated = True
            profile.save()
            token.delete()
            login_user(request, profile.user)
            return HttpResponseRedirect(reverse('user_settings'))

    return HttpResponseRedirect(reverse('home'))
Exemplo n.º 9
0
def facebook_registration(request):
    data = request.POST

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

    is_user = get_object_or_None(User, email=data['email'])

    if not is_user:
        username = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(16))
        new_user = User.objects.create_user(username=username,
                                            first_name=data['name'],
                                            email=data['email'],
                                            password=password,
                                            related_with="artists")
        artist = Artist.objects.create(user=new_user,
                                       facebook_id=data['facebook_id'],
                                       step=2)
        ReceiverAccount.objects.create(user=new_user,
                                       paypal_email=new_user.email)
        WorkTime.objects.create(artist=artist)

        hash_name = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(10))
        path = '/' + MEDIA_FOLDER + '/artists/' + str(
            artist.id) + '/avatar/' + hash_name + '.jpeg'
        full_path = MEDIA_ROOT + 'artists/' + str(
            artist.id) + '/avatar/' + hash_name + '.jpeg'
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data['avatar'], full_path)

        artist.avatar = path
        artist.save()
        kwargs = {}
        kwargs['password'] = password
        send_email(case=3, receiver=new_user, **kwargs)

        login_user(request, new_user)
    else:
        raise Exception("Not registered")
Exemplo n.º 10
0
def facebook_registration(request):
    data = request.POST

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

    is_user = get_object_or_None(User, email=data['email'])

    if not is_user:
        username = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(16))
        new_user = User.objects.create_user(username=username,
                                            first_name=data['name'],
                                            email=data['email'],
                                            password=password,
                                            related_with="salons")
        salon = Salon.objects.create(user=new_user,
                                     facebook_id=data['facebook_id'],
                                     step=2)
        ReceiverAccount.objects.create(user=new_user,
                                       paypal_email=new_user.email)

        hash_name = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(10))
        path = '/' + MEDIA_FOLDER + '/salons/' + str(
            salon.id) + '/avatar/' + hash_name + '.jpeg'
        full_path = MEDIA_ROOT + 'salons/' + str(
            salon.id) + '/avatar/' + hash_name + '.jpeg'
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data['avatar'], full_path)

        salon.avatar = path
        salon.save()

        welcome(None, new_user, password)

        login_user(request, new_user)
    else:
        raise Exception(_("Not registered"))
Exemplo n.º 11
0
def facebook_registration(request):
    data = request.POST

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

    is_user = get_object_or_None(User, email=data['email'])

    if not is_user:
        username = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(16))
        new_user = User.objects.create_user(
            username = username,
            first_name = data['name'],
            email = data['email'], 
            password = password,
            related_with = "artists"
            )
        artist = Artist.objects.create(user=new_user, facebook_id=data['facebook_id'], step=2)
        ReceiverAccount.objects.create(user=new_user, paypal_email=new_user.email)
        WorkTime.objects.create(artist=artist)

        hash_name = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(10))
        path = MEDIA_URL + 'artists/' + str(artist.id) + '/avatar/' + hash_name + '.jpeg'
        full_path = MEDIA_ROOT + 'artists/' + str(artist.id) + '/avatar/' + hash_name + '.jpeg'
        d = os.path.dirname(full_path)
        if not os.path.exists(d):
            os.makedirs(d)
        else:
            shutil.rmtree(d)
            os.makedirs(d)
        urllib.request.urlretrieve(data['avatar'], full_path)
        
        artist.avatar = path
        artist.save()
        kwargs = {}
        kwargs['password'] = password
        send_email(case=3, receiver=new_user, **kwargs)

        login_user(request, new_user)
    else:
        login_user(request, is_user)

    return HttpResponseRedirect(reverse('home'))
Exemplo n.º 12
0
def sign_up(request):
    request.session.flush()
    if request.method == "POST":

        user_form = ProfileForm(request.POST)

        if user_form.is_valid():
            profile = user_form.save()
            data = user_form.cleaned_data
            user = authenticate(email=data['email'], password=data['password'])

            if user is not None and user.is_active:
                login_user(request, profile.user)
                return redirect("/")
                # send_email(case=0, receiver=user)
                # messages.add_message(request, messages.INFO,
                #                      'Registration complete. Please check your e-mail to activate your account.')
    else:
        user_form = ProfileForm()

    return render(request, 'user/sign_up.html', {'user_form': user_form})
Exemplo n.º 13
0
def sign_up(request):
    request.session.flush()
    if request.method == "POST":

        user_form = ProfileForm(request.POST)

        if user_form.is_valid():
            profile = user_form.save()
            data = user_form.cleaned_data
            user = authenticate(
                email=data['email'], password=data['password'])

            if user is not None and user.is_active:
                login_user(request, profile.user)
                return redirect("/")
                # send_email(case=0, receiver=user)
                # messages.add_message(request, messages.INFO,
                #                      'Registration complete. Please check your e-mail to activate your account.')
    else:
        user_form = ProfileForm()

    return render(request, 'user/sign_up.html', {'user_form': user_form})
Exemplo n.º 14
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.º 15
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
        })