def range(self, days=0, hours=0): date = request.params.get('date') date = parse_date(date) hour = request.params.get('hour', '0') hour = int(hour) dtend = datetime.datetime.combine(date, datetime.time(hour)) dt = datetime.timedelta(days=days, hours=hours) return (dtend - dt, dtend)
def _send_group_space_reminders(self): date = parse_date(request.params.get('date')) max_expiry_date = date + datetime.timedelta(days=3) for group in meta.Session.query(Group).all(): # Group space purchase period is about to end? if (group.private_files_lock_date and group.private_files_lock_date.date() <= max_expiry_date and not group.ending_period_notification_sent): self._send_ending_period_reminder(group) meta.Session.commit() # Group space has run out? if group.free_size == 0 and not group.out_of_space_notification_sent: self._send_out_of_space_notification(group) meta.Session.commit()
def static_file(resp, req, filename, root, guessmime=True, mimetype=None, download=False): """ Opens a file in a safe way and returns a HTTPError object with status code 200, 305, 401 or 404. Sets Content-Type, Content-Length and Last-Modified header. Obeys If-Modified-Since header and HEAD requests. """ root = os.path.abspath(root) + os.sep filename = os.path.abspath(os.path.join(root, filename.strip('/\\'))) if not filename.startswith(root): #return HTTPError(403, "Access denied.") return ForbiddenFault("Access denied.") if not os.path.exists(filename) or not os.path.isfile(filename): #return HTTPError(404, "File does not exist.") return fault.ItemNotFoundFault("File does not exist.") if not os.access(filename, os.R_OK): #return HTTPError(403, "You do not have permission to access this file.") return ForbiddenFault("You do not have permission to access this file.") if not mimetype and guessmime: resp.content_type = mimetypes.guess_type(filename)[0] else: resp.content_type = mimetype or 'text/plain' if download == True: download = os.path.basename(filename) if download: resp.content_disposition = 'attachment; filename="%s"' % download stats = os.stat(filename) lm = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(stats.st_mtime)) resp.last_modified = lm ims = req.environ.get('HTTP_IF_MODIFIED_SINCE') if ims: ims = ims.split(";")[0].strip() # IE sends "<date>; length=146" ims = parse_date(ims) if ims is not None and ims >= int(stats.st_mtime): resp.date = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()) return Response(body=None, status=304, headerlist=resp.headerlist) resp.content_length = stats.st_size if req.method == 'HEAD': return Response(body=None, status=200, headerlist=resp.headerlist) else: return Response(body=open(filename).read(), status=200, headerlist=resp.headerlist)