Exemple #1
0
 def post(self):
     post = self.request.POST
     if post['kind'] == 'badge':
         badge = Badge(name=post['name'],
                       description=post['description'],
                       category=post['category'],
                       image=post['image'],
                       value=int(post['value']))
         badge.save()
     elif post['kind'] == 'article':
         date = datetime.datetime.strptime(post['date'], '%Y-%m-%d').date()
         article = NewsArticle(title=post['title'],
                               author=post['author'],
                               body=post['body'],
                               date=date)
         article.save()
     elif post['kind'] == 'award':
         badge = Badge.get_by_id(int(post['badge']))
         for member in post.getall('members'):
             member = Member.get_by_id(int(member))
             award = Award(member=member,
                           badge=badge,
                           date=datetime.date.today(),
                           proof=post['proof'])
             award.save()
     elif post['kind'] == 'talk':
         talk = Talk(title=post['title'],
                     date=datetime.datetime.strptime(
                         post['date'], '%Y-%m-%d').date(),
                     description=post['description'],
                     member=Member.get_by_id(int(post['member'])),
                     video=post['video'])
         talk.put()
     self.get()
Exemple #2
0
def dashboard(request):
	'''
		This function shows the lastgame events and the user private messages.
		If is the users first time, it appends to his account the inicial credits. 
	'''
	#requests user credits
	total_credits=UserCredit.objects.filter(user=request.user)
	#if is the first time adds the credits
	if len(total_credits) == 0:
		inicial_credits=UserCredit(user=request.user, current_credits=DEFAULT_CREDITS)
		inicial_credits.save()
		total_credits=inicial_credits

		badge=Award(title="Tester", winner=request.user, creation_date=datetime.date.today(), badge="firstbadge.png")
		badge.save()
	else:
		total_credits=total_credits[0]
	
	#gets the menu elements and game events from the database
	menu_items=MenuItem.objects.all()
	last_events=GEvent.objects.all()[:20]
	
	#gets users private messagens and send form
	private_messages=PrivateMessage.objects.filter(receiver=request.user)
	form=MessageForm()
	
	#render page and reply to user
	return render_to_response('dash.html',{'user':request.user.username,
											'name':request.user.first_name,'menu_items':menu_items, 'credits':total_credits.current_credits, 'last_events':last_events, 'private_messages':private_messages, 'form':form},
											RequestContext(request))
Exemple #3
0
def add_award(request):
    if request.method == 'POST':
        form = AwardForm(request.POST)
        if form.is_valid():
            user = request.user
            title = form.cleaned_data['title']
            date = form.cleaned_data['date']
            description = form.cleaned_data['description']

            award = Award(member=user,
                          title=title,
                          date=date,
                          description=description)
            award.save()

            return redirect('member:profile')
        else:
            return render_to_response('member/add_award.html', {
                'form': form,
            }, RequestContext(request))
    else:
        form = AwardForm()
        return render_to_response('member/add_award.html', {
            'form': form,
        }, RequestContext(request))
Exemple #4
0
 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()
Exemple #5
0
    def load_awards(cls, soup, event):
        sections = soup.find_all(
            class_="sites-embed-border-on sites-embed sites-embed-full-width")

        awards = []
        for s in sections:
            title = s.find("h4").text
            if "Award" in title:
                text = cls.AWARD_FILTER.sub("", s.get_text())
                # replacing Place and Winner: with Team compensates for lack of prefixing in some
                # ftcpenn pages
                text = re.sub(r"Place:?", "Team ", text)
                text = re.sub(r"Winner:?", "Team ", text)
                # there's a case in 1415pacmp that fools our award detector.
                # oops!
                text = re.sub(r"Teal\s+Team\s+6", "", text)
                title = re.sub(r"Award.*$", "Award", title)

                winners = cls.TEAM_AWARD.findall(text)
                award_type = AwardType.get_type(title)
                for i, t in enumerate(winners, 1):
                    a = Award(name=title,
                              award_type=award_type,
                              event_key=event.key,
                              team_key='ftc' + t,
                              award_place=i)
                    if i == 1:
                        a.name += " Winner"
                    else:
                        a.name += " Finalist"
                    awards.append(a)
        return awards
Exemple #6
0
def init_awards():
    db.session.query(Nomination).delete()
    db.session.query(Award).delete()

    award_order = [
        "Best Director",
        "Best Production Manager",
        "Best Stage Manager",
        "Best Technical Director",
        "Best Music Director",
        "Best Choreography",
        "Best Actress in a Lead Role",
        "Best Actor in a Lead Role",
        "Best Supporting Actress",
        "Best Supporting Actor",
        "Best Featured Performer",
        "Best Ensemble",
        "Best Duo",
        "Best Improv Moment",
        "Best Sketch Actor",
        "Best Cover",
        "Worst Cover",
        "Best Set",
        "Best Lighting",
        "Best Sound",
        "Best Costumes",
        "Best Props",
        "Best Publicity",
        "Best Hair & Makeup",
        "Best House",
        "Best Original Work",
        "Best Strike/Load-in Moment",
        "Worst Strike/Load-in Moment",
        "Best Prank",
        "Most Likely to Injure Oneself",
        "Kevin Perry Technical Insanity Award",
        "Donkeypunch Award",
        "Coolest Rookie",
        "Coolest Veteran",
        "Party Animal",
        "Darren M. Canady Sassypants Award",
        "Cutest Couple",
        "Cutest Potential Couple",
        "Most Successful Flirt",
        "Least Successful Flirt",
        "Most Corrupted",
        "Shannon Deep S'n'S Mom Award",
        'The "It Sounded Like A Good Idea at the Time" Award',
        "King and Queen of the Black Chairs Award",
        "Best Late Show Moment",
        "Nathaniel Biggs Coolest Uncle Award",
        "Nathan Blinn Best Black Chairs Argument",
        "New Kudos Category",
        "Retire a Kudos Category",
    ]

    for i in range(len(award_order)):
        db.session.add(Award(name=award_order[i], order=(i + 1) * 10))

    db.session.commit()
Exemple #7
0
 def post(self):
     post = self.request.POST
     if post['kind'] == 'badge':
         badge = Badge(
             name=post['name'],
             description=post['description'],
             category=post['category'],
             image=post['image'],
             value=int(post['value'])
         )
         badge.save()
     elif post['kind'] == 'article':
         date = datetime.datetime.strptime(post['date'], '%Y-%m-%d').date()
         article = NewsArticle(
             title=post['title'],
             author=post['author'],
             body=post['body'],
             date=date
         )
         article.save()
     elif post['kind'] == 'award':
         badge = Badge.get_by_id(int(post['badge']))
         for member in post.getall('members'):
             member = Member.get_by_id(int(member))
             award = Award(
                 member=member,
                 badge=badge,
                 date=datetime.date.today(),
                 proof=post['proof']
             )
             award.save()
             member.score_cache = member.score + badge.value
             member.save()
     elif post['kind'] == 'talk':
         talk = Talk(
             title=post['title'],
             date=datetime.datetime.strptime(post['date'], '%Y-%m-%d').date(),
             description=post['description'],
             member=Member.get_by_id(int(post['member'])),
             video=post['video']
         )
         talk.put()
     self.get()
Exemple #8
0
 def post(self):
     post = self.request.POST
     if post['kind'] == 'badge':
         badge = Badge(
             name=post['name'],
             description=post['description'],
             category=post['category'],
             image=post['image'],
             value=int(post['value'])
         )
         badge.save()
     elif post['kind'] == 'award':
         badge = Badge.get_by_id(int(post['badge']))
         for member in post.getall('members'):
             member = Member.get_by_id(int(member))
             award = Award(
                 member=member,
                 badge=badge,
                 date=datetime.date.today(),
                 proof=post['proof']
             )
             award.save()
             member.score += badge.value
             member.save()
     elif post['kind'] == 'talk':
         talk = Talk(
             title=post['title'],
             date=utils.parse_date(post['date']),
             description=post['description'],
             member=Member.get_by_id(int(post['member'])),
             video=post['video']
         )
         talk.put()
     elif post['kind'] == 'taglineform':
         properties = GeneralSiteProperties.all().get()
         if properties == None:
             properties = GeneralSiteProperties(tag_line=post['tagline'])
             properties.put()
         else:
             properties.tag_line = post['tagline']
             properties.put()
     self.get()
Exemple #9
0
    async def generate_winners_finalists(cls, event, fail_silent=False):
        finals = (await MatchHelper.get_match_data(
            where="m.comp_level='f' AND m.event_key=$1",
            addn_sql="ORDER BY m.match_number",
            params=(event.key, )))
        #print(finals)
        if len(finals) == 0:
            if event.event_type == EventType.MEET:
                return
            logging.warning(
                f"[award_helper.py]: {event.key} doesn't have finals matches wtf"
            )
            if not fail_silent:
                raise Exception(f"query failed on {event.key} oops")
            return
        last_finals = finals[-1]
        if last_finals['m'].winner == 'red':
            winning_alliance = last_finals['red'].teams
            finalist_alliance = last_finals['blue'].teams
        else:
            winning_alliance = last_finals['blue'].teams
            finalist_alliance = last_finals['red'].teams
        awards = []
        for idx, team in enumerate(winning_alliance, 1):
            a = Award(name=event.award_prefix + "Winner",
                      award_type=AwardType.WINNING_ALLIANCE,
                      award_place=idx,
                      event_key=event.key,
                      team_key=team)
            awards.append(a)

        for idx, team in enumerate(finalist_alliance, 1):
            a = Award(name=event.award_prefix + "Finalist",
                      award_type=AwardType.FINALIST_ALLIANCE,
                      award_place=idx,
                      event_key=event.key,
                      team_key=team)
            awards.append(a)
        async with orm.pool.acquire() as conn:
            for a in awards:
                await a.upsert(conn=conn)
Exemple #10
0
 def post(self):
     post = self.request.POST
     if post['kind'] == 'badge':
         badge = Badge(name=post['name'],
                       description=post['description'],
                       category=post['category'],
                       image=post['image'],
                       value=int(post['value']))
         badge.save()
     elif post['kind'] == 'award':
         badge = Badge.get_by_id(int(post['badge']))
         for member in post.getall('members'):
             member = Member.get_by_id(int(member))
             award = Award(member=member,
                           badge=badge,
                           date=datetime.date.today(),
                           proof=post['proof'])
             award.save()
             member.score += badge.value
             member.save()
     elif post['kind'] == 'talk':
         talk = Talk(title=post['title'],
                     date=utils.parse_date(post['date']),
                     description=post['description'],
                     member=Member.get_by_id(int(post['member'])),
                     video=post['video'])
         talk.put()
     elif post['kind'] == 'taglineform':
         properties = GeneralSiteProperties.all().get()
         if properties == None:
             properties = GeneralSiteProperties(tag_line=post['tagline'])
             properties.put()
         else:
             properties.tag_line = post['tagline']
             properties.put()
     self.get()
Exemple #11
0
    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)