Example #1
0
def add_seminar():
    
    if request.method == 'POST':
        # This assumes client-side validation
        sem = Seminar()
        sem.Organizer_id = current_user.id 
        sem.title = request.form.get("title")
        if request.form.get("private") == 'on':
            sem.private = True
        else:
            sem.private = False

        sem.description =request.form.get("description") 
        sem.website = request.form.get("website")
        sem.contact_name = request.form.get("contact_name")
        sem.contact_email = request.form.get("contact_email")
        base_app.db.session.add(sem)
        base_app.db.session.commit()
        flash("Added seminar: %s" % sem.title, "Success")
        return default()
    
    return render_template('add_seminar.html')
Example #2
0
    def unknown_endtag(self, tag):
        if self._in_entry and self._state == STATE_SPEAKER and tag == "td":
            self._in_entry = None
            if (
                "url" not in self._smnr
                or "date" not in self._smnr
                or "time" not in self._smnr
                or "title" not in self._smnr
                or "speaker" not in self._smnr
            ):
                # might not be in the correct <tr>
                return

            # check if already exist
            url = self._smnr["url"]
            exist = memcache.get(url)
            if exist:
                return
            q = Seminar.gql("WHERE url = :url", url=url)
            if q.count() > 0:
                memcache.add(url, True)
                return

            # start and end time
            date = self._smnr["date"]
            time = self._smnr["time"]

            m = SPLIT_TIME.search(time)
            if not m:
                # might not be in the correct <tr>
                return

            start = m.group(1)
            end = m.group(2)
            try:
                # convert time
                # sample: July 16, 2010 10.00am
                start = " ".join([date, start])
                start = datetime.strptime(start, "%B %d, %Y %I.%M%p")
                start = start.replace(tzinfo=SGT)
                end = " ".join([date, end])
                end = datetime.strptime(end, "%B %d, %Y %I.%M%p")
                end = end.replace(tzinfo=SGT)
            except Exception, e:
                # might not be in the correct <tr>
                logging.error("%s @ %s" % (e, url))
                return

            # title
            title = "".join(self._smnr["title"])
            if len(title) > 0:
                e = chardet.detect(title)["encoding"]
                title = unicode(title, e)
            title = utils.unescape(title)

            # speaker
            sp = self._smnr["speaker"]
            while len(sp) > 0 and sp[0] == "\n":
                sp.pop(0)
            speaker = "".join(sp)
            if len(speaker) > 0:
                e = chardet.detect(speaker)["encoding"]
                speaker = unicode(speaker, e)
            speaker = utils.unescape(speaker)

            # create model
            s = Seminar(start=start, end=end, title=title, speaker=speaker, url=url)
            deferred.defer(s.fetch_and_put)
Example #3
0
    def get(self, year="current"):
        """year can be 'all', 'current', '2002', '2011', etc."""

        self.response.headers["Content-Type"] = "text/calendar; charset=utf-8"

        # find from cache
        q = Cache.gql("WHERE site = :site AND year = :year", site="nuscs", year=year)
        c = q.get()
        if c:
            self.response.out.write(c.data)
            return

        # generate now
        cal = Calendar()
        cal.add("prodid", "-//NUS CS Seminars//ronhuang.org//")
        cal.add("version", "2.0")
        cal.add("X-WR-CALNAME", "NUS CS Seminars")
        cal.add("X-WR-CALDESC", "Seminars are open to the public, and usually held in the School's Seminar Room.")

        q = Seminar.all().order("start")
        if year != "all":
            yn = None
            try:
                yn = int(year)
            except:
                pass

            if yn:
                # return events within that year
                q = q.filter("start >=", datetime(yn, 1, 1, tzinfo=SGT))
                q = q.filter("start <", datetime(yn + 1, 1, 1, tzinfo=SGT))
            else:  # default
                # return a year of events.
                q = q.filter("start >=", datetime.now(SGT) - timedelta(days=366))

        for s in q:
            event = Event()
            event["uid"] = s.url
            event.add("summary", s.title)
            event.add("dtstart", s.start)
            event.add("dtend", s.end)
            event.add("dtstamp", s.stamp)
            event.add("location", s.venue)
            event.add("url", s.url)
            event.add("description", s.speaker)
            event.add("categories", "seminar")
            event.add("class", "PUBLIC")

            cal.add_component(event)

        # generated data
        data = cal.as_string()
        encoding = chardet.detect(data)["encoding"]
        data = unicode(data, encoding)

        # store in datastore
        q = Cache.gql("WHERE site = :site AND year = :year", site="nuscs", year=year)
        c = q.get()
        if c:
            c.data = data
        else:
            c = Cache(site="nuscs", data=data, year=year)
        c.put()

        self.response.out.write(data)