def post(self, comment): """ Edit comment via POST """ comment = Comment.get(comment) if UserData.current().user_id == comment.user.user_id: comment.body = self.request.get('value') comment.put() self.response.write(comment.body)
def post(self): action = self.request.get("action") # logging.info("action = %s", action) if action == "": name = self.request.get("name", "") desc = self.request.get("desc", "") if name == "": self.redirect('/groups/') return group = Group.new_group(name=name, desc=desc, ) if group is None: # group already existed and you are not the owner return self.redirect('/mygroups/') self.redirect('/group/?name=%s' % group.name) return elif action == "delete": name = self.request.get("name") group = Group.get_by_key_name(name) if group is None: self.redirect('/groups/') user = UserData.current() # only the owner can delete the group if group.owner.user_id == user.user_id: group.delete() self.redirect('/groups/') return
def post(self): action = self.request.get("action") if action == "newdonation": user = UserData.current() group_id = self.request.get("group") title = self.request.get("title") body = self.request.get("body") # logging.info(repr(body)) body = body.replace("\r\n", "<br />") tmp = self.request.get("specs") logging.info(repr(tmp)) # logging.info() specs = """<ul>""" for spec in tmp.split("\r\n"): # logging.info(spec) if spec != "": specs += """<li>%s</li>""" % spec specs += """</ul>""" logging.info(specs) donation = Donation.create_donation(user=user, group=db.Key.from_path("Group", group_id), specs = str(specs), title=title, body=body) if donation is None: self.redirect('/group/%s' % group_id) return self.redirect('/donation/%s' % donation.key().id()) return if action == "newplea": user = UserData.current() donationid = self.request.get("donationid") donation = Donation.get_by_id(int(donationid)) title = self.request.get("title") body = self.request.get("body") plea = Plea.new_plea(user=user, donation=donation, title=title, body=body) self.redirect('/donation/%s' % donationid) return self.redirect('/donations/')
def get(self, comment): """ Delete comment via GET """ user = UserData.current() comment = Comment.get(comment) if user.developer or user.moderator \ or user.user_id == comment.user.user_id: comment.delete() self.response.write("Deleted")
def render(self, template = None, **args): if template is None: raise Exception("No 'template' argument to render from") temp = env.get_template(template) args['user'] = UserData.current() args['user_logout'] = users.create_logout_url("/") args['user_login'] = users.create_login_url(args.get("login_url", "/")) self.response.write(temp.render(args))
def get(self): # user = users.get_current_user() user = UserData.current() collections = SNPCollection.all().ancestor(user) # check or update cache # render from template render = self.render("collectionlist.html",collections=collections) self.out(rendered=render, )
def pop(): """Populates the database """ user = UserData.current() if user is None: user = UserData.get_from_db_key_email("*****@*****.**") # create test-user # user = users.User("*****@*****.**") # raise Exception("kan ikke logge ind!") companies = [] for name, desc in [("Umbrella Corp.", "evil/stupid"), ("Cabbage Corp.", "My Cabbages!"), ("SinCorp", "Oooops"), ("Black Mesa", "Resonance Cascade"), ("Mega Corp.", "Final Fantasy")]: # create companies group = Group.new_group(name=name, desc=desc, owner=user) if group is None: continue companies.append(group) # create donation from company for company in companies: name = company.name for i in xrange(1,5): donation = Donation.create_donation(group=company, user=user, title="free stuff from %s! - item: %s" % (name, i), body="Lorem ipsum dolor sit amet, consectetur adipiscing elit. \ Proin eros eros, commodo vitae elementum ac, fermentum non velit. \ Fusce eu turpis sed urna aliquet fermentum ac eu felis. \ Maecenas ut urna vitae libero congue fringilla eget eget massa.\ Pellentesque vel sollicitudin dolor. \ Aenean porttitor lobortis erat, vitae tempor risus interdum in.", pickup=True) # if donation is None: # print "error_2" # continue for i in xrange(3): donation.add_plea(title="I AM NOT WORTHY_%s" % i, body="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eros eros, commodo vitae elementum ac, fermentum non velit. Fusce eu turpis sed urna aliquet fermentum ac eu felis. Maecenas ut urna vitae libero congue fringilla eget eget massa. Pellentesque vel sollicitudin dolor", user=user) Donation.updateSearchIndex() print "done populating database"
def get(self): donation_id = self.request.get("donationid", "") if donation_id == "": self.redirect('/donations/') return donation = Donation.get_by_id(int(donation_id)) if donation is None: self.redirect('/donations/') return owner = False user = UserData.current() if user is not None: if user.user_id == donation.created_by.user_id: logging.info("owner!") owner = True action = self.request.get("action") if action == "deletedonation": donation.delete() elif action == "deleteplea": id = self.request.get("id", "") if id == "": self.redirect('/donations/') return # user = UserData.current().user_id # if user != donation.created_by.user_id or user == plea.user.user_id): # self.redirect('/donation/%s' % donation_id) delete_model("Plea", int(id)) self.redirect('/donation/%s' % donation_id) donation.update_plea_count() return elif action == "acceptplea": pleaid = self.request.get("pleaid", "") if pleaid == "": return self.redirect('/donations/') # user = UserData.current() donation.accept_plea(pleaid) # inform pleas that donation is closed # self.redirect('/donation/%s' % donation_id) return self.render("donationview.html", donation=donation, owner=owner) elif action == "closedonation": if not donation.close_donation(): return self.redirect('/donations/') return self.render("donationview.html", donation=donation, owner=owner) logging.info("test2") return self.redirect('/donations/')
def get(self, name): user = UserData.current() coll = SNPCollection.all().ancestor(user).filter("name =", name).get() if coll is None: logging.info("collection does not exist") self.redirect("/collections/") return logging.info("deleting collection %s" % name) coll.delete() self.redirect("/collections/") return
def close_donation(self): # only owner of donation can accept a plea user = UserData.current().user_id if user != self.created_by.user_id: return False self.active = False self.put() # TODO: informa pleantif that plea was accepted return True
def post(self, gene): gene = Gene.gql("WHERE name = :1", gene).get() comment = Comment() comment.gene = gene.key() comment.body = self.request.get("comment") comment.user = UserData.current().user_id #users.get_current_user() comment.date = datetime.now() comment.put() self.out(gene=gene)
def get(self, id): donation = Donation.get_by_id(int(id)) if donation is None: self.redirect('/') owner = False user = UserData.current() if user is not None: if user.user_id == donation.created_by.user_id: owner = True self.render("donationview.html", donation=donation, login_url="/donation/%s" % id, owner=owner)
def testCreateCollection(self): """Test collection creation - try to create a new collection called 'test' - test that this collection has actually been added to the database afterwards """ test_coll = "test" response = self.testapp.post('/collection/', {'name': test_coll}) user = UserData.current() coll = SNPCollection.all().ancestor(user).filter("name =", test_coll).get() self.assertIsNotNone(coll)
def accept_plea(self, pleaid = None): # only owner of donation can accept a plea user = UserData.current().user_id if user != self.created_by.user_id: return False if pleaid is None: self.active = False self.put() return plea = Plea.get_by_id(int(pleaid)) if plea is None: return False self.active = False self.accepted_plea = plea self.put() # inform winner # emails = [plea.user.user.email() for plea in self.pleas] # mail.send_mail(sender="E-WASTE Donation manager <*****@*****.**>", # to=emails, # subject="Donation '%s' has closed" % self.title, # body=""" # Dear E-Waste user: # Your plea has been accepted! # Go to www.e-waster.appspot.com/donation/%s to check it out! # """ % self.key().id()) # inform looser # emails = [plea.user.user.email() for plea in self.pleas if plea.user.user_id != user] # if len(emails) == 0: # return True # mail.send_mail(sender="E-WASTE Donation manager <*****@*****.**>", # to=emails, # subject="Donation '%s' has closed" % self.title, # body=""" # Dear E-Waste user: # The donation you plead for has closed. # I'm afraid you didn't win the plea, but don't be deterred! # Try and see if there's anything else you might be interested in! # www.e-waster.appspot.com/donations # """) return True
def out(self, **dictionary): """Render the template, passing a dict as inputs""" if self._template is None: # Get template from controller / method names actionName = self.__class__.__name__ self._template = actionName+".html" dictionary['user'] = UserData.current() dictionary['user_logout'] = users.create_logout_url('/') dictionary['user_login'] = users.create_login_url('/') dictionary['user_admin'] = users.is_current_user_admin() temp = jTemplate._e.get_template(self._template) self.response.write(temp.render(dictionary))
def post(self, pubmed_id): self.setTemplate('studyview.html') study = Study.get_by_key_name(pubmed_id) if study is None: self.redirect('/studies/') return comment = Comment() comment.study = study.key() comment.body = self.request.get("comment") comment.user = UserData.current() comment.date = datetime.now() comment.put() self.out(study=study)
def post(self): # logging.info("yeah!") user = UserData.current() name = self.request.get("name") if name == "": self.redirect("/collections/") return coll = SNPCollection.all().ancestor(user).filter("name =", name).get() if coll is None: coll = SNPCollection(parent=user, name=name) coll.put() self.redirect("/collection/?name=%s" % name) return
def get(self, collection_id): # snp_disease_collection for diseases grouped by snp # render = memcache.get(collection_id, namespace="snp_disease_collection") # if render is None: user = UserData.current() # coll = db.get(db.Key.from_path("SNPCollection", collection_id, parent=user.key())) coll = SNPCollection.all().ancestor(user).filter("name =", collection_id).get() if coll is None: self.redirect("/collections/") return snps = db.get(coll.snps) render = self.render("snp_disease_collection.html", snps=snps, collection=coll) # memcache.set(collection_id, render, namespace="snp_disease_collection") self.out(rendered=render)
def get(self): """view or create specified collection""" collection_name = self.request.get("name") if collection_name == "": self.redirect("/collections/") return # login is mandatory # user = users.get_current_user() user = UserData.current() # query for particular collection, creating if it does not exist coll = SNPCollection.all().ancestor(user).filter("name =", collection_name).get() if coll is None: # should have a 404-page self.redirect("/collections/") return # check or update cache # render from template render = self.render("collectionview.html",collection=coll) self.out(rendered=render)
def new_group(name=None, owner=None, desc=None, non_prof=False): """1) make sure that any new group is globally unique 2) only the owner of a group can edit the description of a company 3) if owner is None, user is set to current user""" if owner is None: owner = UserData.current() if name is None: return None group = Group.all().filter("name =", name).get() # if the group is owned by this user if group is not None: if group.owner.user_id == owner.user_id: # group exists - change description if new one is different if desc != group.description: group.description = desc group.put() return group return None group = Group(key_name=name, owner=owner, description=desc, non_prof=non_prof, name=name) group.put() return group
def get(self): user = UserData.current() groups = user.group_set self.render("usergrouplist.html", groups=groups)
def get(self): user = UserData.current() self.out(username=user.nickname)
def get(self, collection_name): # user = users.get_current_user() user = UserData.current() coll = SNPCollection.all().ancestor(user).filter("name =", collection_name).get() if coll is None: # logging.info("redirecting") # if collection doesn't exist - redirect to list of collections self.redirect("/collections/") return # we support a number of actions # addsnps = add a list of snps to a collection # action = self.requst.get("action") error = [] warning = [] # action = "addsnps" # if action == "addsnps": logging.info("adding snps to coll: %s" % collection_name) snps = self.request.get("snps") # for testing # snps = '10260404,3825776,12284594,rs1805007,12345' # comma seperated list of snps snpids = [snp.strip() for snp in snps.split(',')] # verify input: # - if snpid is not a valid integer-value # replace with None and add to list of 'invalid' ids # (might be because its prefixed with RS/rs) invalid_keys = [] for i in xrange(len(snpids)): snp = snpids[i] try: # try to convert to int int(snp) except: invalid_keys.append(snp) snpids[i] = None # collect errors if len(invalid_keys) > 0: error.append("invalid keys: %s" % invalid_keys) # generate composite keys from the list of SNPs which are not None snpids = [snpid for snpid in snpids if not snpid is None] keys = [db.Key.from_path("Snp", snpid) for snpid in snpids] # logging.debug("keys to add: ") # retrieve all Snp-instances from these keys # - note: invalid keys / non-existent keys return with 'None' # aka: "the SNP-id might be valid, but it is not in the GWAS catalog" snp_keys = db.get(keys) # logging.info(snp_keys) # logging.info("ids: %s" % [snp.key() for snp in snp_keys if snp]) # all 'None' keys are from ids unknown to GWAS, compile a list of these unknown_keys = [snpids[i] for i in xrange(len(snp_keys)) if snp_keys[i] is None] if unknown_keys: warning.append("Keys unknown to the GWAS catalog: %s" % unknown_keys) # add keys to collection # list = [snp.key() for snp in snp_keys if snp] # logging.info("WTF: %s" % list) for key in [snp.key() for snp in snp_keys if snp is not None]: if key not in coll.snps: coll.snps.append(key) coll.count = len(coll.snps) coll.put() # try: # coll.addMultipleSNP(snp_keys) # except Exception, e: # logging.warning("issues inserting: %s" % e) # error.append("Unknown issue adding snps to collection") # render logging.info("errors: %s" % error ) logging.info("warning: %s" % warning) render = self.render("collectionview.html", collection=coll) self.out(rendered=render, error=error, warning=warning)