Esempio n. 1
0
    def prevNextDateButtons(self):
        showingDate = self.params['date']
        if showingDate is None:
            if self.desc.currentPhoto() is None:
                return None

            try:
                showingDate = photoDate(self.graph, self.desc.currentPhoto())
            except ValueError:
                return None

        dtd = parse_date(showingDate)
        try:
            prev = dict(prevDate=date_isoformat(
                nextDateWithPics(self.graph, dtd, -datetime.timedelta(
                    days=1))))
        except ValueError:
            prev = None

        try:
            next = dict(nextDate=date_isoformat(
                nextDateWithPics(self.graph, dtd, datetime.timedelta(days=1))))
        except ValueError:
            next = None

        return dict(prev=prev, next=next)
Esempio n. 2
0
    def prevNextDateButtons(self):
        showingDate = self.params['date']
        if showingDate is None:
            if self.desc.currentPhoto() is None:
                return None

            try:
                showingDate = photoDate(self.graph, self.desc.currentPhoto())
            except ValueError:
                return None
        
        dtd = parse_date(showingDate)
        try:
            prev = dict(prevDate=date_isoformat(nextDateWithPics(
                self.graph, dtd, -datetime.timedelta(days=1))))
        except ValueError:
            prev = None

        try:
            next = dict(nextDate=date_isoformat(nextDateWithPics(
                self.graph, dtd, datetime.timedelta(days=1))))
        except ValueError:
            next = None
            
        return dict(prev=prev, next=next)
Esempio n. 3
0
 def render_newestDates(self, ctx, data, n=5):
     dates = []
     d = datetime.datetime.now() + datetime.timedelta(days=1)
     while len(dates) < n:
         d = nextDateWithPics(self.graph, d, -datetime.timedelta(days=1))
         dates.append(T.li[T.a(
             href=["set?date=", date_isoformat(d)])[date_isoformat(d)]])
     return T.ul[dates]
Esempio n. 4
0
 def render_newestDates(self, ctx, data, n=5):
     dates = []
     d = datetime.datetime.now() + datetime.timedelta(days=1)
     while len(dates) < n:
         d = nextDateWithPics(self.graph, d,
                              -datetime.timedelta(days=1))
         dates.append(T.li[T.a(href=["set?date=", date_isoformat(d)])[
             date_isoformat(d)]])
     return T.ul[dates]
Esempio n. 5
0
def dateHasPics(graph, date):
    """
    takes datetime
    """
    dlit = Literal(date_isoformat(date), datatype=XS.date)
    if dlit in _dateHasPics:
        return True
    # should be an ASK
    rows = graph.queryd("""
               SELECT ?img WHERE {
                 ?img a foaf:Image; dc:date ?d .
               } LIMIT 1""", initBindings={"d" : dlit})
    ret = bool(list(rows))
    if ret:
        _dateHasPics.add(dlit)
    return ret
Esempio n. 6
0
def dateHasPics(graph, date):
    """
    takes datetime
    """
    dlit = Literal(date_isoformat(date), datatype=XS.date)
    if dlit in _dateHasPics:
        return True
    # should be an ASK
    rows = graph.queryd("""
               SELECT ?img WHERE {
                 ?img a foaf:Image; dc:date ?d .
               } LIMIT 1""",
                        initBindings={"d": dlit})
    ret = bool(list(rows))
    if ret:
        _dateHasPics.add(dlit)
    return ret
Esempio n. 7
0
def interval_isoformat(arg1, arg2, repeat=None, fmt=None):
    output_r = output_1 = output_2 = None

    # check format
    fmt_segments = [None, None, None]
    if fmt:
        fmt_segments = fmt.split("/")
        if len(fmt_segments) == 3:
            r_fmt = fmt_segments[0]
            # only allow R or Rn
            if r_fmt == "R":
                output_r = "R"
            if r_fmt == "Rn":
                output_r = "R"
                if repeat:
                    if not isinstance(repeat, (int, long)) or repeat < 0:
                        raise TypeError(
                            "repeat must be an whole, non-negative number")
                    output_r += repeat

            # remove repeat format and proceed with other 2 arg formatting
            fmt_segments = fmt_segments[1:]
    else:
        if repeat:
            output_r = "R"
    if isinstance(arg1, datetime):
        str_1 = datetime_isoformat(arg1, fmt_segments[0])
        #assert (isinstance(arg2, datetime, time, date, timedelta))
        if isinstance(arg2, datetime):
            str_2 = datetime_isoformat(arg2, format=fmt_segments[1])
        elif isinstance(arg2, date):
            str_2 = date_isoformat(arg2, format=fmt_segments[1])
    elif isinstance(arg1, datetime.timedelta):
        str1 = duration_isoformat(arg1)
        #assert (isinstance(arg2, datetime))
    else:
        raise ISO8601Error(
            "arg1 must be a datetime, time, date, or timedelta object")