[스파르타7기] 개발일지4 - 2020.04.20

Tia Hwang·2020년 4월 20일
0

스파르타7기

목록 보기
5/12

오늘한일

1. global 변수 없애고, jsonify와 ajax로 email 받아올 수 있게 수정

  • (app.py): 'current_email'을 ajax로 보냄
@app.route('/habits', methods=['POST'])
def saving():
    ~생략~
    return jsonify({'result': 'success', 'current_email': current_email})
  • (index.html): url에 email정보가 뜨게끔 설정
function posting() {
  ~생략~
  $.ajax({
    ~생략~
    success: function (response) {
      if (response["result"] == "success") {
        alert("등록 성공!");
        window.location.href = "/habits?email=" + response["current_email"];
      } 
  • (app.py): flask HTTP 메소드 중 GET방식 사용
@app.route('/habits', methods=['GET'])
def listing():
    current_email = request.args.get('email')
    ~

2. 습관을 달력에 drop하면 db에 습관등록된 날짜와 습관이름 저장

  • FullCalendar 라이브러리의 "eventReceive" 사용
    • 달력에 습관(event)를 drop하면 eventReceive가 호출됨
  • (habits.html)
let calendar = new Calendar(calendarEl, {
  ~생략~
  eventReceive: function (event, _) {
      console.log("습관추가되었쥐");
      saveEvent(event);
  },
});

function saveEvent(event) {
  $.ajax({
    type: "POST",
    url: "/habits-date",
    data: {
      date: event.event.start,
      title: event.event.title,
    },
    dataType: "json",
    success: function (response) {
      if (response["result"] == "success") {
          alert("저장 성공!");
      } else {
          alert("서버 오류!");
      }
    },
  });
}
  • (app.py)
@app.route('/habits-date', methods=['POST'])
def savingEvents():
    date_receive = request.form['date']
    title_receive = request.form['title'];

    calendar = {'date': date_receive, 'title': title_receive}
    db.calendars.insert_one(calendar)

    return jsonify({'result': 'success'})
  • Robo 3T에 확인한 결과 😃

해야할일

1. db에 저장된 습관들 달력에 보이기

2. habit 추가 버튼과 기능 구현

GitHub commit

profile
프론트엔드 개발자로 취업하기

0개의 댓글