def noticia_nueva(request): unsigned = request.GET.get("unsigned") == "true" if (unsigned): # For the sake of simplicity of the sample site, we generate the preset on the fly. It only needs to be created once, in advance. try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset(name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( # Form demonstrating backend upload backend_form = PhotoForm(), # Form demonstrating direct upload direct_form = direct_form, # Should the upload form be unsigned unsigned = unsigned, ) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) if request.method == "POST": form = NoticiaForm(request.POST, request.FILES) context['posted'] = form.instance if form.is_valid(): post = form.save() post.imagen = post.image.url post.save() return redirect('noticias.views.noticia_detail', pk=post.pk) else: form = NoticiaForm() return render(request, 'noticias/post_edit.html', {'form': form, 'tipo' : 'Noticia'})
def upload(request): unsigned = request.GET.get("unsigned") == "true" if (unsigned): # For the sake of simplicity of the sample site, we generate the preset on the fly. It only needs to be created once, in advance. try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset(name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( # Form demonstrating backend upload backend_form = PhotoForm(), # Form demonstrating direct upload direct_form = direct_form, # Should the upload form be unsigned unsigned = unsigned, ) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) if request.method == 'POST': # Only backend upload should be posting here form = PhotoForm(request.POST, request.FILES) context['posted'] = form.instance if form.is_valid(): # Uploads image and creates a model instance for it form.save() return render(request, 'noticias/upload.html', context)
def cloudinary_direct_upload_field(field_name="image", request=None): form = type("OnTheFlyForm", (Form,), {field_name: CloudinaryJsFileField()})() if request: cl_init_js_callbacks(form, request) value = form[field_name] if not PY3: value = unicode(value) return value
def upload(request): direct_form = FeedDirectForm() context = dict( direct_form=direct_form, ) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) return render(request, 'upload.html', context)
def upload(request, object_id): """View for uploading new photo resource to cloudinary and creating model""" user = request.user character = get_character_from_ob(object_id) if not user.is_authenticated() or (user.char_ob != character and not user.is_staff): raise Http404("You are not permitted to upload to this gallery.") unsigned = request.GET.get("unsigned") == "true" if unsigned: # For the sake of simplicity of the sample site, we generate the preset on the fly. # It only needs to be created once, in advance. try: api.upload_preset(PhotoUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset(name=PhotoUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = PhotoUnsignedDirectForm() if unsigned else PhotoDirectForm() context = dict( # Form demonstrating backend upload backend_form=PhotoForm(), # Form demonstrating direct upload direct_form=direct_form, # Should the upload form be unsigned unsigned=unsigned, ) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) context['character'] = character context['page_title'] = 'Upload' if request.method == 'POST': # Only backend upload should be posting here owner_char = Photo(owner=character) form = PhotoForm(request.POST, request.FILES, instance=owner_char) context['posted'] = False if form.is_valid(): # Uploads image and creates a model instance for it if user.is_authenticated() and user.check_permstring("builders"): context['show_hidden'] = True context['posted'] = form.instance form.save() return render(request, 'character/upload.html', context)
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)
def upload(request): unsigned = request.GET.get("unsigned") == "true" if (unsigned): # For the sake of simplicity of the sample site, we generate the preset on the fly. It only needs to be created once, in advance. try: api.upload_preset(ImageUnsignedDirectForm.upload_preset_name) except api.NotFound: api.create_upload_preset(name=ImageUnsignedDirectForm.upload_preset_name, unsigned=True, folder="preset_folder") direct_form = ImageUnsignedDirectForm() if unsigned else ImageDirectForm() context = dict( # Form demonstrating backend upload backend_form=DocImageForm(), # Form demonstrating direct upload direct_form=direct_form, # Should the upload form be unsigned unsigned=unsigned, ) # When using direct upload - the following call is necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) instance = Document.objects.create() if request.method == 'POST': # Only backend upload should be posting here form = DocImageForm(request.POST, request.FILES, instance=instance) context['posted'] = form.instance if form.is_valid(): # Uploads image and creates a model instance for it from library.logger import create_log create_log(request, "Created", instance) form.save() return redirect('document') instance.delete() return render(request, 'upload.html', context)
def upload(request, pk=None): instance = Photo.objects.get(pk=pk) if pk else None context = dict(save_pk = pk or "") if request.method == 'POST': # Only backend upload should be posting here context['backend_form'] = form = PhotoForm(request.POST, request.FILES, instance=instance) if form.is_valid(): # Uploads image and creates a model instance for it context['posted'] = form.save() instance = Photo.objects.get(pk=pk) if pk else None else: # Form demonstrating backend upload context['backend_form'] = PhotoForm(instance=instance) # Form demonstrating direct upload context['direct_form'] = PhotoDirectForm(instance=instance) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) return render(request, 'upload.html', context)
def upload(request, pk=None): instance = Photo.objects.get(pk=pk) if pk else None context = dict(save_pk=pk or "") if request.method == 'POST': # Only backend upload should be posting here context['backend_form'] = form = PhotoForm(request.POST, request.FILES, instance=instance) if form.is_valid(): # Uploads image and creates a model instance for it context['posted'] = form.save() instance = Photo.objects.get(pk=pk) if pk else None else: # Form demonstrating backend upload context['backend_form'] = PhotoForm(instance=instance) # Form demonstrating direct upload context['direct_form'] = PhotoDirectForm(instance=instance) # When using direct upload - the following call in necessary to update the # form's callback url cl_init_js_callbacks(context['direct_form'], request) return render(request, 'upload.html', context)
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
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
def upload_prompt(request): context = dict(direct_form = PostPhotoDirectForm()) cl_init_js_callbacks(context['direct_form'], request) return render(request, 'blog/post_new.html', context)
def upload_prompt(request): context = dict(direct_form=PhotoForm()) cl_init_js_callbacks(context['direct_form'], request) return render(request, 'upload_prompt.html', context)
def cloudinary_direct_upload_field(field_name="image", request=None): form = type("OnTheFlyForm", (Form, ), {field_name: CloudinaryJsFileField()})() if request: cl_init_js_callbacks(form, request) return unicode(form[field_name])