Ejemplo n.º 1
0
 def get(self):
     calendar = ManUpCalendar()
     feed = calendar.get_feed()
     for entry in feed.entry:
         for a_when in entry.when:
             date_string = a_when.start_raw[:19]
             date = datetime.datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S')
             for where in entry.where:
                 meeting = Meeting(name=entry.title.text, start_date=date, location=where.value)
                 meeting.put()
Ejemplo n.º 2
0
    def save_model(self, request, obj, form, change):
        if change:
            meeting = obj
        else:
            meeting = Meeting(
                date=form.cleaned_data['date'],
                start_time=form.cleaned_data['start_time'],
                end_time=form.cleaned_data['end_time'],
                country=form.cleaned_data['country'],
                short_name=form.cleaned_data['short_name'],
                description=form.cleaned_data['description']
            )

        meeting.save()
        self.meeting = meeting
Ejemplo n.º 3
0
def export_calendar_for_user(cal_user_id=None, filename="export"):
    """
    Create and export iCalendar file with the meetings of the chosen user

    :param cal_user_id: User ID to create calendar for
    :param filename: Filename for the ics file
    :return: ics file wrapped in a response
    """
    if cal_user_id is None:
        # Defaults to current user
        cal_user_id = current_user.id

    meeting_list = Meeting.get_user_meetings(cal_user_id)
    tz = timezone(app.config['TIMEZONE'])
    cal = Calendar()
    for meeting in meeting_list:
        event = Event()
        event.add('summary', meeting.title)
        event.add('dtstart', tz.localize(meeting.start_time))
        event.add('dtend', tz.localize(meeting.end_time))
        event.add('description',
                  u'Møte generert av %s. Antall deltakere: %s. ' % (app.config['APP_NAME'],
                                                                    meeting.participant_count))
        cal.add_component(event)

    export = StringIO.StringIO()
    export.writelines(cal.to_ical())
    export.seek(0)
    return send_file(export,
                     attachment_filename=filename + '.ics',
                     as_attachment=True)
Ejemplo n.º 4
0
def extract_results(html, year, season):
    soup = BeautifulSoup(html, 'html.parser').find_all(id='searchResultsPanel')[0]
    soup = soup.find_all('div', recursive=False)[1].find_all('table', limit=1)[0]
    semester = Semester(year, season)
    for row in soup.find_all('tr', recursive=False):
        tds = row.find_all('td', recursive=False)
        if not tds:
            continue
        department, number, section = extract_text(tds[1]).split()
        course = Course(Department.get(department), number)
        title = extract_text(tds[2])
        units = int(extract_text(tds[3]))
        instructors = []
        for tag in tds[4].find_all('abbr'):
            instructor_str = tag['title']
            if instructor_str == 'Instructor Unassigned':
                instructors.append(None)
            else:
                instructors.append(Faculty(instructor_str, *Faculty.split_name(instructor_str)))
        meetings = []
        for tr in tds[5].find_all('tr'):
            meetings.append(Meeting.from_str(*(extract_text(tag) for tag in tr.find_all('td'))))
        cores = list(set(Core.get(extract_text(tag)) for tag in tds[6].find_all('abbr')))
        if not cores:
            cores = []
        seats = int(extract_text(tds[7]))
        enrolled = int(extract_text(tds[8]))
        reserved = int(extract_text(tds[9]))
        reserved_open = int(extract_text(tds[10]))
        waitlisted = int(extract_text(tds[11]))
        Offering(semester, course, section, title, units, tuple(instructors), tuple(meetings), tuple(cores), seats, enrolled, reserved, reserved_open, waitlisted)
Ejemplo n.º 5
0
def edit_meeting(meeting_id):
    """ Renders the edit meeting page and stores the edited meeting """
    # Get the meeting details based on the supplied ID
    meeting = Meeting.get_meeting_by_id(meeting_id)
    # Check if the current user can edit this meeting
    if meeting.user_id != current_user.id:
        flash(u'Du har ikke tilgang til å endre dette møtet!')
        return redirect(url_for('home'))

    if request.method == 'POST':
        form = forms.MeetingForm(request.form)
        # If valid, store the edited meeting details
        if form.validate():
            form.populate_obj(meeting)
            meeting.store()
            flash(u'Møtet ble endret!')
            return redirect(url_for('home'))
        else:
            flash(u'Feil i skjema!')

    else:  # GET
        # Feed meeting details to meeting form
        form = forms.MeetingForm(obj=meeting)

    return render_template(
        'edit_meeting.html',
        set_tab=1,
        form=form,
        action=url_for('edit_meeting', meeting_id=meeting_id)
    )
Ejemplo n.º 6
0
def delete_meeting(meeting_id):
    """ Endpoint to asynchronously delete meeting """
    if not meeting_id:
        return jsonify(
            success=False,
            message=u'Ingen møte ID mottatt'
        )

    meeting = Meeting.get_meeting_by_id(meeting_id)
    # Check if user is owner
    if meeting.user_id == current_user.id:
        # Delete meeting from db before deleting world
        meeting.delete()

        # Object still exists in memory after deleting from db
        if meeting.world_id:
            # Also delete world if it's not favoured
            world = World.get_by_id(meeting.world_id)
            if meeting.user_id == world.user_id and not world.favourite:
                if world.delete():  # Will return false if in use by meeting
                    return jsonify(
                        success=True,
                        message=u'Møtet ble slettet',
                        world_id=world.id
                    )
        return jsonify(
            success=True,
            message=u'Møtet ble slettet'
        )
    return jsonify(
        success=False,
        message=u'Du har ikke tilgang til å slette dette møtet'
    )
Ejemplo n.º 7
0
    def startCommand(self, meetingDB, meetingInProgress, usernames, shuffle, channel_id):
        if meetingInProgress:
            self.sendSlackMessage("Meeting already in progress")
            return HttpResponse()

        if shuffle:
            random.shuffle(usernames)

        meetingDB = Meeting(channel=channel_id,
                            meetingOrder=json.dumps(usernames),
                            questionNum=1,
                            currentMember=usernames[0])
        meetingDB.save()

        self.sendSlackMessage("Let's get this meeting started! The order today will be: " + ", ".join(usernames))
        self.sendSlackMessage(usernames[0] + ": What did you do since your last standup?")
        return HttpResponse()
Ejemplo n.º 8
0
 def list_meetings(self, request):
     authorise(request.person, request.token)
     meetings = Meeting.get_meetings(request.person, request.token)
     # meetings = Meeting.query().fetch()
     res = MeetingsCollection()
     for meeting in meetings:
         res.items.append(meeting2Msg(meeting))
     return res
Ejemplo n.º 9
0
def server_list(meeting_id):
    """ Render server list page for specified meeting """
    # TODO handle get servers
    # TODO check if user has access
    meeting = Meeting.get_meeting_by_id(meeting_id)
    return render_template(
            'server_list.html',
            title=u'Liste over tjenere',
            meeting=meeting,
            locale=locale.getpreferredencoding(),
            servers=[{'address': 'test.com', 'status': 'OK'}]
        )
Ejemplo n.º 10
0
    def update(self, request):
        authorise(request.person, request.token)
        mm = Meeting.get_by_id(request.id)
        if not mm:
            message = 'No meeting with the id "%s" exists.' % request.id
            raise endpoints.NotFoundException(message)

        mm.title = request.title
        mm.startTime = request.startTime
        mm.put()
        res = MeetingMsg(id=mm.put().id(), title=mm.title, startTime=mm.startTime)
        return res
Ejemplo n.º 11
0
 def test_meeting_create_fiber_page_method(self):
     """
     Tests the fiber page constructor method. The fiber page method get_absolute_url does
     not work as expected. Not sure why....
     """
     # Create a meeting
     calgary_2014 = Meeting(year=2014, title='Calgary 2014', location='Calgary', associated_with='AAPA')
     calgary_2014.save()
     # Create a default page tree
     create_django_page_tree()
     # Call page constructor method
     calgary_2014.create_fiber_page()
     # Fetch the fiber page we just created
     calgary_2014_fiber_page = Page.objects.get(url__exact='2014')
     # Test the attributes of the fiber page
     self.assertEqual(calgary_2014_fiber_page.parent, Page.objects.get(url__exact='meetings'))
     self.assertEqual(calgary_2014_fiber_page.url, '2014')
     self.assertEqual(calgary_2014_fiber_page.title, 'Calgary 2014')
     #self.assertEqual(calgary_2014_fiber_page.get_absolute_url, '/meetings/2014/') TODO Whys does this test fail?
     # Test that the page renders
     response = self.client.get('/meetings/2014/')
     self.assertEqual(response.status_code, 200)
Ejemplo n.º 12
0
 def test_meeting_has_detail_method(self):
     """
     Tests the has_detail method
     """
     # Create a meeting
     calgary_2014 = Meeting(year=2014, title='Calgary 2014', location='Calgary', associated_with='AAPA')
     calgary_2014.save()
     # Create a default page tree
     create_django_page_tree()
     # IF no fiber page then has_detail should be false
     self.assertEqual(calgary_2014.has_detail(), False)
     # Call page constructor method
     calgary_2014.create_fiber_page()
     # If fiber page then has_detail should be true
     self.assertEqual(calgary_2014.has_detail(), True)
     cfp = Page.objects.get(url__exact=2014)  # get tha page instance
     cfp.is_public = False  # set to not public
     cfp.save()  # save the change
     self.assertEqual(calgary_2014.has_detail(), False)  # Now has detail should return false
Ejemplo n.º 13
0
    def trackEvents(self):
        logging.info('Tracking Events')
        date = datetime.datetime.now()
        logging.info(date)
        immediate = Meeting.query(ndb.AND(Meeting.startTime >= date + datetime.timedelta(minutes=50)),
                                Meeting.startTime < date + datetime.timedelta(hours=1)).fetch()
        logging.info('Found {} meetings'.format(len(immediate)))
        for meeting in immediate:
            self.processMeeting(meeting)
#Sample POST Data -->  message={"request":{"data":{"custom": "json data"},"platforms": [1,2], "ios_message":"This is a test","ios_button_text":"yeah!","ios_badge": -1, "ios_sound": "soundfile", "android_collapse_key": "collapsekey"}}
        msg = {
            "request":
                {
                    "data":{"custom": "json data"},
                    "platforms": [1,2], 
                    "ios_message":"This is a test",
                    "ios_button_text":"yeah!",
                    "ios_badge": -1,
                    "ios_sound": "soundfile",
                    "android_collapse_key": "collapsekey"}
        }
        BroadcastMessageToTag(msg, meeting.key.id())
Ejemplo n.º 14
0
 def render_template(self, template_name, template_dict=None):
     next_meeting = Meeting.get_next_meeting()
     if next_meeting:
         tag_line = '%s: %s, %s' % (next_meeting.name, next_meeting.start_date, next_meeting.location)
     else:
         tag_line = 'Evening Hack: 14/4/2011 5pm LF15'
 
     if template_dict is None:
         template_dict = {}
     
     user = Hacker.get_current_hacker()
     
     if user:
         if self.login_required:
             redirect_target = '/'
         else:
             redirect_target = self.request.path
         url_creator = users.create_logout_url
     else:
         redirect_target = '/login?url=%s' % self.request.path
         url_creator = users.create_login_url
         
     defaults = {
         'user': user,
         'log_url': url_creator(redirect_target),
         'tag_line': tag_line,
         'title': self.title
     }
     
     for key in defaults:
         if key not in template_dict:
             template_dict[key] = defaults[key]
     
     template_path = get_path(
         os.path.join('templates', '%s.html' % template_name))
     self.response.out.write(
         template.render(template_path, template_dict))
Ejemplo n.º 15
0
    def delete(self, request):
        authorise(request.person, request.token)
        try:
            meeting = Meeting.get_by_id(request.id)
            if meeting.originator == request.person:
                persons = Person.query(Person.parentId==request.id).fetch()
                for person in persons:
                    roles = Role.query(Role.parentId==person.key.id()).fetch()
                    for role in roles:
                        role.key.delete()
                    person.key.delete()
                meeting.key.delete()
            else: # just remove the person from the meeting
                persons = Person.query(Person.parentId==request.id).fetch()
                for person in persons:
                    if(person.email == request.person):
                        roles = Role.query(Role.parentId==person.key.id()).fetch()
                        for role in roles:
                            role.key.delete()
                        person.key.delete()

            return message_types.VoidMessage()
        except (IndexError, TypeError):
            raise endpoints.NotFoundException('Role %s not found.' % (request.id,))
Ejemplo n.º 16
0
def create_three_meetings_with_pages():
    # Create home fiber tree
    create_django_page_tree()
    # Create meeting instances
    calgary = Meeting(year=2014, title='Calgary 2014', location='Calgary, AB', associated_with='AAPA')
    calgary.create_fiber_page()
    calgary.save()
    san_francisco = Meeting(year=2015, title='San Francisco 2015', location='San Francisco, CA', associated_with='SAA')
    san_francisco.create_fiber_page()
    san_francisco.save()
    atlanta = Meeting(year=2016, title='Atlanta 2016', location='Atlanta, GA', associated_with='AAPA')
    atlanta.create_fiber_page()
    atlanta.save()
Ejemplo n.º 17
0
def home():
    """ Renders the home page """
    # Meeting list will be shown at the bottom of the page
    meeting_list = Meeting.get_user_meetings(current_user.id)
    # Selected world (in meeting tab) defaults to None and gets overridden if there is a world selected
    world = None
    # Default to world selection tab
    # 0 is world selection tab and 1 is meeting details tab
    set_tab = 0
    # Locale encoding used for day names
    # preferred_encoding = locale.getpreferredencoding()
    preferred_encoding = 'UTF-8'

    # A form is posted
    if request.method == 'POST':
        # If request is a redirect from map page, we will have a WorldForm
        world_form = forms.WorldForm(request.form)
        if world_form.validate():
            # Go to meeting details tab
            set_tab = 1
            # Show empty meeting form
            meeting_form = forms.MeetingForm()
            try:
                world_id = int(world_form.world_id.data)
                description = world_form.description.data
                world = World.get_by_id(world_id)
                if world:
                    # Update description if changed
                    if world.description != description:
                        world.description = description
                        world.store()
                    # Put world ID in meeting form for reference
                    meeting_form.world_id.process_data(str(world_id))
                else:  # World does not exist
                    flash(u'Den valgte Minecraft verdenen eksisterer ikke')
                    set_tab = 0

            except ValueError:
                # A number was not supplied as world ID
                flash(u'world_id ValueError')

            return render_template(
                'index.html',
                set_tab=set_tab,
                title=u'Hjem',
                meetings=meeting_list,
                form=meeting_form,
                world=world,
                action=url_for('home'),
                locale=preferred_encoding
            )

        # Check if a meeting form is posted
        form = forms.MeetingForm(request.form)
        if form.validate():
            # If valid, put data from form into Meeting object
            meeting = Meeting(user_id=current_user.id)
            form.populate_obj(meeting)
            if meeting.world_id:  # World ID will be none if the posted value is not an integer
                if World.exists(meeting.world_id):  # Check that the world exists in the database
                    meeting.store()

                    # Celery stuff
                    # tasks.meeting_test.apply_async()
                    tasks.meeting_test.apply_async(eta=meeting.start_time, expires=meeting.end_time)

                    flash(u'Nytt møte lagt til')
                    return redirect(url_for('home'))

                else:  # World does not exist
                    flash(u'Den valgte Minecraft verdenen eksisterer ikke')
                    set_tab = 1

            else:  # World probably not chosen
                flash(u'Ingen Minecraft verden valgt')
                set_tab = 0

        else:  # Form not valid
            flash(u'Feil i skjema!')
            set_tab = 1
            try:  # Insert world info
                world_id = int(form.world_id.data)
                world = World.get_by_id(world_id)
            except ValueError:
                pass

    else:  # If not POST
        # Serve blank form
        form = forms.MeetingForm()

    return render_template(
        'index.html',
        set_tab=set_tab,
        title=u'Hjem',
        meetings=meeting_list,
        form=form,
        world=world,
        action=url_for('home'),
        locale=preferred_encoding
    )