def check_attrs (self):
     self.txt = self.txt.decode('utf-8')
     for attr in ['title','cuisine',
                  'source','link']:
         if getattr(self.rec,attr):
             assert re.search('<%(attr)s>\s*%(val)s\s*</%(attr)s>'%{
                 'attr':attr,
                 'val':getattr(self.rec,attr)
                 },
                              self.txt), \
                              'Did not find %s value %s'%(attr,getattr(self.rec,attr))
     if self.rec.yields:
         assert re.search('<yields>\s*%s\s*%s\s*</yields>'%(
                 self.rec.yields,
                 self.rec.yield_unit),
                          self.txt) or \
                          re.search('<yields>\s*%s\s*%s\s*</yields>'%(
                                  float_to_frac(self.rec.yields),
                                  self.rec.yield_unit),
                                    self.txt), \
                                    'Did not find yields value %s %s'%(self.rec.yields,
                                                             self.rec.yield_unit)
     for att in ['preptime','cooktime']:
         if getattr(self.rec,att):
             tstr = seconds_to_timestring(getattr(self.rec,att))
             assert re.search('<%(att)s>\s*%(tstr)s\s*</%(att)s>'%locals(),self.txt),\
                    'Did not find %s value %s'%(att,tstr)
예제 #2
0
 def check_attrs(self):
     self.txt = self.txt.decode('utf-8')
     for attr in ['title', 'cuisine', 'source', 'link']:
         if getattr(self.rec, attr):
             assert re.search('<%(attr)s>\s*%(val)s\s*</%(attr)s>'%{
                 'attr':attr,
                 'val':getattr(self.rec,attr)
                 },
                              self.txt), \
                              'Did not find %s value %s'%(attr,getattr(self.rec,attr))
     if self.rec.yields:
         assert re.search('<yields>\s*%s\s*%s\s*</yields>'%(
                 self.rec.yields,
                 self.rec.yield_unit),
                          self.txt) or \
                          re.search('<yields>\s*%s\s*%s\s*</yields>'%(
                                  float_to_frac(self.rec.yields),
                                  self.rec.yield_unit),
                                    self.txt), \
                                    'Did not find yields value %s %s'%(self.rec.yields,
                                                             self.rec.yield_unit)
     for att in ['preptime', 'cooktime']:
         if getattr(self.rec, att):
             tstr = seconds_to_timestring(getattr(self.rec, att))
             assert re.search('<%(att)s>\s*%(tstr)s\s*</%(att)s>'%locals(),self.txt),\
                    'Did not find %s value %s'%(att,tstr)
예제 #3
0
 def _grab_attr_(self, obj, attr):
     if attr == "category":
         return ", ".join(self.rd.get_cats(obj))
     try:
         ret = getattr(obj, attr)
     except:
         return None
     else:
         if attr in ["preptime", "cooktime"]:
             # this 'if' ought to be unnecessary, but is kept around
             # for db converting purposes -- e.g. so we can properly
             # export an old DB
             if ret and type(ret) != str:
                 ret = convert.seconds_to_timestring(ret, fractions=self.fractions)
         elif attr == "rating" and ret and type(ret) != str:
             if ret / 2 == ret / 2.0:
                 ret = "%s/5 %s" % (ret / 2, _("stars"))
             else:
                 ret = "%s/5 %s" % (ret / 2.0, _("stars"))
         if type(ret) in types.StringTypes and attr not in ["thumb", "image"]:
             try:
                 ret = ret.encode(self.DEFAULT_ENCODING)
             except:
                 print "oops:", ret, "doesn't look like unicode."
                 raise
         return ret
예제 #4
0
파일: exporter.py 프로젝트: wummel/gourmet
    def _grab_attr_(self, obj, attr):
        # This is a bit ugly -- we allow exporting categories as if
        # they were a single attribute even though we in fact allow
        # multiple categories.
        if attr == 'category':
            return ', '.join(self.rd.get_cats(obj))
        try:
            ret = getattr(obj, attr)
        except:
            return None
        else:
            if attr in ['preptime', 'cooktime']:
                # this 'if' ought to be unnecessary, but is kept around
                # for db converting purposes -- e.g. so we can properly
                # export an old DB
                if ret and not isinstance(ret, str):
                    ret = convert.seconds_to_timestring(
                        ret, fractions=self.fractions)
            elif attr == 'rating' and ret and not isinstance(ret, str):
                if ret / 2 == ret / 2.0:
                    ret = "%s/5 %s" % (ret / 2, _('stars'))
                else:
                    ret = "%s/5 %s" % (ret / 2.0, _('stars'))
            elif attr == 'servings' and not isinstance(ret, str):
                ret = convert.float_to_frac(ret, fractions=self.fractions)
            elif attr == 'yields':
                ret = convert.float_to_frac(ret, fractions=self.fractions)
                yield_unit = self._grab_attr_(obj, 'yield_unit')
                if yield_unit:
                    ret = '%s %s' % (
                        ret, yield_unit
                    )  # FIXME: i18n? (fix also below in exporter_mult)

            return ret
예제 #5
0
 def _grab_attr_(self, obj, attr):
     if attr == 'category':
         return ', '.join(self.rd.get_cats(obj))
     try:
         ret = getattr(obj, attr)
     except:
         return None
     else:
         if attr in ['preptime', 'cooktime']:
             # this 'if' ought to be unnecessary, but is kept around
             # for db converting purposes -- e.g. so we can properly
             # export an old DB
             if ret and type(ret) != str:
                 ret = convert.seconds_to_timestring(
                     ret, fractions=self.fractions)
         elif attr == 'rating' and ret and type(ret) != str:
             if ret / 2 == ret / 2.0:
                 ret = "%s/5 %s" % (ret / 2, _('stars'))
             else:
                 ret = "%s/5 %s" % (ret / 2.0, _('stars'))
         if type(ret) in types.StringTypes and attr not in [
                 'thumb', 'image'
         ]:
             try:
                 ret = ret.encode(self.DEFAULT_ENCODING)
             except:
                 print "oops:", ret, "doesn't look like unicode."
                 raise
         return ret
예제 #6
0
def time_to_text (val):
    curtime = time.time()
    if val == 0:
        return 'Unknown'
    # within 18 hours, return in form 4 hours 23 minutes ago or some such
    if curtime - val < 18 * 60 * 60:
        return _("%s ago")%convert.seconds_to_timestring(curtime-val,round_at=1)
    tupl=time.localtime(val)
    if curtime - val <  7 * 24 * 60 * 60:
        return time.strftime('%A %T',tupl)
    else:
        return time.strftime('%D %T',tupl)
예제 #7
0
def time_to_text (val):
    curtime = time.time()
    if val == 0:
        return 'Unknown'
    # within 18 hours, return in form 4 hours 23 minutes ago or some such    
    if curtime - val < 18 * 60 * 60:
        return _("%s ago")%convert.seconds_to_timestring(curtime-val,round_at=1)
    tupl=time.localtime(val)
    if curtime - val <  7 * 24 * 60 * 60:
        return time.strftime('%A %T',tupl)
    else:
        return time.strftime('%D %T',tupl)
예제 #8
0
def get_display_constructor(attribute):
    if attribute == 'rating':
        return lambda v: ratingWidget.StarImage(
            ratingWidget.star_generator, value=v, upper=10)
    elif attribute in ['preptime', 'cooktime']:
        return lambda v: gtk.Label(convert.seconds_to_timestring(v))
    elif attribute == 'image':
        return lambda v: (v and gtk.Label("An Image") or gtk.Label("No Image"))
    elif attribute in gglobals.DEFAULT_TEXT_ATTR_ORDER:
        return make_text_label
    elif attribute == 'last_modified':
        return lambda v: gtk.Label(time_to_text(v))
    else:
        return lambda v: v and gtk.Label(v) or gtk.Label(_('None'))
예제 #9
0
def get_display_constructor (attribute):
    if attribute == 'rating':
        return lambda v: ratingWidget.StarImage(
            ratingWidget.star_generator,
            value=v,
            upper=10)
    elif attribute in ['preptime','cooktime']:
        return lambda v: gtk.Label(convert.seconds_to_timestring(v))
    elif attribute=='image':
        return lambda v: (v and gtk.Label("An Image") or gtk.Label("No Image"))
    elif attribute in gglobals.DEFAULT_TEXT_ATTR_ORDER:        
        return make_text_label
    elif attribute == 'last_modified':
        return lambda v: gtk.Label(time_to_text(v))
    else:
        return lambda v: v and gtk.Label(v) or gtk.Label(_('None'))
예제 #10
0
파일: browser.py 프로젝트: tmccombs/gourmet
 def convert_val(self, attr, val):
     if attr in ['preptime', 'cooktime']:
         if val:
             return convert.seconds_to_timestring(val)
         else:
             return 'None'
     elif attr == 'rating':
         if not val: return 'Unrated'
         else:
             val = int(val)
             txt = str(int(val) / 2)
             if val % 2:
                 txt += ' 1/2'
             txt += ' ' + _('Stars')
             return txt
     else:
         return str(val)
예제 #11
0
파일: browser.py 프로젝트: Bercio/gourmet
 def convert_val (self, attr, val):
     if attr in ['preptime','cooktime']:
         if val:
             return convert.seconds_to_timestring(val)
         else:
             return 'None'
     elif attr=='rating':
         if not val: return 'Unrated'
         else:
             val = int(val)
             txt = str(int(val) / 2)
             if val % 2:
                 txt += ' 1/2'
             txt += ' ' + _('Stars')
             return txt
     else:
         return str(val)
예제 #12
0
 def check_attrs(self):
     self.txt = self.txt.decode("utf-8")
     for attr in ["title", "cuisine", "source", "link"]:
         if getattr(self.rec, attr):
             assert re.search(
                 "<%(attr)s>\s*%(val)s\s*</%(attr)s>" % {"attr": attr, "val": getattr(self.rec, attr)}, self.txt
             ), "Did not find %s value %s" % (attr, getattr(self.rec, attr))
     if self.rec.yields:
         assert re.search(
             "<yields>\s*%s\s*%s\s*</yields>" % (self.rec.yields, self.rec.yield_unit), self.txt
         ) or re.search(
             "<yields>\s*%s\s*%s\s*</yields>" % (float_to_frac(self.rec.yields), self.rec.yield_unit), self.txt
         ), (
             "Did not find yields value %s %s" % (self.rec.yields, self.rec.yield_unit)
         )
     for att in ["preptime", "cooktime"]:
         if getattr(self.rec, att):
             tstr = seconds_to_timestring(getattr(self.rec, att))
             assert re.search(
                 "<%(att)s>\s*%(tstr)s\s*</%(att)s>" % locals(), self.txt
             ), "Did not find %s value %s" % (att, tstr)
예제 #13
0
파일: exporter.py 프로젝트: wummel/gourmet
    def _grab_attr_(self, obj, attr):
        if attr == 'category':
            return ', '.join(self.rd.get_cats(obj))
        try:
            ret = getattr(obj, attr)
        except:
            return None
        else:
            if attr in ['preptime', 'cooktime']:
                # this 'if' ought to be unnecessary, but is kept around
                # for db converting purposes -- e.g. so we can properly
                # export an old DB
                if ret and not isinstance(ret, str):
                    ret = convert.seconds_to_timestring(
                        ret, fractions=self.fractions)
            elif attr == 'rating' and ret and not isinstance(ret, str):
                if ret / 2 == ret / 2.0:
                    ret = "%s/5 %s" % (ret / 2, _('stars'))
                else:
                    ret = "%s/5 %s" % (ret / 2.0, _('stars'))

            return ret
예제 #14
0
 def _grab_attr_(self, obj, attr):
     # This is a bit ugly -- we allow exporting categories as if
     # they were a single attribute even though we in fact allow
     # multiple categories.
     if attr == "category":
         return ", ".join(self.rd.get_cats(obj))
     try:
         ret = getattr(obj, attr)
     except:
         return None
     else:
         if attr in ["preptime", "cooktime"]:
             # this 'if' ought to be unnecessary, but is kept around
             # for db converting purposes -- e.g. so we can properly
             # export an old DB
             if ret and type(ret) != str:
                 ret = convert.seconds_to_timestring(ret, fractions=self.fractions)
         elif attr == "rating" and ret and type(ret) != str:
             if ret / 2 == ret / 2.0:
                 ret = "%s/5 %s" % (ret / 2, _("stars"))
             else:
                 ret = "%s/5 %s" % (ret / 2.0, _("stars"))
         elif attr == "servings" and type(ret) != str:
             ret = convert.float_to_frac(ret, fractions=self.fractions)
         elif attr == "yields":
             ret = convert.float_to_frac(ret, fractions=self.fractions)
             yield_unit = self._grab_attr_(obj, "yield_unit")
             if yield_unit:
                 ret = "%s %s" % (ret, yield_unit)  # FIXME: i18n? (fix also below in exporter_mult)
         if type(ret) in [str, unicode] and attr not in ["thumb", "image"]:
             try:
                 ret = ret.encode(self.DEFAULT_ENCODING)
             except:
                 print "oops:", ret, "doesn't look like unicode."
                 raise
         return ret
예제 #15
0
 def set_value(self, seconds: float):
     self.entry.set_text(
         seconds_to_timestring(seconds, fractions=FRACTIONS_ASCII))
예제 #16
0
 def set_value (self,seconds):
     self.entry.set_text(
         convert.seconds_to_timestring(seconds,
                               fractions=convert.FRACTIONS_ASCII)
         )
예제 #17
0
 def set_value(self, seconds):
     self.entry.set_text(
         convert.seconds_to_timestring(seconds,
                                       fractions=convert.FRACTIONS_ASCII))