if not note:
     continue
 if not note.context:
     continue
 if note.context.id not in context_ids:
     continue
 feedbacks_comment = Feedback.query.filter(Feedback.table_name.ilike('note'), Feedback.row_id==note.id, Feedback.kind=='comment').all()
 feedbacks_like = Feedback.query.filter(Feedback.table_name.ilike('note'), Feedback.row_id==note.id, Feedback.kind=='like').all()
 feedback_landmark = Feedback.query.filter(Feedback.table_name.ilike('note'), Feedback.row_id==note.id, Feedback.kind=='Landmark').first()
 location_text = ""
 if note.kind == "FieldNote" and feedback_landmark:
     location = Context.query.filter_by(name=feedback_landmark.content).first()
     if location:
         location_text = "location: " + location.title + "\r\n"
 new_desc = location_text + note.to_trello_desc() + "\r\n#likes: " + str(len(feedbacks_like))
 card = trello_api.get_card_by_id(note.id)
 new_card = False
 if card:
     # update the card
     card_title = note.content
     if len(card_title) == 0 or media.link == card_title:
         card_title = "[no description]"
     trello_api.update_card(note.id, card_title, new_desc)
 else:
     # create the card
     new_card = True
     n = n + 1
     note.status = str(note.created_at.date())
     db.session.commit()
     if len(note.content) == 0:
         card = trello_api.add_card_with_attachment(note.id, media.link, new_desc, note.status, media.get_url())
示例#2
0
#             # db.session.commit()
#         else:
#             f = Feedback.query.filter(Feedback.table_name.ilike('note'), Feedback.row_id==note.id, Feedback.kind=='comment', Feedback.content==comment['data']['text']).first()
#             if not f:
#                 feedback = Feedback(1, 'comment', comment['data']['text'], 'note', note.id, 0)
#                 db.session.add(feedback)
#                 db.session.commit()

# second pass (server -> trello)
# print "SECOND PASS"
ideas = Note.query.filter(Note.kind.ilike('designidea'), Note.context_id==context.id).all()
print "%s ideas to sync." % len(ideas)
num_new_cards = 0
for i in ideas:
    # look if it does not exists in trello create it, else update it
    card = trello_api.get_card_by_id(i.id)
    feedbacks_comment = Feedback.query.filter(Feedback.table_name.ilike('note'), Feedback.row_id==i.id, Feedback.kind=='comment').all()
    feedbacks_like = Feedback.query.filter(Feedback.table_name.ilike('note'), Feedback.row_id==i.id, Feedback.kind=='like').all()
    new_desc = i.to_trello_desc() + "\r\n#likes: " + str(len(feedbacks_like)) + "\r\n#comments: " + str(len(feedbacks_comment))
    new_card = None
    if not card:
        # create it
        num_new_cards = num_new_cards + 1
        if not i.status or i.status == '':
            i.status = trello_api.DEFAULT_LIST
            i.modified_at = datetime.now()
        list_name = i.status
        list_id = trello_api.get_list_id(list_name)
        if not list_id:
            i.status = trello_api.DEFAULT_LIST
            list_name = trello_api.DEFAULT_LIST