def AddFile(request): newFile = request.FILES['file'] type = request.POST.get('type') title=request.POST.get('title') category=request.POST.get('category') monograph=request.POST.get('monograph') path='/New File/'+ newFile.name folder_path = '/Applications/XAMPP/htdocs/New File' current=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) userID=request.POST.get('userID') user=User.objects.get(id=userID) if type=='pdf': reference=request.POST.get('studyRef') intervention=request.POST.get('intervention') design=request.POST.get('studyDesgin') ID=request.POST.get('studyID') file=book(titles=title,file_type=type,path=path,file_ownership=category,modification_time=current, monograph_part=monograph,study_reference=reference,Intervention=intervention,study_design=design,study_ID=ID) else: file=others(titles=title,file_type=type,path=path, file_ownership=category,modification_time=current,monograph_part=monograph) file.save() destination = open(os.path.join(folder_path, newFile.name), 'wb+') for chunk in newFile.chunks(): destination.write(chunk) newLog=log(logType='Add',titles=title,user=user.username,file_type=type,path=path, file_ownership=category,modification_time=current,monograph_part=monograph) newLog.save() return Response({'status':200})
def removeSomeReviews(c): rows = c.getSession().execute('SELECT id FROM prs.users where reviews_filtered=false') for row in rows: logging.info("Getting reviews for user %s", row['id']) user=models.Users.get(id=row['id']) list=user.list_reviews if(list is None): user.reviews_filtered=True user.save() continue list.sort(key=lambda r: r.rating, reverse=True) index=0 for i, r in enumerate(list): if(r.rating<3): index=i break if(index>0): list[index:] = [] list[500:] = [] user.list_reviews=[] for r in list: ac=models.user(id=r.actor.id, gid=r.actor.gid, name=r.actor.name, friends_count=r.actor.friends_count, reviews_count= r.actor.reviews_count, age=r.actor.age, gender=r.actor.gender, small_user=r.actor.small_user, private=r.actor.private) bk=models.book(id=r.book.id, gid=r.book.gid, title=ascii(r.book.title),isbn=r.book.isbn, isbn13=r.book.isbn13, publication_date=r.book.publication_date, average_rating=r.book.average_rating, ratings_count=r.book.ratings_count, small_book=r.book.small_book, author=r.book.author) user.list_reviews.append(models.review(id=r.id, actor=ac, book=bk, gid=r.gid, rating=r.rating, text=ascii(r.text))) user.reviews_count=len(user.list_reviews) user.reviews_filtered=True user.save() logging.info("Finish removing some reviews for user %s", row['id'])
def books_to_book(book): return models.book(id=book.id, gid=book.gid, title=book.title, isbn=book.isbn, isbn13=book.isbn13, publication_date=book.publication_date, average_rating=book.average_rating, ratings_count=book.ratings_count, small_book=book.small_book, author=book.author, list_shelves=book.list_shelves)
def new_book(): public = False if request.get_json()['public'] == True: public = True b = book(title=request.get_json()['title'], \ description='', \ date = '12/12/2018', \ user_id = current_user.id, public=public) db.session.add(b) db.session.commit() return redirect('/')
def removeSomeReviews(c): rows = c.getSession().execute( 'SELECT id FROM prs.users where reviews_filtered=false') for row in rows: logging.info("Getting reviews for user %s", row['id']) user = models.Users.get(id=row['id']) list = user.list_reviews if (list is None): user.reviews_filtered = True user.save() continue list.sort(key=lambda r: r.rating, reverse=True) index = 0 for i, r in enumerate(list): if (r.rating < 3): index = i break if (index > 0): list[index:] = [] list[500:] = [] user.list_reviews = [] for r in list: ac = models.user(id=r.actor.id, gid=r.actor.gid, name=r.actor.name, friends_count=r.actor.friends_count, reviews_count=r.actor.reviews_count, age=r.actor.age, gender=r.actor.gender, small_user=r.actor.small_user, private=r.actor.private) bk = models.book(id=r.book.id, gid=r.book.gid, title=ascii(r.book.title), isbn=r.book.isbn, isbn13=r.book.isbn13, publication_date=r.book.publication_date, average_rating=r.book.average_rating, ratings_count=r.book.ratings_count, small_book=r.book.small_book, author=r.book.author) user.list_reviews.append( models.review(id=r.id, actor=ac, book=bk, gid=r.gid, rating=r.rating, text=ascii(r.text))) user.reviews_count = len(user.list_reviews) user.reviews_filtered = True user.save() logging.info("Finish removing some reviews for user %s", row['id'])
def addbook(request): if request.POST: post=request.POST authorid=post['authorid'] multiple_book = book(ISBN = post['ISBN'],title = post['title'],authorid = authorid, publisher=post['publisher'],publishdate=post['publishdate'], price=post['price']) multiple_book.save() try: author_lst = author.objects.filter(authorid__contains = authorid) if author_lst: return render_to_response('index.html') else: return render_to_response('authoradd.html',{'authorid':authorid}) except: return render_to_response('authoradd.html',{'authorid':authorid}) else: return render_to_response('add.html')
def addbook(req): if req.POST: post = req.POST ID=post["AuthorID"] author=Author.objects.get(AuthorID = ID) if author: newbook = book( ISBN = post["ISBN"], Title = post["title"], AuthorID = author, Publisher = post["Publisher"], PublishDate = post["publishdate"], Price = post["price"],) newbook.save() count=Author.objects.all() return render_to_response("addsucess.html", {"count":count}) count=Author.objects.all() return render_to_response("addbook.html", {"count":count})
def upload(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/login') if request.method=='POST': l=request.FILES['file'] title=request.POST['title'] author=request.POST['author'] if l and title and author and l.content_type == 'application/pdf': key=sha1(title+author).hexdigest()[:15] if key in os.listdir(settings.BOOKS): return HttpResponseRedirect('/upload') b=book(title=title,author=author,bookKey=key) b.save() move_uploaded_file(l,key) createThumbnail(key) return HttpResponseRedirect('/upload') else: return render_to_response("upload.html", {'error':'1.All fields are mandatory<br>2.Only PDF files Allowed'},context_instance=RequestContext(request)) else: return render_to_response("upload.html",{'title':'Upload files'},context_instance=RequestContext(request))
def update(request): if 'id' in request.GET: book_lst = book.objects.get(title = request.GET['id']) if request.POST: post = request.POST authorid = post['authorid'] book_lst=book.objects.filter(authorid=authorid) ISBN=book_lst[0].ISBN title=book_lst[0].title book_lst = book(ISBN,title,authorid, publisher=post['publisher'],publishdate=post['publishdate'],price=request.POST['price']) book_lst.save() book_lst=book.objects.all() try: author_lst = author.objects.filter(authorid__contains = authorid) if author_lst: return render_to_response('index.html') else: return render_to_response('authoradd.html',{'authorid':authorid}) except: return render_to_response('authoradd.html',{'authorid':authorid}) return render_to_response('update.html',{'book':book_lst})
def RecoveryFile(request): infor=json.loads(request.body) logID=infor['logID'] file=log.objects.get(id=logID) current=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) abso_path = '/Applications/XAMPP/htdocs' + file.path fpath , fname = os.path.split(abso_path) dest_path='/Applications/XAMPP/htdocs/Bin/'+ fname if file.file_type=='pdf': new_file=book(titles=file.titles,file_type=file.file_type,path=file.path, file_ownership=file.file_ownership,modification_time=current,monograph_part=file.monograph_part, study_reference=file.study_reference,Intervention=file.Intervention,study_design=file.study_design, study_ID=file.study_ID) else: new_file=others(titles=file.titles,file_type=file.file_type,path=file.path, file_ownership=file.file_ownership,modification_time=current,monograph_part=file.monograph_part) new_file.save() shutil.move(dest_path, fpath) file.delete() return Response({'status':200})
day.query.delete() except: print 'db already cleared' ## add user u = user(username='******', email='*****@*****.**', first='Tim', last='Flaspoehler') db.session.add(u) db.session.commit() ## add books b = book(title='introduction', \ description='Gives a brief intro to the bullet-jounraling methodology in the context of this implementation. Also shows a todo list of what needs to be finished.', \ date = '12/12/2018', \ user_id = u.id, public=True) db.session.add(b) db.session.commit() ## add days to the book days = [ dict(id=1, title='Bullet Journaling Introduction', text='''<br><br> This is a very basic web application I've been working on to mimic bulletjournaling (<a href="https://bulletjournal.com/">bulletjournal.com</a>). Many people keep personal/work notebooks to jot down notes throughout the day with little methodology for keeping it organized. bulletjournaling (<a href="https://bulletjournal.com/">bulletjournal.com</a>) is a simple method for keeping track of your daily life. For years, I used a very basic version of this so I thought I'd make a simple web app that follows my methodology. I'm sure there are better versions of this out there (including through the main website), but this is simply what I use. At the end of the day, this is more of a project to keep up to date with building user-friendly, useful web apps. <br><br> -Tim Flaspoehler'''), dict( id=2,
def books_to_book(book): return models.book(id=book.id, gid=book.gid, title=book.title,isbn=book.isbn, isbn13=book.isbn13, publication_date=book.publication_date,average_rating=book.average_rating, ratings_count=book.ratings_count, small_book=book.small_book, author=book.author, list_shelves=book.list_shelves)