def post(self): if len(self.request.POST) == 4 and 'handle' in self.request.POST \ and 'real_name' in self.request.POST \ and 'email' in self.request.POST \ and 'bio' in self.request.POST: handle = self.request.POST.getall('handle')[0] template_dict = {} hacker = Hacker.get_current_hacker() other = Hacker.gql('WHERE handle = :1', handle).get() if (not handle or len(handle) > 12 or any(l not in self.valid_letters for l in handle)): template_dict['error'] = 'Pick something sensible, you moron.' elif other and other.user_id != hacker.user_id: template_dict['error'] = 'Sorry, already taken.' elif handle.lower() in self.banned_names: template_dict['error'] = self.banned_names[handle] else: real_name = self.request.POST.getall('real_name')[0] if real_name: hacker.real_name = real_name email = self.request.POST.getall('email')[0] if email: hacker.email = email bio = self.request.POST.getall('bio')[0] if bio: hacker.bio = bio hacker.handle = handle hacker.save() template_dict['error'] = 'Profile updated' self.render_template('account', template_dict=template_dict)
def post(self): post = self.request.POST if post['kind'] == 'badge': b = Badge(name=post['name'], description=post['description'], category=post['category'], image=post['image'], value=int(post['value'])) b.save() elif post['kind'] == 'article': a = NewsArticle(title=post['title'], author=post['author'], body=post['body'], date=datetime.date.today()) a.save() elif post['kind'] == 'award': badge = Badge.gql('WHERE name = :1', post['badge']).get() for h in post.getall('hackers'): hacker = Hacker.gql('WHERE handle = :1', h).get() a = Award(hacker=hacker, badge=badge, date=datetime.date.today(), proof=post['proof']) a.save() hacker.score_cache = hacker.score + badge.value hacker.save() self.get()
def post(self): post = self.request.POST if post['kind'] == 'badge': b = Badge(name=post['name'], description=post['description'], category=post['category'], image=post['image'], value=int(post['value'])) b.save() elif post['kind'] == 'article': a = NewsArticle(title=post['title'], author=post['author'], body=post['body'], date=datetime.date.today()) a.save() elif post['kind'] == 'award': badge = Badge.gql('WHERE name = :1', post['badge']).get() for h in post.getall('hackers'): hacker = Hacker.gql('WHERE handle = :1', h).get() a=Award(hacker=hacker, badge=badge, date=datetime.date.today(), proof=post['proof']) a.save() hacker.score_cache = hacker.score + badge.value hacker.save() self.get()
def get(self): handle = self.request.get('handle', None) if handle is None: # First request, just get the first handle out of the datastore. hacker = Hacker.gql('ORDER BY handle DESC').get() if not hacker: # No hackers in database self.response.headers['Content-Type'] = 'text/plain' self.response.out.write("No Hackers in database") return handle = hacker.handle query = Hacker.gql('WHERE handle <= :1 ORDER BY handle DESC', handle) hackers = query.fetch(limit=2) current_hacker = hackers[0] if len(hackers) == 2: next_handle = hackers[1].handle next_url = '/admin/hacker_migration?handle=%s' % urllib.quote( next_handle) else: next_handle = 'FINISHED' next_url = '/' # Finished processing, go back to main page. awards_updated = 0 talks_updated = 0 updated_hacker = False # Add a new member if this Hacker has not been migrated if not Member.gql('WHERE handle = :1', current_hacker.handle).get(): new_member = Member(user_id=current_hacker.user_id, email=current_hacker.email, handle=current_hacker.handle, bio=current_hacker.bio, real_name=current_hacker.real_name) new_member.put() # Find any award or talk entities that reference the old hacker # and remap them awards = Award.gql('WHERE hacker = :1', current_hacker) for award in awards: award.member = new_member if hasattr(award, 'hacker'): del award.hacker award.put() awards_updated += 1 talks = Talk.gql('WHERE member = :1', current_hacker) for talk in talks: talk.member = new_member talk.put() talks_updated += 1 updated_hacker = True # Delete the Hacker current_hacker.delete() context = { 'current_handle': handle, 'updated_hacker': updated_hacker, 'awards_updated': awards_updated, 'talks_updated': talks_updated, 'next_handle': next_handle, 'next_url': next_url, } self.render_template('hacker_migration', context)
def get(self): handle = self.request.get('handle', None) if handle is None: # First request, just get the first handle out of the datastore. hacker = Hacker.gql('ORDER BY handle DESC').get() if not hacker: # No hackers in database self.response.headers['Content-Type'] = 'text/plain' self.response.out.write("No Hackers in database") return handle = hacker.handle query = Hacker.gql('WHERE handle <= :1 ORDER BY handle DESC', handle) hackers = query.fetch(limit=2) current_hacker = hackers[0] if len(hackers) == 2: next_handle = hackers[1].handle next_url = '/admin/hacker_migration?handle=%s' % urllib.quote(next_handle) else: next_handle = 'FINISHED' next_url = '/' # Finished processing, go back to main page. awards_updated = 0 talks_updated = 0 updated_hacker = False # Add a new member if this Hacker has not been migrated if not Member.gql('WHERE handle = :1', current_hacker.handle).get(): new_member = Member(user_id=current_hacker.user_id, email=current_hacker.email, handle=current_hacker.handle, bio=current_hacker.bio, real_name=current_hacker.real_name) new_member.put() # Find any award or talk entities that reference the old hacker # and remap them awards = Award.gql('WHERE hacker = :1', current_hacker) for award in awards: award.member = new_member if hasattr(award, 'hacker'): del award.hacker award.put() awards_updated += 1 talks = Talk.gql('WHERE member = :1', current_hacker) for talk in talks: talk.member = new_member talk.put() talks_updated += 1 updated_hacker = True # Delete the Hacker current_hacker.delete() context = { 'current_handle': handle, 'updated_hacker': updated_hacker, 'awards_updated': awards_updated, 'talks_updated': talks_updated, 'next_handle': next_handle, 'next_url': next_url, } self.render_template('hacker_migration', context)
def get(self, handle): query = Hacker.gql('WHERE handle = :1', urllib.unquote(handle)) hacker = iter(query).next() if query.count() else None self.render_template('member', {'hacker': hacker})