def add_sequencelisting(request): if request.method == 'POST': form = SequenceListingForm(request.POST) title_form = TitleForm(request.POST) if form.is_valid() and title_form.is_valid(): filingDateFromForm = request.POST.get('filingDate') # set to None bc the model does not handle properly empty string from form fd = filingDateFromForm if filingDateFromForm else None sl_instance = SequenceListing.objects.create( fileName=request.POST.get('fileName'), dtdVersion='1', softwareName='prototype', softwareVersion='0.1', productionDate=timezone.now( ), #should be overwritten upon xml export applicantFileReference=request.POST.get( 'applicantFileReference'), IPOfficeCode=request.POST.get('IPOfficeCode'), applicationNumberText=request.POST.get( 'applicationNumberText'), # filingDate = request.POST.get('filingDate'), filingDate=fd, earliestPriorityIPOfficeCode=request.POST.get( 'earliestPriorityIPOfficeCode'), earliestPriorityApplicationNumberText=request.POST.get( 'earliestPriorityApplicationNumberText'), earliestPriorityFilingDate=request.POST.get( 'earliestPriorityFilingDate'), applicantName=request.POST.get('applicantName'), applicantNameLanguageCode=request.POST.get( 'applicantNameLanguageCode'), applicantNameLatin=request.POST.get('applicantNameLatin'), inventorName=request.POST.get('inventorName'), inventorNameLanguageCode=request.POST.get( 'inventorNameLanguageCode'), inventorNameLatin=request.POST.get('inventorNameLatin'), ) sl_instance.save() tcd = title_form.cleaned_data title_instance = Title( sequenceListing=sl_instance, inventionTitle=tcd['inventionTitle'], inventionTitleLanguageCode=tcd['inventionTitleLanguageCode']) title_instance.save() return HttpResponseRedirect( reverse('sequencelistings:edit_seql', args=(sl_instance.pk, ))) else: form = SequenceListingForm() title_form = TitleForm() return render(request, 'sequencelistings/add_sequencelisting.html', { 'form': form, 'title_form': title_form })
def fix(cursor=None): ttq = Title.all() ttq.with_cursor(cursor) title = ttq.get() if not title: return rename = Rename.get_by_key_name(title.name) if rename: if rename.name != title.key().name(): title_r = Title(name=rename.name, show=title.show, subbers = title.subbers) deferred.defer(fix_ep, title.key(), rename.name) title_r.put() title.delete() if rename.name == rename.key().name(): rename.delete() deferred.defer(fix, ttq.cursor())
def add_sequencelisting(request): if request.method == 'POST': form = SequenceListingForm(request.POST) title_form = TitleForm(request.POST) if form.is_valid() and title_form.is_valid(): filingDateFromForm = request.POST.get('filingDate') # set to None bc the model does not handle properly empty string from form fd = filingDateFromForm if filingDateFromForm else None sl_instance = SequenceListing.objects.create( fileName = request.POST.get('fileName'), dtdVersion = '1', softwareName = 'prototype', softwareVersion = '0.1', productionDate = timezone.now(), #should be overwritten upon xml export applicantFileReference = request.POST.get('applicantFileReference'), IPOfficeCode = request.POST.get('IPOfficeCode'), applicationNumberText = request.POST.get('applicationNumberText'), # filingDate = request.POST.get('filingDate'), filingDate = fd, earliestPriorityIPOfficeCode = request.POST.get('earliestPriorityIPOfficeCode'), earliestPriorityApplicationNumberText = request.POST.get('earliestPriorityApplicationNumberText'), earliestPriorityFilingDate = request.POST.get('earliestPriorityFilingDate'), applicantName = request.POST.get('applicantName'), applicantNameLanguageCode = request.POST.get('applicantNameLanguageCode'), applicantNameLatin = request.POST.get('applicantNameLatin'), inventorName = request.POST.get('inventorName'), inventorNameLanguageCode = request.POST.get('inventorNameLanguageCode'), inventorNameLatin = request.POST.get('inventorNameLatin'), ) sl_instance.save() tcd = title_form.cleaned_data title_instance = Title(sequenceListing = sl_instance, inventionTitle = tcd['inventionTitle'], inventionTitleLanguageCode = tcd['inventionTitleLanguageCode'] ) title_instance.save() return HttpResponseRedirect(reverse('sequencelistings:detail', args=(sl_instance.pk,))) else: form = SequenceListingForm() title_form = TitleForm() return render(request, 'sequencelistings/add_sequencelisting.html', {'form': form, 'title_form': title_form})
def author(nickname): author = User.query.filter_by(nickname=nickname).first() if author is None: flash('Author ' + nickname + ' not found.') return redirect(url_for('index')) entries = Entry.query.filter_by(user_id=author.id) return render_template('author.html', title=author.nickname, author=author, entries=entries, titles=Title.fetch_non_empty_titles(Title()))
def init_db(): identity = Id(name="5dec8e0b0e38d4df6b25be65") identity.save() title = Title(name="HomeWork") title.save() desc = Description(name="do today's HomeWork") desc.save() store = Done(name="done") store.save
def savebookmark(TitleF,UrlF,DescriptionF,TagF,PrivateF,UserF): TitleF = unicode(TitleF) UrlF = unicode(UrlF) DescriptionF = unicode(DescriptionF) Tagf = unicode(TagF) try : UrlB = Url.objects.get(url=UrlF) except : UrlB = Url(url=UrlF) UrlB.save() try : TitleB = Title.objects.get(title=TitleF) except : TitleB = Title(title=TitleF) TitleB.save(); try : DescriptionB = Description.objects.get(description=DescriptionF) except : DescriptionB = Description(description=DescriptionF) DescriptionB.save() try : PrivateB = Private.objects.get(private= (PrivateF == 'True')) except : PrivateB = Private(private= (PrivateF == 'True')) PrivateB.save() try : b2 = Bookmark.objects.get(url=UrlB) b2.title=TitleB b2.description=DescriptionB b2.private=PrivateB except : b2 = Bookmark(title=TitleB,url=UrlB,description=DescriptionB,private=PrivateB) b2.save() b2.user.add(UserF) b2.save() tags = TagF.split(" ") tags.sort() for t in tags : try : TagB = Tag.objects.get(tag=t) except : TagB= Tag(tag=t) TagB.save() TagB.user.add(UserF) TagB.save() b2.tag.add(TagB) b2.save()
def get( self ): try: city = self.request.get( 'city' ) state = self.request.get( 'state' ) country = self.request.get( 'country' ) songID = self.request.get('songid') type_ = self.request.get('contenttype') term = self.request.get('songTitle') if not type_: type_ = 'lyrics' if songID: try: resultPack = scrapeSongID(songID) except: self.response.out.write(dumps({'post':'No Hits', 'title':''})) return else: resultPack = androidSearch(QLSearch(term,type_)) if resultPack['result'] is None: lyrics = 'No Hits' else: lyrics = resultPack['result']['content'] title = resultPack['result']['title'] if lyrics == 'No Hits': self.response.out.write(dumps({'post':'No Hits', 'title':''})) return Title( title = title, city = city, state = state, country = country, contenttype = type_ ).put() self.response.out.write( dumps( {'post':lyrics, 'title':title,'hits':resultPack['hits']} ) ) except httplib.IncompleteRead, e: # print 'hi' # print e # print type(e) # print '\n######\n' self.response.out.write(dumps({'post':'Server Error', 'title':''}))
def insert_titles_into_db(batch_size: int = 10000, limit: int = 200000): with open('title.basics.tsv') as titles_tsv: titles_tsv.readline() reader = csv.reader(titles_tsv, delimiter='\t') counter = 0 titles = [] number_in_batch = 0 for row in tqdm(reader): if number_in_batch > batch_size: number_in_batch = 0 db_session.add_all(titles) db_session.commit() titles = [] counter += batch_size print(f'added {counter} titles') if limit and counter >= limit: return row = list(map(map_null, row)) title = Title(tconst=row[0], titleType=row[1], primaryTitle=row[2], originalTitle=row[3], isAdult=bool(int(row[4])), startYear=row[5], endYear=row[6], runtimeMinutes=row[7], genres=row[8]) titles.append(title) number_in_batch += 1 db_session.commit()
def iepginput(d): a_title = Title(name=d['program-title']) b_waves = Waves(name=d['station']) c_station = Station(name=d['station-name']) d_comments = Comments(name=d['comment']) op = timeset(d, start) ed = timeset(d, end) sg1 = d['genre-1'] * 16 + d['subgenre-1'] if d['genre-2'] == 0: x = Program(title=a_title, program_id=d['program-id'], waves=b_waves, station=c_station, start=op, end=ed, gen_1=d['genre-1'], sgn_1=sg1, comments=d_comments) x.save else: sg2 = d['genre-2'] * 16 + d['subgenre-2'] x = Program(title=a_title, program_id=d['program-id'], waves=b_waves, station=c_station, start=op, end=ed, gen_1=d['genre-1'], sgn_1=sg1, gen_2=d['genre-2'], sgn_2=sg2, comments=d_comments) x.save
def add_title(request, pk): if request.method == 'POST': form = TitleForm(request.POST) if form.is_valid(): sl = SequenceListing.objects.get(pk=pk) cd = form.cleaned_data title_instance = Title(sequenceListing = sl, inventionTitle = cd['inventionTitle'].encode('utf-8'), inventionTitleLanguageCode = cd['inventionTitleLanguageCode'] ) title_instance.save() return HttpResponseRedirect(reverse('sequencelistings:detail', args=(pk,))) else: form = TitleForm() return render(request, 'sequencelistings/add_title.html', {'form': form, 'pk': pk})
def register(): form = LoginForm() if form.validate_on_submit(): user = User() user.nickname = form.nickname.data user.password = form.password.data if User.query.filter_by(nickname=user.nickname).first(): flash('username exists') return redirect(url_for('register')) db.session.add(user) db.session.commit() flash('congrulations, you become an author') login_user(user) return redirect(url_for('index')) return render_template('register.html', title='sign up', form=form, titles=Title.fetch_non_empty_titles(Title()))
def entry(entry_id): form = SubmitEntry() entry = Entry.query.filter_by(id=entry_id).first() entries = [] entries.append(entry) title = Title.query.filter_by(id=entry.title_id).first() if form.validate_on_submit(): new_entry = Entry(body=form.body.data, timestamp=datetime.utcnow(), user_id=current_user.id, title_id=title_id) g.user.submit_entry(new_entry) return redirect(url_for('title', name=title.title_name)) return render_template('title.html', title=title.title_name, ttl=title, entries=entries, form=form, titles=Title.fetch_non_empty_titles(Title()))
def login(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('index')) form = LoginForm() if form.validate_on_submit(): nickname = form.nickname.data password = form.password.data registered_user = User.query.filter_by(nickname=nickname, password=password).first() if registered_user is None: flash('wrong username or password') return redirect(url_for('login')) login_user(registered_user) registered_user.save_last_seen() flash('logged in succesfully.') return redirect(request.args.get('next') or url_for('index')) return render_template('login.html', title='login', form=form, titles=Title.fetch_non_empty_titles(Title()))
def edit(entry_id): entry = Entry.query.filter_by(id=entry_id).first() entries = [] entries.append(entry) if g.user.id == entry.user_id or g.user.role == ROLE_ADMIN: form = SubmitEntry(body=entry.body) title = Title.query.filter_by(id=entry.title_id).first() if form.validate_on_submit(): entry.body = form.body.data db.session.commit() return redirect(url_for('title', name=title.title_name)) else: flash("you are not supposed to this.") return redirect(url_for('index')) return render_template('title.html', title=title.title_name, ttl=title, entries=entries, form=form, titles=Title.fetch_non_empty_titles(Title()))
def title(name): form = SubmitEntry() title = Title.query.filter_by(title_name=name).first() entries = Entry.query.filter_by(title_id=title.id).all() if title == None: return redirect(url_for('index')) if form.validate_on_submit(): entry = Entry(body=form.body.data, timestamp=datetime.utcnow(), user_id=current_user.id, title_id=title.id) g.user.submit_entry(entry) return redirect(url_for('title', name=title.title_name)) return render_template('title.html', title=title.title_name, ttl=title, entries=entries, form=form, titles=Title.fetch_non_empty_titles(Title()) )
def titles_update(titles): mode,t = titles.pop() title_db = Title.get_by_key_name(t) if title_db: title_db.show = mode title_db.put() if not titles: return deferred.defer(titles_update, titles)
def search(): if not g.search_form.validate_on_submit(): return redirect(url_for('index')) title_name = g.search_form.data['search'] title = Title.query.filter_by(title_name=title_name).first() if title == None and g.user.is_authenticated(): title = Title(title_name=title_name) db.session.add(title) db.session.commit() elif title == None and not g.user.is_authenticated(): flash('title not found') return redirect(url_for('index')) return redirect(url_for('title', name=title.title_name))
def add_title(request, pk): if request.method == 'POST': form = TitleForm(request.POST) if form.is_valid(): sl = SequenceListing.objects.get(pk=pk) cd = form.cleaned_data title_instance = Title( sequenceListing=sl, inventionTitle=cd['inventionTitle'].encode('utf-8'), inventionTitleLanguageCode=cd['inventionTitleLanguageCode']) title_instance.save() return HttpResponseRedirect( reverse('sequencelistings:edit_seql', args=(pk, ))) else: form = TitleForm() return render(request, 'sequencelistings/add_title.html', { 'form': form, 'pk': pk })
def post(self): form = AddItemForm() item = Item() categories = Category.objects.all() licenses = License.objects.all() form.set_categories(categories, g.lang) form.set_licenses(licenses) if form.validate_on_submit(): # first, the user has to share something ! if not form.github.data and not form.files.data: flash('Neither a repo URL nor files has been shared, come on!', category='alert') return render_template('items/add_item.html', form=form) # give that something at least one title if not form.ar_title.data and not form.fr_title.data and \ not form.en_title.data: flash('You need to give this item at least one title, \ just pick one language and name it!', category='alert') return render_template('items/add_item.html', form=form) # now we can proceed ar_title = Title() fr_title = Title() en_title = Title() ar_title.title = form.ar_title.data.strip() ar_title.lang = 'ar' fr_title.title = form.fr_title.data.strip() fr_title.lang = 'fr' en_title.title = form.en_title.data.strip() en_title.lang = 'en' item.titles.append(ar_title) item.titles.append(fr_title) item.titles.append(en_title) item.description = form.description.data item.tags = form.tags.data.strip().split(',') item.category = Category.objects.get( category_id=int(form.category.data)) item.submitter = User.objects.get(id=current_user.id) thumbnail = request.files['thumbnail'] thumbnail_name = secure_filename(thumbnail.filename) if thumbnail and allowed_thumbnails(thumbnail_name): ext = thumbnail.mimetype.split('/')[-1] # use the 'thumbnail' name for all thumbnails filename = '.'.join(["thumbnail", ext]) item.thumbnail.put(thumbnail.stream, content_type=thumbnail.mimetype, filename=filename) if form.github.data: item.github = form.github.data item.save() # no need to process any uploaded files flash('Item submitted successfully', category='success') return redirect(url_for('items.detail', item_id=item.item_id)) else: item.license = License.objects.get( license_id=int(form.license.data)) else: flash('upload unsuccessful', category='error') return render_template('items/add_item.html', form=form) uploaded_files = request.files.getlist("files") for file in uploaded_files: # Make the filename safe, remove unsupported chars filename = secure_filename(file.filename) # Check if the file is one of the allowed types/extensions if file and allowed_file(filename): # put the file in the ListField. # see https://gist.github.com/tfausak/1299339 file_ = GridFSProxy() file_.put(file.stream, content_type=file.mimetype, filename=filename) item.files.append(file_) # Save the thing item.save() flash('Item uploaded successfully', category='success') return redirect(url_for('items.detail', item_id=item.item_id))
def get( self ): shuffler = randint( 0, 9 ) recentTitles = [titlecase( ttl.title.lower() ) for ttl in Title.all().order( '-date' ).fetch( 100 )[shuffler::20]] self.response.out.write( template.render( os.path.join( os.path.dirname( __file__ ), 'templates', 'index.htm' ), {'recentTitles':recentTitles}, True ) )
def post(self): form = AddItemForm() item = Item() categories = Category.objects.all() licenses = License.objects.all() form.set_categories(categories, g.lang) form.set_licenses(licenses) if form.validate_on_submit(): # first, the user has to share something ! if not form.github.data and not form.files.data: flash('Neither a repo URL nor files has been shared, come on!', category='alert') return render_template('items/add_item.html', form=form) # give that something at least one title if not form.ar_title.data and not form.fr_title.data and \ not form.en_title.data: flash('You need to give this item at least one title, \ just pick one language and name it!', category='alert') return render_template('items/add_item.html', form=form) # now we can proceed ar_title = Title() fr_title = Title() en_title = Title() ar_title.title = form.ar_title.data.strip() ar_title.lang = 'ar' fr_title.title = form.fr_title.data.strip() fr_title.lang = 'fr' en_title.title = form.en_title.data.strip() en_title.lang = 'en' item.titles.append(ar_title) item.titles.append(fr_title) item.titles.append(en_title) item.description = form.description.data item.tags = form.tags.data.strip().split(',') item.category = Category.objects.get(category_id= int(form.category.data)) item.submitter = User.objects.get(id=current_user.id) thumbnail = request.files['thumbnail'] thumbnail_name = secure_filename(thumbnail.filename) if thumbnail and allowed_thumbnails(thumbnail_name): ext = thumbnail.mimetype.split('/')[-1] # use the 'thumbnail' name for all thumbnails filename = '.'.join(["thumbnail", ext]) item.thumbnail.put(thumbnail.stream, content_type=thumbnail.mimetype, filename=filename) if form.github.data: item.github = form.github.data item.save() # no need to process any uploaded files flash('Item submitted successfully', category='success') return redirect(url_for('items.detail', item_id=item.item_id)) else: item.license = License.objects.get(license_id= int(form.license.data)) else: flash('upload unsuccessful', category='error') return render_template('items/add_item.html', form=form) uploaded_files = request.files.getlist("files") for file in uploaded_files: # Make the filename safe, remove unsupported chars filename = secure_filename(file.filename) # Check if the file is one of the allowed types/extensions if file and allowed_file(filename): # put the file in the ListField. # see https://gist.github.com/tfausak/1299339 file_ = GridFSProxy() file_.put(file.stream, content_type=file.mimetype, filename=filename) item.files.append(file_) # Save the thing item.save() flash('Item uploaded successfully', category='success') return redirect(url_for('items.detail', item_id=item.item_id))
def index(): non_empty_titles = Title.fetch_non_empty_titles(Title()) return render_template("index.html", title='home', titles=non_empty_titles, )
def result_to_title(r): return Title(r["title"])