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 process_event(event_file, user):
    event_data = json.loads(event_file)
    event_name = event_data['name']
    event_place = event_data['place']
    event_date_from = datetime.strptime(event_data['date_from'], '%Y-%m-%d').date()
    event_date_to = datetime.strptime(event_data['date_to'], '%Y-%m-%d').date()
    event_timezone = event_data['timezone']
    if 'description' in event_data:
        event_description = event_data['description']
    else:
        event_description = ''

    ev = Event(owner=user,
               name=event_name,
               place=event_place,
               date_from=event_date_from,
               date_to=event_date_to,
               timezone=event_timezone,
               description=event_description,
               data=event_data
               )
    ev.put()

    for session in event_data['sessions']:
        session_name = session['name']
        session_room = session['room']
        tr = Session(owner=user,
                     name=session_name,
                     room=session_room,
                     event=ev.key)
        tr.put()

        for talk in session['talks']:
            talk_title = talk['title']
            talk_authors = talk['authors']
            talk_start = datetime.strptime(talk['start'], '%Y-%m-%d %H:%M')
            talk_end = datetime.strptime(talk['end'], '%Y-%m-%d %H:%M')
            if 'tags' in talk:
                talk_tags = talk['tags']
            else:
                talk_tags = []

            if 'abstract' in talk:
                talk_abstract = talk['abstract']
            else:
                talk_abstract = ''

            tk = Talk(owner=user,
                      session=tr.key,
                      title=talk_title,
                      authors=talk_authors,
                      start=talk_start,
                      end=talk_end,
                      tags=talk_tags,
                      abstract=talk_abstract
                      )

            tk.put()
Exemple #3
0
def process_event(event_file, user):
    event_data = json.loads(event_file)
    event_name = event_data['name']
    event_place = event_data['place']
    event_date_from = datetime.strptime(event_data['date_from'],
                                        '%Y-%m-%d').date()
    event_date_to = datetime.strptime(event_data['date_to'], '%Y-%m-%d').date()
    event_timezone = event_data['timezone']
    if 'description' in event_data:
        event_description = event_data['description']
    else:
        event_description = ''

    ev = Event(owner=user,
               name=event_name,
               place=event_place,
               date_from=event_date_from,
               date_to=event_date_to,
               timezone=event_timezone,
               description=event_description,
               data=event_data)
    ev.put()

    for session in event_data['sessions']:
        session_name = session['name']
        session_room = session['room']
        tr = Session(owner=user,
                     name=session_name,
                     room=session_room,
                     event=ev.key)
        tr.put()

        for talk in session['talks']:
            talk_title = talk['title']
            talk_authors = talk['authors']
            talk_start = datetime.strptime(talk['start'], '%Y-%m-%d %H:%M')
            talk_end = datetime.strptime(talk['end'], '%Y-%m-%d %H:%M')
            if 'tags' in talk:
                talk_tags = talk['tags']
            else:
                talk_tags = []

            if 'abstract' in talk:
                talk_abstract = talk['abstract']
            else:
                talk_abstract = ''

            tk = Talk(owner=user,
                      session=tr.key,
                      title=talk_title,
                      authors=talk_authors,
                      start=talk_start,
                      end=talk_end,
                      tags=talk_tags,
                      abstract=talk_abstract)

            tk.put()
def add_talk_seminar(seminarid):
    sem = Seminar.query.get(seminarid)

    if sem is None:
        flash("No Such Seminar", "Error")
        return default()

    if request.method == 'POST': 
        if sem.Organizer_id == current_user.id or current_user.has_role('admin'): 
            talk = Talk()
            talk.topic = request.form.get("topic")
            talk.abstract = request.form.get("abstract")
            talk.date_of = datetime.strptime(request.form.get("date_of"), '%m/%d/%Y %I:%M %p')
            talk.seminar_id = seminarid
            talk.speaker = request.form.get("speaker")
            talk.speaker_info = request.form.get("speaker_info") 
            talk.location = request.form.get("location")
            base_app.db.session.add(talk)
            base_app.db.session.commit()
            flash("Talk added for seminar %s" % sem.title, "Success")
            return default()
        else:
            flash("Insufficient Permissions", "Error")
            return default()

    return render_template('add_talk.html', seminar=sem)
Exemple #5
0
 def test_add_talk_to_speaker(self):
     s = Speaker(name = 'Jimi Hendrix',
                 slug = 'jimi-hendrix',
                 url = 'http://jimi.hendrix.com')
     s.save()
     t = Talk(title = 'First Talk',
              start_time = '15:00')
     t.save()
     
     s.talk_set.add(t)
     self.assertQuerysetEqual(s.talk_set.all(), 
                             ['<Talk: First Talk>'])
     self.assertQuerysetEqual(t.speakers.all(), 
                             ['<Speaker: Jimi Hendrix>'])
Exemple #6
0
 def test_creating_talk_basic(self):
     """test to create a Talk instance"""
     talk = Talk()
     talk.topic = u"Bla"
     talk.when = datetime.datetime.now()
     talk.tags = [u"foo", u"bar"]
     talk.duration = 5.5
     talk.validate()
     talk.save()
     
     self.assertTrue(talk['_id'])
     self.assertEqual(talk.duration, 5.5)
Exemple #7
0
 def post(self):
     name = self.request.get("name")
     talk_key = self.request.get("talk_key")
     talk = Talk.get_by_id(long(talk_key))
     talk.name = str(name)
     talk.put()
     self.redirect("chatroom?talk_key=%s&name=%s" % (str(talk_key), str(name)))
Exemple #8
0
 def post(self):
     message = self.request.get("message_content")
     talk_key = self.request.get("talk_key")
     talk = Talk.get_by_id(long(talk_key))
     for user in talk.users:
         """ Send message to those users """
         client_id = str(user.user_id()) + str(talk_key)
         channel.send_message(client_id,message)
def view_talks():
	talks = Talk.all()
	talks.order('-votes')

	# Convenient statistics
	max_votes = max([abs(talk.votes) for talk in talks])

	return render_template('view.html', talks=talks, max_votes=max_votes)
Exemple #10
0
def delete_talk(netid, talk_id):
	if netid not in ('fxh32', 'cxw158', 'jas404', 'srj15'):
		return redirect(url_for('index'))

	talk = Talk.get_by_id(talk_id)
	talk.delete()

	return redirect(url_for('index'))
def delete_talk(netid, talk_id):
	if netid not in authorized_users:
		return redirect(url_for('index'))

	talk = Talk.get_by_id(talk_id)
	talk.delete()

	return redirect(url_for('index'))
Exemple #12
0
 def get(self):
     query = Talk.query()
     to_parse = list()
     for singular in query:
         f_q = {"talk_key": str(singular.key.id()), "name": singular.name}
         to_parse.append(f_q)
     template_string = {"query_results": to_parse}
     self.response.write(self.render_template("home.html", "home", template_string))
Exemple #13
0
    def get(self):
        # gets the user from the google users datastore.
        user = users.get_current_user()
        talk_key = self.request.get("talk_key")

        if not user:
            # if user is not logged in, log them in.
            self.redirect(users.create_login_url(self.request.uri))
            return
        if not talk_key:
            talk = Talk()
            talk.host = user
            talk.users.append(user)
            talk.put()
            self.talk = talk
            talk_key = talk.key.id()
            self.redirect(str(self.request.url + "?talk_key=%i" % talk_key ))
        else:
            talk = Talk.get_by_id(long(self.request.get("talk_key")))
            if talk == None:
                self.redirect("/home")
        if user not in talk.users:
            talk.users.append(user)
            talk.put()

        key_name = self.request.get("talk_key")
        channel_id = str(user.user_id() + str(talk_key))
        channel_token = channel.create_channel(channel_id)
        template_things = {"id": key_name, "talk": talk, "user": user, "token": channel_token}
        self.response.write(self.render_template("index.html", "html", template_things))
Exemple #14
0
def session(session_key):
    user = users.get_current_user()
    session_ = ndb.Key(urlsafe=session_key).get()
    return render_template('session.html',
                           session=session_,
                           talks=Talk.in_session(session_key),
                           user=user,
                           logout=users.create_logout_url('/')
    )
Exemple #15
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 #16
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()
def vote(netid, talk_id, direction):
	app.logger.info(dir(netid))
	app.logger.info(netid)
	votes = Vote.all()
	votes.filter('talk_id =', talk_id)
	votes.filter('netid =', netid)
	
	votes_res = votes.fetch(1)

	netid = str(netid)

	if len(votes.fetch(1)) < 1 or (votes_res[0].direction != 'up' and votes_res[0].direction != 'down'):
		# User has not voted before
		new_vote = Vote(direction=direction, netid=str(netid), talk_id=talk_id)
		talk = Talk.get_by_id(talk_id)
		
		if direction == 'up':
			talk.votes += 1
		elif direction == 'down':
			talk.votes -= 1

		talk.put()
		new_vote.put()
		app.logger.info("Did a vote")
		return redirect(url_for('index'))
	elif votes_res[0].direction != direction:
		# The user has voted and is changing
		vote = votes_res[0]
		vote.direction = direction
		talk = Talk.get_by_id(talk_id)
		if direction == 'up':
			talk.votes += 2
		elif direction == 'down':
			talk.votes -= 2
		talk.put()
		vote.put()
		app.logger.info("Did a exist vote")
		return redirect(url_for('index'))
	else:
		# User is not allowed to vote
		return redirect(url_for('index'))
Exemple #18
0
    def post(self):
        user = users.get_current_user()

        sent_message = self.request.get("message_content")
        talk = Talk.get_by_id(long(self.request.get("talk_key")))
        message_package = {"author": str(user), "message": sent_message}
        talk.messages.append(message_package)
        talk.put()

        key_name = long(self.request.get("talk_key"))
        template_things = {"id": key_name, "talk": talk}
        self.response.write(self.render_template("index.html", "html", template_things))
Exemple #19
0
    def clean(self):
        cleaned_data = self.cleaned_data
        capture = cleaned_data.get('capture')
        license = cleaned_data.get('license')
        charges = cleaned_data.get('charges')
        city = cleaned_data.get('city')
        country = cleaned_data.get('country')
        speakers = cleaned_data.get('speakers')

        if capture == '1' and license == None:
            self._errors['license'] = self.error_class(
                [_(u"This field is required.")])
            del cleaned_data['license']

        if charges != '0':
            if city == '':
                self._errors['city'] = self.error_class(
                    [_(u"This field is required.")])
                del cleaned_data['city']
            if country == None:
                self._errors['country'] = self.error_class(
                    [_(u"This field is required.")])
                del cleaned_data['country']

        if speakers != None:
            if speakers.strip() == '':
                self._errors['speakers'] = self.error_class(
                    [_(u"This field is required.")])
            else:
                speaker_re = Talk.speaker_re()

                speakers = speakers.strip()
                errors = []
                success = []
                for s in speakers.split("\n"):
                    s = s.strip()
                    if speaker_re.match(s) == None:
                        errors.append(s)
                    else:
                        success.append(s)

                if errors != []:
                    errors.reverse()
                    errors.append(
                        _(u"The following lines don't match the correct format:"
                          ))
                    errors.reverse()
                    self._errors['speakers'] = self.error_class(errors)
                    del cleaned_data['speakers']

        return cleaned_data
def create_talk():
	name = request.form['name']
	speaker = request.form['speaker']
	talk = Talk(votes=0, name=name, speaker=speaker)
	talk.name = name
	talk.speaker = speaker
	talk.votes = 0
	talk.put()
	return redirect(url_for('create_talk_form'))
Exemple #21
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 #22
0
    def clean(self):
        cleaned_data = self.cleaned_data
        capture = cleaned_data.get('capture')
        license = cleaned_data.get('license')
        charges = cleaned_data.get('charges')
        city = cleaned_data.get('city')
        country = cleaned_data.get('country')
        speakers = cleaned_data.get('speakers')

        if capture == '1' and license == None:
            self._errors['license'] = self.error_class([_(u"This field is required.")])
            del cleaned_data['license']

        if charges != '0':
            if city == '':
                self._errors['city'] = self.error_class([_(u"This field is required.")])
                del cleaned_data['city']
            if country == None:
                self._errors['country'] = self.error_class([_(u"This field is required.")])
                del cleaned_data['country']

        if speakers != None:
            if speakers.strip() == '':
                self._errors['speakers'] = self.error_class([_(u"This field is required.")])
            else:
                speaker_re = Talk.speaker_re()

                speakers = speakers.strip()
                errors = []
                success = []
                for s in speakers.split("\n"):
                    s = s.strip()
                    if speaker_re.match(s) == None:
                        errors.append(s)
                    else:
                        success.append(s)

                if errors != []:
                    errors.reverse()
                    errors.append(_(u"The following lines don't match the correct format:"))
                    errors.reverse()
                    self._errors['speakers'] = self.error_class(errors)
                    del cleaned_data['speakers']

        return cleaned_data
Exemple #23
0
def import_talks(talks):
    for talk in talks:
        # See if the RoomDay exists
        room_day = db.session.query(RoomDay)\
                        .filter(RoomDay.room == talk['room'])\
                        .filter(RoomDay.day == talk['day'])\
                        .first()
        if not room_day:
            room_day = RoomDay(
                room=talk['room'],
                day=talk['day'],
                date=talk['start'].date(),
                vid='',
            )
            db.session.add(room_day)
            db.session.flush()

        # Create talk data
        talk_data = Talk(
            room_day_id=room_day.id,
            path=talk['path'],
            speakers=talk['speakers'],
            sched_start=talk['start'].strftime("%H:%M"),
            sched_end=talk['end'].strftime("%H:%M"),
            title=talk['title'],
            description=talk['description'],
        )

        # See if the Talk already exists
        talk = db.session.query(Talk)\
                    .filter(Talk.path == talk['path'])\
                    .first()
        if not talk:
            db.session.add(talk_data)
        else:
            # If talk already exists, we may need to update some of its fields
            talk.room_day_id = talk_data.room_day_id
            talk.sched_start = talk_data.sched_start
            talk.sched_end = talk_data.sched_end
            talk.title = talk_data.title
            talk.description = talk_data.description
Exemple #24
0
 def get(self):
     self.render_template('talks', {'talks': Talk.all()})
Exemple #25
0
def public_session(session_key):
    session_ = ndb.Key(urlsafe=session_key).get()
    return render_template('public_session.html',
                           session=session_,
                           talks=Talk.in_session(session_key)
                           )
Exemple #26
0
 def test_create_talk(self):
     t = Talk(title = 'First Talk',
              start_time = '15:00')
     t.save()
     self.assertQuerysetEqual(Talk.objects.all(), 
                             ['<Talk: First Talk>'])
Exemple #27
0
 def get(self):
     self.render_template('talks', {
         'talks' : Talk.all()
     })
def index(netid):
	talks = Talk.all()
	all_votes = Vote.all()
	votes = all_votes.filter('netid =', netid)
	return render_template('index.html', talks=talks, votes=votes, ticket=request.args['ticket'], netid=netid)
Exemple #29
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)
Exemple #31
0
 def get(self):
     self.talk_key = self.request.get("talk_key")
     template_values = {"talk": Talk.get_by_id(long(self.talk_key)), "user": users.get_current_user(), "id": self.talk_key}
     self.response.write(self.render_template("chatroomRename.html", "chatroomRename", template_values))