def execute_diary_task(dbo, username, tasktype, taskid, linkid, selecteddate): """ Runs a diary task tasktype: ANIMAL or PERSON taskid: The ID of the diarytaskhead record to run linkid: The ID of the animal or person to run against selecteddate: If the task has any detail records with a pivot of 0, the date to supply (as python date) """ def fix(s): return s.replace("<", "<").replace(">", ">") rollingdate = dbo.today() dtd = dbo.query( "SELECT * FROM diarytaskdetail WHERE DiaryTaskHeadID = ? ORDER BY OrderIndex", [taskid]) tags = {} linktype = ANIMAL if tasktype == "ANIMAL": linktype = ANIMAL tags = wordprocessor.animal_tags(dbo, animal.get_animal(dbo, int(linkid))) elif tasktype == "PERSON": linktype = PERSON tags = wordprocessor.person_tags(dbo, person.get_person(dbo, int(linkid))) for d in dtd: if d["DAYPIVOT"] == 9999: rollingdate = selecteddate else: rollingdate = i18n.add_days(rollingdate, int(d["DAYPIVOT"])) insert_diary(dbo, username, linktype, int(linkid), rollingdate, \ d["WHOFOR"], \ wordprocessor.substitute_tags(fix(d["SUBJECT"]), tags, True), \ wordprocessor.substitute_tags(fix(d["NOTE"]), tags, True))
def execute_diary_task(dbo, username, tasktype, taskid, linkid, selecteddate): """ Runs a diary task tasktype: ANIMAL or PERSON taskid: The ID of the diarytaskhead record to run linkid: The ID of the animal or person to run against selecteddate: If the task has any detail records with a pivot of 0, the date to supply (as python date) """ def fix(s): return s.replace("<", "<").replace(">", ">") rollingdate = i18n.now(dbo.timezone) dtd = db.query(dbo, "SELECT * FROM diarytaskdetail WHERE DiaryTaskHeadID = %d ORDER BY ID" % int(taskid)) tags = {} linktype = ANIMAL if tasktype == "ANIMAL": linktype = ANIMAL tags = wordprocessor.animal_tags(dbo, animal.get_animal(dbo, int(linkid))) elif tasktype == "PERSON": linktype = PERSON tags = wordprocessor.person_tags(dbo, person.get_person(dbo, int(linkid))) for d in dtd: if d["DAYPIVOT"] == 9999: rollingdate = selecteddate else: rollingdate = i18n.add_days(rollingdate, int(d["DAYPIVOT"])) insert_diary(dbo, username, linktype, int(linkid), rollingdate, \ d["WHOFOR"], \ wordprocessor.substitute_tags(fix(d["SUBJECT"]), tags, True), \ wordprocessor.substitute_tags(fix(d["NOTE"]), tags, True))
# If we're posting as us, but to a page, post to the page # but stick with the user's access_token if page_name != "": post_to = page_id # Grab the animal details a = animal.get_animal(dbo, utils.cint(oauth_state[1:])) # Bail out if we have a problem if a is None: raise utils.ASMValidationError( "Facebook response did not contain a valid animal ID (got %s)" % oauth_state[1:]) # Generate the body of the post from our facebook template tags = wordprocessor.animal_tags(dbo, a) template = configuration.facebook_template(dbo) posttext = wordprocessor.substitute_tags(template, tags, False, "$$", "$$") # Post on the wall try: l = dbo.locale fb_url = "https://graph.facebook.com/%s/photos?access_token=%s" % ( post_to, access_token) al.debug( "FB posting photo and text '%s' to '%s' at %s" % (posttext, page_name, fb_url), "social.post_animal_facebook", dbo) imagedata = dbfs.get_string(dbo, a["WEBSITEMEDIANAME"]) req, hdr, response = utils.post_multipart( fb_url,
access_token = page_access_token # If we're posting as us, but to a page, post to the page # but stick with the user's access_token if page_name != "": post_to = page_id # Grab the animal details a = animal.get_animal(dbo, utils.cint(oauth_state[1:])) # Bail out if we have a problem if a is None: raise utils.ASMValidationError("Facebook response did not contain a valid animal ID (got %s)" % oauth_state[1:]) # Generate the body of the post from our facebook template tags = wordprocessor.animal_tags(dbo, a) template = configuration.facebook_template(dbo) posttext = wordprocessor.substitute_tags(template, tags, False, "$$", "$$") # Post on the wall try: l = dbo.locale fb_url = "https://graph.facebook.com/%s/photos?access_token=%s" % (post_to, access_token) al.debug("FB posting photo and text '%s' to '%s' at %s" % (posttext, page_name, fb_url), "social.post_animal_facebook", dbo) imagedata = dbfs.get_string(dbo, a["WEBSITEMEDIANAME"]) req, hdr, response = utils.post_multipart(fb_url, ( ("message", utils.decode_html(posttext).encode("utf-8")),), ( ("source", "pic.jpg", imagedata), )) al.debug("FB response: %s" % response, "social.post_animal_facebook", dbo) # If the option is on and all was ok, make a note in the log if configuration.facebook_log(dbo):