コード例 #1
0
ファイル: views.py プロジェクト: SpeeDly/glamfame
def upload(request):
    artist = request.user.artist

    if request.method == 'POST':
        fee = get_fee(artist)
        form = UploadListing(request.POST, request=request)
        if form.is_valid():
            listing = form.save(artist, request.POST)
            messages.add_message(request, messages.INFO,
                _("Your listing %s has been successfully created and submitted for review. Your listing will go live within the next couple of hours.") % listing.title)
            return HttpResponseRedirect(reverse('all_listing'))

    else:
        form = UploadListing()
        fee = get_fee(artist)

    return render(request, 'artists/upload.html', {'artist': artist, "form": form, "fee": fee})
コード例 #2
0
    def save(self, FILES):

        data = self.cleaned_data
        artist = Artist.objects.get(id=int(data['artist']))
        artist_id = str(data['artist'])
        pictures = FILES.getlist('files')
        hash_name = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for x in range(6))
        for index, picture in enumerate(pictures):

            dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$')
            my_file = dataUrlPattern.match(picture).group(2)

            path = '/' + MEDIA_FOLDER + '/artists/' + artist_id + '/listings/' + hash_name + '/'
            if index == int(data["cover"]):
                full_path = MEDIA_ROOT + 'artists/' + artist_id + '/listings/' + hash_name + '/' + str(
                    index) + '.jpeg'
                cover = full_path
            else:
                full_path = MEDIA_ROOT + 'artists/' + artist_id + '/listings/' + hash_name + '/' + str(
                    index) + '.jpeg'

            #if the folder doesn't exist, create one
            d = os.path.dirname(full_path)
            if not os.path.exists(d):
                os.makedirs(d)

            im = Image.open(BytesIO(base64.b64decode(my_file.encode('ascii'))))
            im.save(full_path, 'JPEG')

        price = math.ceil(int(data['price']) * (1 + (get_fee() / 100)))

        listing = Listing.objects.create(artist=artist,
                                         picture=path,
                                         title=data['title'],
                                         description=data['description'],
                                         picture_cover=cover,
                                         original_price=data['price'],
                                         price=price,
                                         metadata=hash_name,
                                         gender=data['gender'],
                                         duration=int(data['duration']))

        tags = data['tags'].split(',')
        tags.append(artist.get_style_display())
        for tag in tags:
            tag = tag.lower()
            current_tag = get_object_or_None(Tags, tag=tag)
            if not current_tag:
                current_tag = Tags.objects.create(tag=tag)

            ListingTags.objects.create(listing=listing, tags=current_tag)
        listing.save()

        return [listing, artist]
コード例 #3
0
ファイル: forms.py プロジェクト: SpeeDly/glamfame
    def save(self, artist, FILES):
        data = self.cleaned_data
        artist_id = str(artist.id)
        pictures = FILES.getlist('files')
        hash_name = ''.join(random.choice(string.ascii_lowercase + string.digits)for x in range(6))

        for index, picture in enumerate(pictures):

            dataUrlPattern = re.compile('data:image/(png|jpeg);base64,(.*)$')
            my_file = dataUrlPattern.match(picture).group(2)

            path = '/' + MEDIA_FOLDER + '/artists/' + artist_id + '/listings/' + hash_name + '/'
            if index == int(data["cover"]):
                full_path = MEDIA_ROOT + 'artists/' + artist_id + '/listings/' + hash_name + '/' + str(index) + '.jpeg'
                cover = full_path
            else:
                full_path = MEDIA_ROOT + 'artists/' + artist_id + '/listings/' + hash_name + '/' + str(index) + '.jpeg'

            #if the folder doesn't exist, create one
            d = os.path.dirname(full_path)
            if not os.path.exists(d):
                os.makedirs(d)

            im = Image.open(BytesIO(base64.b64decode(my_file.encode('ascii'))))
            im.save(full_path, 'JPEG')

        price = math.ceil(int(data['price'])*(1 + (get_fee(artist)/100)))

        listing = Listing.objects.create(
            artist=artist,
            picture=path,
            title=data['title'],
            description=data['description'],
            picture_cover=cover,
            original_price=data['price'],
            price=price,
            metadata=hash_name,
            gender=data['gender'],
            duration=int(data['duration']),
        )

        tags = data['tags'].split(',')
        tags.append(artist.get_style_display())
        for tag in tags:
            tag = tag.lower()
            current_tag = get_object_or_None(Tags, tag=tag)
            if not current_tag:
                current_tag = Tags.objects.create(tag=tag)

            ListingTags.objects.create(listing=listing, tags=current_tag)
        listing.save()
        return listing
コード例 #4
0
def upload(request):
    artist = request.user.artist

    if request.method == 'POST':
        fee = get_fee(artist)
        form = UploadListing(request.POST, request=request)
        if form.is_valid():
            listing = form.save(artist, request.POST)
            messages.add_message(
                request, messages.INFO,
                _("Your listing %s has been successfully created and submitted for review. Your listing will go live within the next couple of hours."
                  ) % listing.title)
            return HttpResponseRedirect(reverse('all_listing'))

    else:
        form = UploadListing()
        fee = get_fee(artist)

    return render(request, 'artists/upload.html', {
        'artist': artist,
        "form": form,
        "fee": fee
    })
コード例 #5
0
ファイル: views.py プロジェクト: SpeeDly/glamfame
def upload(request):
    salon = request.user.salon

    if request.method == "POST":
        form = UploadListing(salon, request.POST, request=request)
        fee = get_fee()

        if form.is_valid():
            listing = form.save(request.POST)[0]
            messages.add_message(
                request,
                messages.INFO,
                _(
                    "Your listing %s has been successfully created and submitted for review. Your listing will go live within the next couple of hours."
                )
                % listing.title,
            )
            return HttpResponseRedirect(reverse("salons_listings"))

    else:
        form = UploadListing(salon)
        fee = get_fee()
    return render(request, "salons/upload.html", {"salon": salon, "form": form, "fee": fee})
コード例 #6
0
def upload(request):
    salon = request.user.salon

    if request.method == 'POST':
        form = UploadListing(salon, request.POST, request=request)
        fee = get_fee()

        if form.is_valid():
            listing = form.save(request.POST)[0]
            messages.add_message(
                request, messages.INFO,
                _("Your listing %s has been successfully created and submitted for review. Your listing will go live within the next couple of hours."
                  ) % listing.title)
            return HttpResponseRedirect(reverse('salons_listings'))

    else:
        form = UploadListing(salon)
        fee = get_fee()
    return render(request, 'salons/upload.html', {
        'salon': salon,
        "form": form,
        "fee": fee
    })