Exemple #1
0
def edit_account(request, user_type):
    context = {}

    user_form = EditUserForm(request.POST or None,
                             instance=request.user,
                             label_suffix="")

    if user_type == "Designer":
        abstract_user_form = EditDesignerForm(request.POST or None,
                                              instance=request.user.designer,
                                              label_suffix="")
    else:
        abstract_user_form = EditBuyerForm(request.POST or None,
                                           instance=request.user.buyer,
                                           label_suffix="")

    if request.method == "POST":
        if user_form.is_valid() and abstract_user_form.is_valid():

            # save forms if valid
            user = user_form.save()
            abstract_user = abstract_user_form.save(commit=False)

            # rename avatar link to a folder
            if request.POST.get("avatar") is not None:
                avatar_link = request.user.username
                avatar_link = photo_rename(avatar_link,
                                           [request.POST.get("avatar")])[0]
                abstract_user.avatar = avatar_link

            abstract_user.save()

            # save the tags
            abstract_user_form.save_m2m()

            context['changes_saved'] = "Changes saved."

    context['user_form'] = user_form
    context['abstract_user_form'] = abstract_user_form
    context['action'] = request.path
    cl_init_js_callbacks(context['abstract_user_form'], request)

    return render(request, "Users/edit_account.html", context)
Exemple #2
0
def create_collection(request, username):
    error = None
    if request.user.username == username:
        collection_form = CreateCollection(request.POST or None)
        if request.method == "POST":
            if collection_form.is_valid():
                collection = collection_form.save(commit=False)
                collection.designer = request.user.designer

                try:
                    collection.save()
                    collection_form.save_m2m()
                except IntegrityError:
                    error = "Sorry! You are already using this title for another collection"

                # photos
                folder_link = "%s/%s" % (username, collection.pk)
                photos = request.POST.getlist("images")
                pieces = photo_rename(folder_link, photos)

                for piece in pieces:
                    Piece.objects.create(collection_id=collection.pk,
                                         front_view=piece)

                if not error:
                    slug = slugify(collection.title)
                    return HttpResponseRedirect(
                        reverse('Portfolios:create_linesheet',
                                args=(username, collection.pk, slug)))

        context = {"collection_form": collection_form, "error": error or None}

        cl_init_js_callbacks(context['collection_form'], request)
        return render(request, "Portfolios/create_collection.html", context)
    else:
        raise Http404
Exemple #3
0
def create_collection(request, username):
    error = None
    if request.user.username == username:
        collection_form = CreateCollection(request.POST or None)
        if request.method =="POST":
            if collection_form.is_valid():
                collection = collection_form.save(commit=False)
                collection.designer = request.user.designer

                try:
                    collection.save()
                    collection_form.save_m2m()
                except IntegrityError:
                    error = "Sorry! You are already using this title for another collection"

                # photos
                folder_link = "%s/%s" % (username, collection.pk)
                photos = request.POST.getlist("images")
                pieces = photo_rename(folder_link, photos)

                for piece in pieces:
                    Piece.objects.create(collection_id=collection.pk, front_view=piece)

                if not error:
                    slug = slugify(collection.title)
                    return HttpResponseRedirect(reverse('Portfolios:create_linesheet', args=(username, collection.pk, slug)))
            
        context = {
            "collection_form":collection_form,
            "error":error or None
        }

        cl_init_js_callbacks(context['collection_form'], request)
        return render(request, "Portfolios/create_collection.html", context)
    else:
        raise Http404
Exemple #4
0
def edit_account(request, user_type):
    context = {}

    user_form = EditUserForm(request.POST or None, instance=request.user, label_suffix="")
    
    if user_type == "Designer":
        abstract_user_form = EditDesignerForm(request.POST or None, instance=request.user.designer, label_suffix="")
    else:
        abstract_user_form = EditBuyerForm(request.POST or None, instance=request.user.buyer, label_suffix="")
    
    if request.method == "POST":
        if user_form.is_valid() and abstract_user_form.is_valid():

            # save forms if valid
            user = user_form.save()
            abstract_user = abstract_user_form.save(commit=False)

            # rename avatar link to a folder
            if request.POST.get("avatar") is not None:
                avatar_link = request.user.username
                avatar_link = photo_rename(avatar_link, [request.POST.get("avatar")])[0]
                abstract_user.avatar = avatar_link

            abstract_user.save()
            
            # save the tags
            abstract_user_form.save_m2m()

            context['changes_saved'] = "Changes saved."

    context['user_form'] = user_form
    context['abstract_user_form'] = abstract_user_form
    context['action'] = request.path
    cl_init_js_callbacks(context['abstract_user_form'], request)

    return render(request, "Users/edit_account.html", context)