def edit_person(slug): try: p = Person.objects.get(site=g.site.domain, slug=slug) except Person.DoesNotExist: abort(404) if not g.site.domain == g.user: abort(403) if request.method == "POST": reqfile = request.files.get('file') if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file(reqfile, request.config["UPLOAD_FOLDER"]) f.save() p.name = request.form.get("name") p.title = request.form.get("title") p.phone = request.form.get("phone") p.email = request.form.get("email") p.twitter = request.form.get("twitter") p.description = request.form.get("description") if reqfile: p.image_slug = f.slug p.save() return redirect(url_for(".show_person", slug=p.slug)) return render_template("edit_person.html", person=p)
def edit_post(year, month, day, slug): try: p = Post.objects.get(site=g.site.domain, year=year, month=month, day=day, slug=slug) except Post.DoesNotExist: abort(404) if not g.site.domain == g.user: abort(403) if request.method == "POST": reqfile = request.files.get('file') if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file( reqfile, current_app.config["UPLOAD_FOLDER"]) f.save() p.name = request.form.get("name") p.text = request.form.get("text") if reqfile: p.image_slug = f.slug p.save() return redirect( url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug)) return render_template("edit_post.html", post=p)
def edit_post(year, month, day, slug): try: p = Post.objects.get(site=g.site.domain, year=year, month=month, day=day, slug=slug) except Post.DoesNotExist: abort(404) if not g.site.domain == g.user: abort(403) if request.method == "POST": reqfile = request.files.get("file") if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file(reqfile, current_app.config["UPLOAD_FOLDER"]) f.save() p.name = request.form.get("name") p.text = request.form.get("text") if reqfile: p.image_slug = f.slug p.save() return redirect(url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug)) return render_template("edit_post.html", post=p)
def edit_person(slug): try: p = Person.objects.get(site=g.site.domain, slug=slug) except Person.DoesNotExist: abort(404) if not g.site.domain == g.user: abort(403) if request.method == "POST": reqfile = request.files.get('file') if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file( reqfile, request.config["UPLOAD_FOLDER"]) f.save() p.name = request.form.get("name") p.title = request.form.get("title") p.phone = request.form.get("phone") p.email = request.form.get("email") p.twitter = request.form.get("twitter") p.description = request.form.get("description") if reqfile: p.image_slug = f.slug p.save() return redirect(url_for(".show_person", slug=p.slug)) return render_template("edit_person.html", person=p)
def post(self): fil = self.request.POST["file"] if not fil.value: self.redirect("/") return logging.getLogger().info("selected val %s" % self.request.POST["compression-type"]) if self.request.POST["compression-type"] == "NONE": data = fil.value else: params = urllib.urlencode( [ ("js_code", fil.value), ("compilation_level", self.request.POST["compression-type"]), ("output_format", "text"), ("output_info", "compiled_code"), ] ) headers = {"Content-type": "application/x-www-form-urlencoded"} conn = httplib.HTTPConnection("closure-compiler.appspot.com") conn.request("POST", "/compile", params, headers) response = conn.getresponse() data = response.read() conn.close file = File() file.name = fil.filename file.file = db.Blob(data) file.content_type = fil.type file.user = users.get_current_user() file.put() self.redirect("/")
def create_file(self, filename, user=None): file = File() if user is None: user = self.get_current_user() file.author = user file.name = filename key = file.put() self.create_permission(file, file.author, ACCESS_WRITE) #self.redirect('/file?' + urllib.urlencode({'id': key})) return key
def order(): if 'username' not in session: return redirect(url_for('login')) form = forms.OrderForm(formdata=request.form) form.category.choices = [ (c.id, c.name) for c in Category.query.filter_by(subject_id=form.subject.data) ] if ('0', 'Select...') not in form.subject.choices: form.subject.choices.insert(0, ('0', 'Select...')) if request.method == 'POST' and form.validate(): new_order = Order() new_order.title = form.title.data new_order.user_id = session['user_id'] new_order.subject_id = form.subject.data new_order.category_id = form.category.data new_order.os_id = form.os.data new_order.details = form.details.data new_order.deadline = form.deadline.data new_order.explanations = form.explanations.data db.session.add(new_order) db.session.commit() files = request.files.getlist('file[]') order_files = [] for f in files: if f.filename: ext = f.filename.split('.')[-1] name = str(uuid.uuid4()) + '.' + ext path = os.path.join(app.config['FILE_UPLOAD_PATH'], name) f.save(path) of = File() of.order_id = new_order.id of.name = f.filename of.local_name = name order_files.append(of) for of in order_files: db.session.add(of) db.session.commit() flash('Order submitted :)', _CATEGORY_MESSAGE) return redirect(url_for('profile')) return render_template('order.html', form=form)
def save_file(self, path, _hash): f = File() f.id = str(uuid()) f.name = os.path.basename(path) f.hash = _hash f.filesize = os.path.getsize(path) f.isdir = os.path.isdir(path) f.date = datetime.datetime.now() dirname = os.path.dirname(path) os.renames(path, os.path.join(dirname, f.id)) self.session.add(f)
def files(): if request.method == "POST" and g.site.domain == g.user: reqfile = request.files["file"] f = File() f.site = g.site.domain f.name = reqfile.filename f.slug = secure_filename(f.name) f.content_type = reqfile.mimetype f.slug, f.content_length = save_file(reqfile, app.config["UPLOAD_FOLDER"]) f.save() files = File.objects(site=g.site.domain) return render_template("files.html", files=files)
def order(): if 'username' not in session: return redirect(url_for('login')) form = forms.OrderForm(formdata=request.form) form.category.choices = [(c.id, c.name) for c in Category.query.filter_by(subject_id=form.subject.data)] if ('0', 'Select...') not in form.subject.choices: form.subject.choices.insert(0, ('0', 'Select...')) if request.method == 'POST' and form.validate(): new_order = Order() new_order.title = form.title.data new_order.user_id = session['user_id'] new_order.subject_id = form.subject.data new_order.category_id = form.category.data new_order.os_id = form.os.data new_order.details = form.details.data new_order.deadline = form.deadline.data new_order.explanations = form.explanations.data db.session.add(new_order) db.session.commit() files = request.files.getlist('file[]') order_files = [] for f in files: if f.filename: ext = f.filename.split('.')[-1] name = str(uuid.uuid4()) + '.' + ext path = os.path.join(app.config['FILE_UPLOAD_PATH'], name) f.save(path) of = File() of.order_id = new_order.id of.name = f.filename of.local_name = name order_files.append(of) for of in order_files: db.session.add(of) db.session.commit() flash('Order submitted :)', _CATEGORY_MESSAGE) return redirect(url_for('profile')) return render_template('order.html', form=form)
def post(self): fil = self.request.POST["file"] if not fil.value: self.redirect("/") return file = File() file.name = fil.filename file.file = db.Blob(cssmin.cssmin(fil.value)) file.original = db.Blob(fil.value) file.content_type = fil.type file.user = users.get_current_user() file.put() self.redirect("/")
def files(): if request.method == "POST" and g.site.domain == g.user: reqfile = request.files['file'] f = File() f.site = g.site.domain f.name = reqfile.filename f.slug = secure_filename(f.name) f.content_type = reqfile.mimetype f.slug, f.content_length = save_file(reqfile, app.config["UPLOAD_FOLDER"]) f.save() files = File.objects(site=g.site.domain) return render_template('files.html', files=files)
def upload_file(name, folder_id, f): root = MEDIA_ROOT folder = Folder.objects.get(id=folder_id) # create a file with open(folder.path + "/" + name, 'w') as destination: for chunk in f.chunks(): destination.write(chunk) file = File() file.name = name file.folder = folder file.active = True file.save() return file.id
def create_file(name, folder_id): root = MEDIA_ROOT folder = Folder.objects.get(id=folder_id) # Open a file f = open(folder.path + "/" + name, "w") # Close opend file f.close() file = File() file.name = name file.folder = folder file.active = True file.save() return file.id
def compile_java(file_id): #first traslate traslate_java(file_id) file = File.objects.get(id=file_id) folder = file.folder user = folder.user galatea_code = GALATEA + "galatea.jar " code = "javac -cp "+ galatea_code + folder.path + "/*.java" #print code value = subprocess.check_output([code], shell=True) #print value #get all the file in this folder for root, dirs, files in os.walk(folder.path): root_folder = Folder.objects.get(path=root, name = os.path.basename(root)) for dir in dirs: folders = Folder.objects.filter(father=root_folder.id) esta = False for folder in folders: if folder.name == dir: esta = True if not esta: folder = Folder() folder.name = dir folder.path = root_folder.path + "/" + dir folder.user = user folder.father = root_folder.id folder.active = True folder.save() #print dirs for file in files: files_folder = File.objects.filter(folder = root_folder.id) esta = False for f in files_folder: if f.name == file: esta = True if not esta: if (os.path.splitext(file)[1] != ".class"): f = File() f.name = file f.folder = root_folder f.active = True f.save() return value
def new_post(): if not g.site.domain == g.user: abort(403) p = Post() if request.method == "POST": reqfile = request.files.get('file') if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file(reqfile, blog.config["UPLOAD_FOLDER"]) f.save() import datetime p.site = g.site.domain p.name = request.form.get("name") p.created = datetime.datetime.utcnow() p.year = p.created.year p.month = p.created.month p.day = p.created.day slugs = [ __j.slug for __j in Post.objects.filter(site=g.site.domain, year=p.year, month=p.month, day=p.day, slug=p.slug) ] counter = 1 slug = slugify(p.name) __slug = slug while __slug in slugs: counter += 1 __slug = "%s_%d" % (slug, counter) p.slug = __slug p.text = request.form.get("text") if reqfile: p.image_slug = f.slug p.save() return redirect( url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug)) return render_template("edit_post.html", post=p)
def new_person(): if not g.site.domain == g.user: abort(403) p = Person() if request.method == "POST": reqfile = request.files.get('file') if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file( reqfile, current_app.config["UPLOAD_FOLDER"]) f.save() p.site = g.site.domain p.name = request.form.get("name") p.title = request.form.get("title") p.phone = request.form.get("phone") p.email = request.form.get("email") p.twitter = request.form.get("twitter") p.description = request.form.get("description") slugs = [__p.slug for __p in Person.objects.filter(site=g.site.domain)] slug = slugify(p.name) counter = 1 __slug = slug while __slug in slugs: counter += 1 __slug = "%s_%d" % (slug, counter) p.slug = __slug if reqfile: p.image_slug = f.slug p.save() pl = Personnel.objects.get(site=g.site.domain) pl.people.append(p.slug) pl.save() return redirect(url_for(".show_personnel")) return render_template("edit_person.html", person=p)
def new_person(): if not g.site.domain == g.user: abort(403) p = Person() if request.method == "POST": reqfile = request.files.get('file') if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file(reqfile, current_app.config["UPLOAD_FOLDER"]) f.save() p.site = g.site.domain p.name = request.form.get("name") p.title = request.form.get("title") p.phone = request.form.get("phone") p.email = request.form.get("email") p.twitter = request.form.get("twitter") p.description = request.form.get("description") slugs = [ __p.slug for __p in Person.objects.filter(site=g.site.domain) ] slug = slugify(p.name) counter = 1 __slug = slug while __slug in slugs: counter += 1 __slug = "%s_%d" % (slug, counter) p.slug = __slug if reqfile: p.image_slug = f.slug p.save() pl = Personnel.objects.get(site=g.site.domain) pl.people.append(p.slug) pl.save() return redirect(url_for(".show_personnel")) return render_template("edit_person.html", person=p)
def new_post(): if not g.site.domain == g.user: abort(403) p = Post() if request.method == "POST": reqfile = request.files.get("file") if reqfile: f = File() f.site = g.site.domain f.name = reqfile.filename f.content_type = reqfile.mimetype f.slug, f.content_length = save_file(reqfile, blog.config["UPLOAD_FOLDER"]) f.save() import datetime p.site = g.site.domain p.name = request.form.get("name") p.created = datetime.datetime.utcnow() p.year = p.created.year p.month = p.created.month p.day = p.created.day slugs = [ __j.slug for __j in Post.objects.filter(site=g.site.domain, year=p.year, month=p.month, day=p.day, slug=p.slug) ] counter = 1 slug = slugify(p.name) __slug = slug while __slug in slugs: counter += 1 __slug = "%s_%d" % (slug, counter) p.slug = __slug p.text = request.form.get("text") if reqfile: p.image_slug = f.slug p.save() return redirect(url_for("post", year=p.year, month=p.month, day=p.day, slug=p.slug)) return render_template("edit_post.html", post=p)
def Upload(request): if request.method != "POST": raise Http404 if not request.FILES: if "cliptext" not in request.POST: raise Http404 token = utils.gentoken() while os.path.isdir("/var/www/synchy.org/main/synchy-django/media/%s" % token): token = utils.gentoken() os.mkdir("/var/www/synchy.org/main/synchy-django/media/%s" % token) os.mkdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token) if not request.FILES: if 'cliptext' in request.POST: group = Group() group.token = token group.multi = False group.save() file = File() file.group = group file.name = "clipboard.txt" file.mime = "text/plain" file.save() data = request.POST['cliptext'] handle = open("/var/www/synchy.org/main/synchy-django/media/%s/files/%s" % (token, file.name), 'w+') handle.write(data) handle.close() else: os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token) os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token) return Http404 else: if len(request.FILES) != 1: os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token) os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token) raise Http404 else: if 'file' in request.FILES: group = Group() group.token = token group.multi = False group.save() file = File() file.group = group file.name = request.FILES['file'].name file.mime = request.FILES['file'].content_type file.save() data = request.FILES['file'].read() handle = open("/var/www/synchy.org/main/synchy-django/media/%s/files/%s" % (token, file.name), 'w+') handle.write(data) handle.close() elif 'zip' in request.FILES: group = Group() group.token = token group.multi = True group.save() if request.FILES['zip'].content_type != "application/octet-stream": os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token) os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token) raise Http404 data = request.FILES['zip'].read() handle = open("/var/www/synchy.org/main/synchy-django/media/%s/%s%s%s%s" % (token, "files-", token[:2], token[-2:], ".zip"), 'w+') handle.write(data) handle.close() os.system('cd "%s/var/www/synchy.org/main/synchy-django/media/%s/files/"; sudo jar -xf %s/var/www/synchy.org/main/synchy-django/media/%s/files-%s%s.zip' % (os.getcwd(), token, os.getcwd(), token, token[:2], token[-2:])) zfile = Zip() zfile.group = group zfile.name = "%s%s%s%s" % ("files-", token[:2], token[-2:], ".zip") zfile.save() mime = magic.Magic(mime=True) for name in os.listdir("/var/www/synchy.org/main/synchy-django/media/%s/files/" % token): file = File() file.group = group file.name = name file.mime = mime.from_file("/var/www/synchy.org/main/synchy-django/media/%s/files/%s" % (token, name)) file.save() else: os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s/files" % token) os.rmdir("/var/www/synchy.org/main/synchy-django/media/%s" % token) raise Http404 return HttpResponse(token)