Beispiel #1
0
def prepare_content(handler, gcname, content):
    # Same index retrieval used for unique group name checking
    groups = Group.gql("WHERE name_c=:1 LIMIT 1", gcname)
    if groups.count() != 1:
        handler.error(404)
        handler.response.out.write("Group identifier " + gcname + " not found")
        return
    group = groups[0];
    qres = recent_group_reviews(group)
    picurl = "img/emptyprofpic.png"
    if group.picture:
        picurl = "grppic?groupid=" + str(group.key().id())
    # facebook doesn't like "../" relative urls
    if "localhost" in handler.request.url:
        picurl = "../" + picurl
    else:
        picurl = "http://www.fgfweb.com/" + picurl
    content = re.sub('\$GROUPNAME', group.name, content)
    content = re.sub('\$GROUPDESCR', group.description, content)
    content = re.sub('\$IMGSRC', picurl, content)
    content = re.sub('\$GROUPID', str(group.key().id()), content)
    content = re.sub('\$GROUPJSON', obj2JSON(group), content)
    content = re.sub('\$REVDATA', qres2JSON(
            qres.objects, "", -1, ""), content)
    refer = handler.request.referer
    if refer:
        refer = "<img src=\"../bytheimg?grpinqref=" +\
            safeURIEncode(refer) + "\"/>\n"
    else:
        refer = "<img id=\"btwimg\" src=\"../bytheimg?grpinq=" +\
            str(group.key().id()) + "\"/>\n"
    content = re.sub('\$REFER', refer, content)
    content = re.sub('\&quot;', "\\\"", content)  #browser interp pre-parse
    return content
Beispiel #2
0
 def get(self):
     ctype = normalize_mctr_type(self)
     if not ctype:
         return
     parid = intz(self.request.get("parentid"))  # sets to 0 if not found
     acc = None
     if not ctype == "Coop":
         acc = moracct.authenticated(self.request)
         if not acc:
             return srverr(self, "403", "Authentication failed")
     # Anyone following a theme has stats access, but profiles are private
     if ctype == "PenName":
         pnm = rev.acc_review_modification_authorized(acc, self)
         if not pnm or (pnm and pnm.key().id() != parid):
             return srverr(self, "403",
                           "You may only view stats for your own profile")
     elif (ctype == "Site" and 
         (not acc or acc.key().id() != 11005) and 
         (not self.request.host_url.startswith('http://localhost'))):
         return srverr(self, "403", 
                       "Access stats through your profile or theme")
     cqk = ctype + "CtrQuery" + str(parid)
     res = memcache.get(cqk)
     counter = get_mctr(ctype, parid)
     if res:
         res = json.loads(res)
         # if last saved counter is not the current counter, and the 
         # current counter is not temporary, then results are old
         if len(res) and res[-1]["day"] != counter.day and counter.modified:
             res = ""
             memcache.set(cqk, "")
     if res:
         counter = db.to_dict(counter)
         if len(res) and res[-1]["day"] == counter["day"]:
             res[-1] = counter
         else:
             res.append(counter)
         return moracct.writeJSONResponse(json.dumps(res, True), 
                                          self.response)
     refp = ctype + "Counter" + str(parid)
     daysback = 70  # max 10 weeks back if not restricted by batch_size
     dtnow = datetime.datetime.utcnow()
     thresh = dt2ISO(dtnow - datetime.timedelta(daysback))
     vq = None
     if ctype == "Site":
         vq = VizQuery(MembicCounter, "WHERE day > :1", thresh)
     else:
         vq = VizQuery(MembicCounter, "WHERE refp = :1 AND day > :2", 
                       refp, thresh)
     ctrs = vq.run(read_policy=db.EVENTUAL_CONSISTENCY, batch_size=1000)
     jsondat = moracct.qres2JSON(ctrs)
     memcache.set(cqk, jsondat)
     moracct.writeJSONResponse(jsondat, self.response)
Beispiel #3
0
def write_group_content(content, review):
    groups = []
    gids = extract_array_field_value("postedgroups", review.svcdata)
    for idx, grpid in enumerate(gids):
        grpid = grpid[1:len(grpid) - 1]  # strip quotes
        group = cached_get(intz(grpid), Group)
        if group:
            groups.append(group)
    content = re.sub('\$GRPSJSON', qres2JSON(groups, "", -1, ""), content)
    linkhtml = ""
    for group in groups:
        linkhtml += "<a href=\"../groups/" + canonize(group.name) + "\">" +\
            group.name + "</a>\n"
    content = re.sub('\$GRPLINKS', linkhtml, content)
    return content
Beispiel #4
0
def prepare_content(handler, cpen, content):
    # Same index retrieval already used by pen.py NewPenName
    pens = PenName.gql("WHERE name_c=:1 LIMIT 1", cpen)
    if pens.count() != 1:
        handler.error(404)
        handler.response.out.write("Blog identifier " + cpen + " not found")
        return
    pen = pens[0];
    # filter sensitive PenName fields
    pen.mid = 0
    pen.gsid = "0"
    pen.fbid = 0
    pen.twid = 0
    pen.ghid = 0
    pen.abusive = ""
    # retrieve reviews
    qres = fetch_blog_reviews(pen)
    # write content
    picurl = "img/emptyprofpic.png"
    if pen.profpic:
        picurl = "profpic?profileid=" + str(pen.key().id())
    # facebook doesn't like "../" relative urls
    if "localhost" in handler.request.url:
        picurl = "../" + picurl
    else:
        picurl = "http://www.fgfweb.com/" + picurl
    content = re.sub('\$PENNAME', pen.name, content)
    content = re.sub('\$PAGEDESCR', make_page_desc(handler, pen), content)
    content = re.sub('\$IMGSRC', picurl, content)
    content = re.sub('\$PENID', str(pen.key().id()), content)
    content = re.sub('\$PENJSON', obj2JSON(pen), content)
    content = re.sub(', "abusive": ""', '', content)  #bad SEO :-)
    content = re.sub('\$REVDATA', qres2JSON(
            qres.objects, "", -1, ""), content)
    refer = handler.request.referer
    if refer:
        refer = "<img src=\"../bytheimg?bloginqref=" +\
            safeURIEncode(refer) + "\"/>\n"
    else:
        refer = "<img id=\"btwimg\" src=\"../bytheimg?bloginq=" +\
            str(pen.key().id()) + "\"/>\n"
    content = re.sub('\$REFER', refer, content)
    content = re.sub('\&quot;', "\\\"", content)  #browser interp pre-parse
    return content