def add_post (self, request): # 글 제목 처리 if request.POST.has_key('title') == False: return HttpResponse('글 제목을 입력해야 한다우.') else: if len(request.POST['title']) == 0: return HttpResponse('글 제목엔 적어도 한 글자는 넣자!') else: entry_title = request.POST['title'] # 글 본문 처리 if request.POST.has_key('content') == False: return HttpResponse('글 본문을 입력해야 한다우.') else: if len(request.POST['content']) == 0: return HttpResponse('글 본문엔 적어도 한 글자는 넣자!') else: entry_content = request.POST['content'] # 글 갈래 처리 if request.POST.has_key('category') == False: return HttpResponse('글 갈래를 골라야 한다우.') else: try: entry_category = Categories.objects.get(id=request.POST['category']) except: return HttpResponse('이상한 글 갈래구려') # 글 꼬리표 처리 if request.POST.has_key('tags') == True: tags = map(lambda str: str.strip(), unicode(request.POST['tags']).split(',')) tag_list = map(lambda tag: TagModel.objects.get_or_create(title=tag)[0], tags) else: tag_list = [] # 꼬리표 저장을 위해 임시 저장 new_entry = Entries(title=entry_title, content=entry_content, category=entry_category) try: new_entry.save() except: return HttpResponse('글을 써넣다가 오류가 발생했습니다.') # 꼬리표 추가 for tag in tag_list: new_entry.tags.add(tag) # 최종 저장. if len(tag_list) > 0: try: new_entry.save() except: return HttpResponse('글을 써넣다가 오류가 발생했습니다.') return HttpResponse('%s번 글을 제대로 써넣었습니다.' % new_entry.id)
def post(self): title = request.form.get("title", None) text = request.form.get("text", None) Entries.new_item(title, text) results = { "status": True, } return self.create_response(results)
def add_entry(): if not session.get("username", None): abort(401) title = request.form.get("title", None) text = request.form.get("text", None) Entries.new_item(title, text) flash(u"添加成功") return redirect(url_for("show_entries"))
def get_entries_by_search_term(self, query, search_type): if search_type == "employee_name": query_cond = Entries.employee_name.contains(query) items = Entries.select().where(query_cond) elif search_type == "task_name_and_notes": query_cond1 = Entries.task_name.contains(query) query_cond2 = Entries.notes.contains(query) items_1 = Entries.select().where(query_cond1) items_2 = Entries.select().where(query_cond2) items = items_1 + items_2 return items
def get_entries_by_date(self, date): # grab all dates of that date target_date_lb = datetime.datetime.strptime(date, "%Y-%m-%d") target_date_ub = target_date_lb + datetime.timedelta(days=1) items = Entries.select().where(Entries.date >= target_date_lb, Entries.date < target_date_ub) return items
def delete(self, enty_id): if enty_id is not None: status = Entries.delete_item(enty_id=enty_id) results = { "status": status } return self.create_response(results)
def hello(name): if get_entry_list(flask.request.remote_addr, name): response = 'nice to see you again {}'.format(name) else: response = 'nice to meet you {}'.format(name) # add entry for this request entry = Entries(ip=flask.request.remote_addr, name=name) session.add(entry) session.commit() return flask.jsonify({'service': 'nice redfish', 'response': response})
def put(self, enty_id): title = request.form.get("title", None) text = request.form.get("text", None) status = Entries.update_item(enty_id, title=title, text=text) results = { "status": status } return self.create_response(results)
def add_entry(self, prompts, output): entry = {} for prompt in prompts: if prompt["model"] in output: entry[prompt["model"]] = output[prompt["model"]] else: entry[prompt["model"]] = "" item = Entries.create(**entry) return item
def get(self, enty_id): if enty_id is None: items = Entries.get_list(format=True) else: items = Entries.query.get(enty_id) items = items.format() results = { "status": True, "data": items, } return self.create_response(results)
def test(request): if request.method == 'POST': if request.POST.get('twilioNumber'): twilioUser = request.POST.get('twilioNumber') print twilioUser number = Notifications(number=str(twilioUser)) number.save() return render(request, 'app/page.html') else: username = request.POST.get('username') repo = request.POST.get('repo') service = request.POST.get('service') data = issues.batchTasks(username, repo, service) client.messages.create( to="+13473282978", from_="+13473259195", body="David, you have to present at Hack battle soon!", ) # Store in database if service == 'github': for datum in data: print datum if 'due' in datum: entry = Entries(due=datum['due'], title=datum['title'], username=datum['username']) entry.save() else: entry = Entries(due='', title=datum['title'], username=datum['username']) entry.save() if service == 'bitbucket': for datum in data: entry = BitbucketEntries(due='', title=datum['title'], username=datum['username']) entry.save() return HttpResponse(json.dumps(data)); else: print 'Not a post request?' return render(request, 'app/page.html')
def get_data(self): items = Entries.get_list() return items
def add_entry(): content = Entries(request.form['title'], request.form['text']) db.session.add(content) db.session.commit() flash('New entry was successfully posted') return redirect(url_for('show_entries'))
from flask import Flask, jsonify, request from mydiary import entries, users from models import MyDiary, Entries from db import MyDiary_Database app = Flask(__name__) app.config['SECRET_KEY'] = 'secret' app_db = MyDiary_Database() my_diary_object = MyDiary() my_diary_object.user_entries = Entries()
def show_entries(): app.logger.info("HHH") entry_list = Entries.get_list() return render_template("show_list.html", entries=entry_list)
def get_all_entries(self): items = Entries.select() return items
def get_entries_by_time_amt(self, time_amt): items = Entries.select().where(Entries.time_amt == int(time_amt)) return items