def persistRSS(): rss = memcache.get("rss_content") if rss: gallery = Gallery.all().order('-updated_at').get() if gallery is None: gallery = Gallery(name="all") gallery.xml = rss gallery.put()
def gallery_add(request, project_id): if request.GET.get('ignore'): return HttpResponse('') project = Project.objects.get(id=project_id) gallery = Gallery(project=project, title=request.META['HTTP_X_GALLERY_TITLE'], created=request.user) gallery.save() return HttpResponse('/projects/%s/stockphoto/%s' % (str(project_id), str(gallery.id)))
def setUp(self): self.client.login(username='******', password='******') # Set up test Picture and Gallery. # These must be set up here instead of in fixtures in order to allow Picture # to use a NamedTemporaryFile. tdir = tempfile.gettempdir() file1 = tempfile.NamedTemporaryFile(suffix=".file1", dir=tdir) file1.write('a' * (2 ** 21)) filename = file1.name file1.close() g = Gallery(name="Test Gallery") g.save() p = Picture(name="Test Picture", image=filename, gallery=g) p.save()
def enter_gallery(self, instance): galleryinfo = [ instance.gallery_id, instance.gallery_token, instance.pagecount, instance.gallery_name, instance.gallery_tags, instance.gallery_thumb, instance.filesize ] existgallery = db.query(Gallery).filter_by( gallery_id=instance.gallery_id).first() if existgallery: pass else: gallery = Gallery(gallery_id=instance.gallery_id, gallery_token=instance.gallery_token, pagecount=instance.pagecount, gallery_name=instance.gallery_name, gallery_thumb=instance.gallery_thumb, filesize=instance.filesize) db.add(gallery) db.commit() for tag in instance.gallery_tags: gallerytag = GalleryTags(galleryid=gallery.id, tag=tag) db.add(gallerytag) db.commit() preview_screen = App.get_running_app( ).root.ids.sadpanda_screen_manager.get_screen("gallery_preview_screen") preview_screen.gallery_id = instance.gallery_id App.get_running_app().root.next_screen("gallery_preview_screen")
def gallery_uploader(request): """ uploads image to google cloud storage stores some metadata in DB Args: None Returns: None """ email = request.user.email if request.method == 'POST': imageupload = GalleryForm(request.POST, request.FILES) if imageupload.is_valid(): u = imageupload.save(commit=False) uploaded_file = request.FILES['image'] content_type = request.FILES['image'].content_type name = request.FILES['image'].name data = uploaded_file.read() gcs_file = gcs.open( ('/' + bucket_name + '/' + name), mode = 'w', content_type = content_type, options = { 'x-goog-acl': 'bucket-owner-full-control' } ) gcs_file.write(data) gcs_file.close() #get_serving_url blob_key = blobstore.create_gs_key( '/gs/' + bucket_name + '/' + name ) serving_url = get_serving_url(blob_key) #save user uploaded photo info in Gallery Database g = Gallery( blob_key = blob_key, url = serving_url, email = email, name = name, ) g.save() return HttpResponseRedirect('/my_account/')
def photo_add(request, project_id, gallery_id): filename = request.META['HTTP_X_FILE_NAME'] filesize = request.META['HTTP_X_FILE_SIZE'] filetype = request.META['HTTP_X_FILE_TYPE'] if filetype.split('/')[0] == 'image': im = SimpleUploadedFile(filename, request._raw_post_data, filetype) if gallery_id: gallery = Gallery.objects.get(id=gallery_id) else: project = Project.objects.get(id=project_id) gallery = Gallery(project=project, title=request.META['HTTP_X_GALLERY_TITLE'], created=request.user) gallery.save() photo = Photo(image=File(im), desc=filename, gallery=gallery) photo.save() return HttpResponse('/projects/%s/stockphoto/%s' % (str(project_id), str(gallery.id)))
def getRSSItemsString(): rss = memcache.get("rss_content") if rss: return rss else: gallery = Gallery.all().order('-updated_at').get() if gallery: rss = gallery.xml memcache.set("rss_content", rss) return rss return ""
def uploadgallery(request, authUser): res = JSONParser().parse(request) files = request.FILES.getlist("files") if not res['title'] or not res['description']: return JSONResponse( {'message': 'Both title and description is required'}, status=400) if len(files) > 0: gallery_obj = Gallery(owner=authUser, title=res['title'], description=res['description']) gallery_obj.save() check_first = True try: for file in files: pic = GalleryPictures(url=file, gallery=gallery_obj) pic.save() if check_first: pic.cover_photo = pic.url check_first = False pic.save() galleryQuerySet = Gallery.objects.filter(id=gallery_obj.id) return JSONResponse(getCleanObject( json.loads(serialize('json', galleryQuerySet))), status=200) except: gallery_obj.delete() return JSONResponse( { 'message': 'Unexpected error, may be too much files to upload.' }, status=400) else: return JSONResponse({'message': 'No Image files selected'}, status=400)
def create_gallery(): if not login.current_user.is_active(): flash('请登录后再搞相册哦~') return redirect(url_for('light-cms.user_login')) if request.method == 'GET': return render_template('create_gallery.html', title='创建相册') if request.method == 'POST': uuid = shortuuid.ShortUUID().random(length=6) while Gallery.objects(gid=uuid): uuid = shortuuid.ShortUUID().random(length=6) title = request.form['title'] g = Gallery() g.user = login.current_user._get_current_object() g.gid = uuid g.title = title g.save() return redirect(url_for('light-cms.add_image_to_gallery', gid=g.gid))
def create_gallery(): if not login.current_user.is_active(): flash('앨범기능엔 로그인이 필요합니다') return redirect(url_for('light-cms.user_login')) if request.method == 'GET': return render_template('create_gallery.html', title='앨범 만들기') if request.method == 'POST': uuid = shortuuid.ShortUUID().random(length=6) while Gallery.objects(gid=uuid): uuid = shortuuid.ShortUUID().random(length=6) title = request.form['title'] g = Gallery() g.user = login.current_user._get_current_object() g.gid = uuid g.title = title g.save() return redirect(url_for('light-cms.add_image_to_gallery', gid=g.gid))
def index(): return render_template('index.html', title='홈', images=Image.objects(gallery__not__exists=True).order_by('-pub_date')[:30], galleries=Gallery.objects().order_by('-pub_date'), )
def index(): return render_template('index.html', title='首页', images=Image.objects(gallery__not__exists=True).order_by('-pub_date')[:30], galleries=Gallery.objects().order_by('-pub_date'), )
def add_gallery(request): if request.method == "POST": json_dict = {} if request.POST["name"] == "": json_dict["name"] = "This field is required." file = None if request.FILES.get("file"): file = request.FILES["file"] if request.POST["change"] == "0" and not file: json_dict["file"] = "This field is required. Please select a file." elif request.POST["change"] == "0" and clean_file(file, image=True) != "": json_dict["file"] = clean_file(file, image=True) for i in range(0, int(request.POST["nr"])): file = None if request.FILES.get("form-" + str(i) + "-file"): file = request.FILES["form-" + str(i) + "-file"] if file: error = clean_file(file, image=True) if error != "": json_dict[i] = error if json_dict != {}: response = HttpResponse(json.dumps(json_dict), content_type='application/json') response.status_code = 400 return response if request.POST["change"] == "1": obj = get_object_or_404(Gallery, id=request.POST["id"]) obj.name = escape(request.POST["name"]) if request.FILES.get("file"): obj.file = request.FILES["file"] obj.save() for i in range(0, int(request.POST["delete_nr"])): id = int(request.POST["delete-" + str(i) + "-id"]) photo = GalleryPhoto.objects.get(pk=id) photo.delete() else: obj = Gallery(name=escape(request.POST["name"]), file=request.FILES["file"], author=request.user) obj.save() for i in range(0, int(request.POST["nr"])): id = None if request.POST.get("form-" + str(i) + "-id"): id = request.POST["form-" + str(i) + "-id"] file = None if request.FILES.get("form-" + str(i) + "-file"): file = request.FILES["form-" + str(i) + "-file"] name = request.POST["form-" + str(i) + "-name"] if not id: photo = GalleryPhoto(gallery=obj, name=name, file=file, author=request.user, location="gallery/" + str(obj.slug)) photo.save() else: photo = GalleryPhoto.objects.get(pk=id) photo.name = name photo.save() return redirect("/admin/gallery/gallery/") else: return HttpResponseForbidden()