def technologies(): if request.method == 'GET': return {'technologies': [t.name for t in Technology.select()]} else: technologies_str = request.form.get('technologies', '') technologies_list = [t.strip() for t in technologies_str.split(',')] inserted = Technology.insert_many([{'name': tech} for tech in technologies_list]).returning().on_conflict_ignore().execute() return '{} technologies inserted'.format(inserted)
def post(self): form = TechnologyForm(self.request.POST) if form.validate(): title = form.data["title"] slug = title.strip().lower().replace(" ", "-") technology = Technology(title = title, slug = slug) technology.put() else: print form.errors self.redirect_to('admin-projects-technologies')
def t000_Technology(self): """Lista delle tecnologie""" L.i("TecnologyTestData load start") c = 0 for el in TestData.listTechnologies: L.i(" Dataloaded #{0}".format(c)) c += 1 technology = Technology(title=el['title'], description=el['description'], icon="nunce") self.technologyEntity.append(technology) technology.put() L.i("TechnologyTestData load ended") return True
def t000_Technology(self): """Lista delle tecnologie""" L.i("TecnologyTestData load start") c = 0 for el in TestData.listTechnologies: L.i(" Dataloaded #{0}".format(c)); c+=1; technology = Technology( title = el['title'], description=el['description'], icon="nunce") self.technologyEntity.append(technology) technology.put() L.i("TechnologyTestData load ended") return True
def get(self): technologies = Technology.all() return { "admin_section": "admin-projects-technologies", "technologies": technologies, }
def get(self): form = PortfolioProjectForm() form.technologies.choices = [(tech.key().id(), tech.title) for tech in Technology.all().fetch(None)] return { "admin_section": "admin-projects-new", "form": form, }
def get(self, project_id, extra=""): project = PortfolioProject.get_by_id(long(project_id)) form = PortfolioProjectForm(obj = project) form.technologies.choices = [(tech.key().id(), tech.title) for tech in Technology.all().fetch(None)] return { "admin_section": "admin-projects-portfolio", "form": form, "success": extra == "saved", "upload_url": blobstore.create_upload_url(webapp2.uri_for('image-upload')), "project": project, }
def post(self): form = PortfolioProjectForm(self.request.POST) form.technologies.choices = [(tech.key().id(), tech.title) for tech in Technology.all().fetch(None)] if form.validate(): project = PortfolioProject(**form.data) project.save() self.redirect_to("admin-projects-edit-extra", project_id = project.key().id(), extra="saved") return { "admin_section": "admin-projects-new", "form": form, }
def add_technology(): form = AddTechnologyForm(request.form) if request.method == 'POST' and form.validate(): technology = Technology(form.name.data) db.session.add(technology) db.session.commit() flash('Technology added', 'info') return redirect(url_for('add_technology')) return render_template('_add.html', form=form, rows=Technology.query.all(), target_model="Technology", fields=Technology.__mapper__.c.keys(), action="addtechnology")
def website_upload(): postJson = json.loads(request.data) app.logger.debug(postJson) if not postJson.has_key('hostname'): return jsonify(status='missing hostname') technologies = [] for t in postJson['technologies']: if not t.has_key('title'): return jsonify(status='missing technology title') if not t.has_key('category'): return jsonify(status='missing technology category') if not t.has_key('url'): t['url'] = None if not t.has_key('detail'): t['detail'] = None # 完全一致的技术 tmpTech = Technology.query.filter_by(title=t['title']).filter_by( category=t['category']).filter_by(detail=t['detail']).first() if tmpTech is None: tmpTech = Technology(category=t['category'], title=t['title'], detail=t['detail'], url=t['url']) db.session.add(tmpTech) technologies.append(tmpTech) upload = Website.query.filter_by(hostname=postJson['hostname'], port=postJson['port']).first() if not upload: upload = Website(hostname=postJson['hostname'], port=postJson['port'], title=postJson['title'], ipaddress=postJson['ipaddress'], geo=postJson['geo'], technologies=technologies) else: upload.last_time = datetime.now() upload.title = postJson['title'] upload.technologies = technologies upload.ipaddress = postJson['ipaddress'] upload.geo = postJson['geo'] upload.frequency = upload.frequency + 1 db.session.add(upload) db.session.commit() return jsonify(status='ok')
def post(self, technology_id): form = TechnologyForm(self.request.POST) if form.validate(): slug = form.data["title"].strip().lower().replace(" ", "-") technology = Technology.get(long(category_id)) form.populate_obj(technology) technology.put() return { "result": { "id": technology.key().id(), "title": technology.title, "slug": technology.slug, } }
def post(self, project_id, extra=""): project = PortfolioProject.get_by_id(long(project_id)) form = PortfolioProjectForm(self.request.POST) form.technologies.choices = [(tech.key().id(), tech.title) for tech in Technology.all().fetch(None)] success = False if form.validate(): form.populate_obj(project) project.save() success = True return { "admin_section": "admin-projects-portfolio", "form": form, "success": success, "project": project, }
def get(self, category=None, technology=None): cur_technology = cur_category = None categories = ProjectCategory.all() if category: cur_category = ProjectCategory.all().filter("slug =", category).get() projects = PortfolioProject.all().filter("category =", cur_category).order("-date_created") elif technology: cur_technology = Technology.all().filter("slug =", technology).get() projects = PortfolioProject.all().filter("technologies =", cur_technology.key()).order("-date_created") else: projects = PortfolioProject.all().order("-date_created") cur_category = None return { "section": "portfolio", "projects": projects, "cur_category": cur_category, "cur_technology": cur_technology, "categories": categories, }
def addpost(): posttype = request.form['posttype'] post_title = request.form['posttitle'] posted_by = request.form['postedby'] location = request.form['postlocation'] #file_attach = request.files[''] content = request.form['content'] email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if posttype == 'politics' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000: post = Politics(post_type=posttype, post_title=post_title, posted_by=posted_by, location=location, content=content, date_posted=datetime.now()) db.session.add(post) email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if my_user is None: pass #counting = my_user.post_counter + 1 #counting =str(counting) my_user.post_counter += 1 my_user.daily_post += 1 my_user.user_balance += 100 #my_user.post_counter=counts db.session.add(my_user) #t db.session.commit() return "Posted" + posted_by #my_user.withdraw = "yes" #db.session.add(my_user) #t #db.session.commit() #return 'You no more eligiable please wait for the next 24hours and withdraw yor money' email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if posttype == 'general' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000: post = General(post_type=posttype, post_title=post_title, posted_by=posted_by, location=location, content=content, date_posted=datetime.now()) db.session.add(post) db.session.commit() email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if my_user is None: pass #counting = my_user.post_counter + 1 #counting =str(counting) my_user.post_counter += 1 my_user.daily_post += 1 my_user.user_balance += 100 #my_user.post_counter=counts db.session.add(my_user) #t db.session.commit() return "Posted" + posted_by email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if posttype == 'entertainment' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000: post = Entertainment(post_type=posttype, post_title=post_title, posted_by=posted_by, location=location, content=content, date_posted=datetime.now()) db.session.add(post) email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if my_user is None: pass #counting = my_user.post_counter + 1 #counting =str(counting) my_user.post_counter += 1 my_user.daily_post += 1 my_user.user_balance += 100 #my_user.post_counter=counts db.session.add(my_user) #t db.session.commit() return "Posted" + posted_by email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if posttype == 'sport' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000: post = Sport(post_type=posttype, post_title=post_title, posted_by=posted_by, location=location, content=content, date_posted=datetime.now()) db.session.add(post) db.session.commit() return "Posted" + posted_by email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if posttype == 'tech' and my_user.post_counter < 10 and my_user.daily_post < 10 and my_user.daily_post < 1000: post = Technology(post_type=posttype, post_title=post_title, posted_by=posted_by, location=location, content=content, date_posted=datetime.now()) db.session.add(post) db.session.commit() email = current_user.email my_user = db.session.query(User).filter_by(email=email).first() if my_user is None: pass #counting = my_user.post_counter + 1 #counting =str(counting) my_user.post_counter += 1 my_user.daily_post += 1 my_user.user_balance += 100 #my_user.post_counter=counts db.session.add(my_user) #t db.session.commit() flash("Thank You Content Posted") return redirect(url_for('dashboard')) else: return 'post type is not selected or not available'
def init_technologies(techs): Technology.insert_many([{'name': tech} for tech in techs]).execute()
def getList(self, request): technology = Technology() return list(technology.all())
def getList(self,request): technology = Technology() return list( technology.all() )