Esempio n. 1
0
 def post(self):
     calendar_link = ""
     if(settings.APP['gcalenabled']):
         ck = db.Key(self.request.get('clientkey'))
         ck_query = Clients.all()
         ck_query.filter('__key__ =', ck)
         client = ck_query.fetch(1)
         clientname = client[0].business
         try:
             cal_title = self.request.get('pname') + " - " + clientname
             projectdesc = 'Client: ' + clientname + ' '
             projectdesc += 'Project: ' + self.request.get('pname')
             gconnect = Gconnection()
             gd_client = gconnect.calendar_connect()
             calendar = gdata.calendar.CalendarListEntry()
             calendar.title = atom.Title(text=cal_title)
             calendar.summary = atom.Summary(text=projectdesc)
             calendar.where = gdata.calendar.Where(value_string=settings.COMPANY["city"])
             calendar.color = gdata.calendar.Color(value='#2952A3')
             calendar.timezone = gdata.calendar.Timezone(value='America/Los_Angeles')
             calendar.hidden = gdata.calendar.Hidden(value='false')
             new_calendar = gd_client.InsertCalendar(new_calendar=calendar)
             calendar_link = new_calendar.link[0].href
         except:
             # TODO figure out proper action to take
             calendar_link = "Something went wrong."
     projects = Projects()
     projects.client = db.Key(self.request.get('clientkey'))
     projects.pname = self.request.get('pname')
     projects.calendarid = calendar_link
     projects.status = 'empty'
     projects.summary = 0
     projects.put()
     action = '/projects?clientkey=' + self.request.get('clientkey') + ''
     self.redirect(action)
Esempio n. 2
0
 def post(self):
     calendar_link = ""
     if (settings.APP['gcalenabled']):
         ck = db.Key(self.request.get('clientkey'))
         ck_query = Clients.all()
         ck_query.filter('__key__ =', ck)
         client = ck_query.fetch(1)
         clientname = client[0].business
         try:
             cal_title = self.request.get('pname') + " - " + clientname
             projectdesc = 'Client: ' + clientname + ' '
             projectdesc += 'Project: ' + self.request.get('pname')
             gconnect = Gconnection()
             gd_client = gconnect.calendar_connect()
             calendar = gdata.calendar.CalendarListEntry()
             calendar.title = atom.Title(text=cal_title)
             calendar.summary = atom.Summary(text=projectdesc)
             calendar.where = gdata.calendar.Where(
                 value_string=settings.COMPANY["city"])
             calendar.color = gdata.calendar.Color(value='#2952A3')
             calendar.timezone = gdata.calendar.Timezone(
                 value='America/Los_Angeles')
             calendar.hidden = gdata.calendar.Hidden(value='false')
             new_calendar = gd_client.InsertCalendar(new_calendar=calendar)
             calendar_link = new_calendar.link[0].href
         except:
             # TODO figure out proper action to take
             calendar_link = "Something went wrong."
     projects = Projects()
     projects.client = db.Key(self.request.get('clientkey'))
     projects.pname = self.request.get('pname')
     projects.calendarid = calendar_link
     projects.status = 'empty'
     projects.summary = 0
     projects.put()
     action = '/projects?clientkey=' + self.request.get('clientkey') + ''
     self.redirect(action)
Esempio n. 3
0
    def post(self):
        # Philosophically, posting new time assumes that you are logging 
        # your time as you finish the task at hand. You can override this
        # behavior by providing a date/time, but that timestamp is 
        # still assumed to be the end point of the task, and the amount
        # of time entered is subtracted from it.
        #
        # I'm not sure why I have to import this here, but it throws errors
        # if I do it at the top;
        # TODO get someone to explain why.
        from datetime import datetime, timedelta

        # Calculate dates and times.
        # The submitting form has service, project, date, note, and 
        # multiplier (hours) fields. It is assumed that you log your time 
        # when you *finish* a task and subtract the amount of time (multiplier) 
        # that you just spent on  it. You can, of course override "now" and 
        # provide the end time manually, but the base assumption is that you 
        # take the given time and *subtract* the multiplier (hours).
        hours = float(self.request.get('hours'))

        # First, we check to see if we're overriding our "now" assumption
        # if we are, we have to append :00 onto the time (as the datetime html5
        # input doesn't seem to support the full this) to conform to 
        # the gdata API; otherwise, we take GMT and format it accoringly so
        # that we can do the math
        if self.request.get('date'):
        #    end_time = self.request.get('date') + ":00"
            end_time = self.request.get('date')
        else:
            end_time = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime())
        the_end = datetime.strptime(end_time,'%Y-%m-%dT%H:%M:%S')

        # Adjust for timezone.
        # TODO refactor to support Eastern timezones as this breaks if you
        # use a positive GMT offset.
        ender = the_end - timedelta(hours=settings.CAL["GMToffset"])

        # subtract the hours spent
        the_start = ender - timedelta(hours=hours)

        #format things for calendar API (add the T)
        event_end = str(ender).replace(" ", "T")
        event_start = str(the_start).replace(" ", "T")

        # Get project details from projects model
        projectid = db.Key(self.request.get('pid'))
        project_query = Projects.all()
        project_query.filter('__key__ =', projectid)
        projects = project_query.fetch(1)

        # Get the calendar ID so that we can post
        # to it and add this event to the appropriate calendar
        calendar_uri = projects[0].calendarid

        # Update the project status to reflect that it now has billable time.
        # If we don't do this, we won't be able to select the project in the UI
        # as we test for project status; if it's "empty" the checkbox is
        # disabled.
        projects[0].status = 'normal'
        projects[0].put()

        # put together time details to go into time model
        rateservice = str(self.request.get('service')).split(" || ")
        linetotal = int(rateservice[1]) * float(self.request.get('hours'))
        linetotal = "%.2f" % linetotal
        entry = Time()
        entry.client = db.Key(self.request.get('clientkey'))
        entry.project = projectid
        entry.date = the_end
        entry.hours = float(self.request.get('hours'))
        entry.service = rateservice[0]
        entry.rate = int(rateservice[1])
        entry.rateunit = rateservice[2]
        entry.total = str(linetotal)
        entry.worker = self.request.get('worker')
        entry.note = self.request.get('note')
        entry.status = 'logged'
        entry.put()

        # if gcalendar is enabled, use the gdata API to add event to 
        # this project's calendar
        if(settings.APP["gcalenabled"]):
            gconnect = Gconnection()
            gd_client = gconnect.calendar_connect()
            location = settings.APP["title"]
            title = rateservice[0]
            desc = self.request.get('note')
            desc += "\nWorker: " + self.request.get('worker')
            desc += "\nHours: " + self.request.get('hours')
            event_entry = gdata.calendar.CalendarEventEntry()
            event_entry.title = atom.Title(text=title)
            event_entry.content = atom.Content(text=desc)
            event_entry.timezone = gdata.calendar.Timezone(value='America/Los_Angeles')
            event_entry.when.append(gdata.calendar.When(start_time=event_start, end_time=event_end))
            event_entry.where.append(gdata.calendar.Where(value_string=location))
            try:
                cal_event = gd_client.InsertEvent(event_entry,calendar_uri)
            except gdata.service.RequestError, request_exception:
                request_error = request_exception[0]
                if request_error['status'] == 401 or request_error['status'] == 403:
                    self.response.out.write("401 or 403")
                else:
                    raise
Esempio n. 4
0
    def post(self):
        # Philosophically, posting new time assumes that you are logging
        # your time as you finish the task at hand. You can override this
        # behavior by providing a date/time, but that timestamp is
        # still assumed to be the end point of the task, and the amount
        # of time entered is subtracted from it.
        #
        # I'm not sure why I have to import this here, but it throws errors
        # if I do it at the top;
        # TODO get someone to explain why.
        from datetime import datetime, timedelta

        # Calculate dates and times.
        # The submitting form has service, project, date, note, and
        # multiplier (hours) fields. It is assumed that you log your time
        # when you *finish* a task and subtract the amount of time (multiplier)
        # that you just spent on  it. You can, of course override "now" and
        # provide the end time manually, but the base assumption is that you
        # take the given time and *subtract* the multiplier (hours).
        hours = float(self.request.get('hours'))

        # First, we check to see if we're overriding our "now" assumption
        # if we are, we have to append :00 onto the time (as the datetime html5
        # input doesn't seem to support the full this) to conform to
        # the gdata API; otherwise, we take GMT and format it accoringly so
        # that we can do the math
        if self.request.get('date'):
            #    end_time = self.request.get('date') + ":00"
            end_time = self.request.get('date')
        else:
            end_time = time.strftime('%Y-%m-%dT%H:%M:%S', time.gmtime())
        the_end = datetime.strptime(end_time, '%Y-%m-%dT%H:%M:%S')

        # Adjust for timezone.
        # TODO refactor to support Eastern timezones as this breaks if you
        # use a positive GMT offset.
        ender = the_end - timedelta(hours=settings.CAL["GMToffset"])

        # subtract the hours spent
        the_start = ender - timedelta(hours=hours)

        #format things for calendar API (add the T)
        event_end = str(ender).replace(" ", "T")
        event_start = str(the_start).replace(" ", "T")

        # Get project details from projects model
        projectid = db.Key(self.request.get('pid'))
        project_query = Projects.all()
        project_query.filter('__key__ =', projectid)
        projects = project_query.fetch(1)

        # Get the calendar ID so that we can post
        # to it and add this event to the appropriate calendar
        calendar_uri = projects[0].calendarid

        # Update the project status to reflect that it now has billable time.
        # If we don't do this, we won't be able to select the project in the UI
        # as we test for project status; if it's "empty" the checkbox is
        # disabled.
        projects[0].status = 'normal'
        projects[0].put()

        # put together time details to go into time model
        rateservice = str(self.request.get('service')).split(" || ")
        linetotal = int(rateservice[1]) * float(self.request.get('hours'))
        linetotal = "%.2f" % linetotal
        entry = Time()
        entry.client = db.Key(self.request.get('clientkey'))
        entry.project = projectid
        entry.date = the_end
        entry.hours = float(self.request.get('hours'))
        entry.service = rateservice[0]
        entry.rate = int(rateservice[1])
        entry.rateunit = rateservice[2]
        entry.total = str(linetotal)
        entry.worker = self.request.get('worker')
        entry.note = self.request.get('note')
        entry.status = 'logged'
        entry.put()

        # if gcalendar is enabled, use the gdata API to add event to
        # this project's calendar
        if (settings.APP["gcalenabled"]):
            gconnect = Gconnection()
            gd_client = gconnect.calendar_connect()
            location = settings.APP["title"]
            title = rateservice[0]
            desc = self.request.get('note')
            desc += "\nWorker: " + self.request.get('worker')
            desc += "\nHours: " + self.request.get('hours')
            event_entry = gdata.calendar.CalendarEventEntry()
            event_entry.title = atom.Title(text=title)
            event_entry.content = atom.Content(text=desc)
            event_entry.timezone = gdata.calendar.Timezone(
                value='America/Los_Angeles')
            event_entry.when.append(
                gdata.calendar.When(start_time=event_start,
                                    end_time=event_end))
            event_entry.where.append(
                gdata.calendar.Where(value_string=location))
            try:
                cal_event = gd_client.InsertEvent(event_entry, calendar_uri)
            except gdata.service.RequestError, request_exception:
                request_error = request_exception[0]
                if request_error['status'] == 401 or request_error[
                        'status'] == 403:
                    self.response.out.write("401 or 403")
                else:
                    raise