当前位置: 首页>>代码示例>>Python>>正文


Python date.format_date函数代码示例

本文整理汇总了Python中utils.date.format_date函数的典型用法代码示例。如果您正苦于以下问题:Python format_date函数的具体用法?Python format_date怎么用?Python format_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了format_date函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pretty_format_update_time

 def pretty_format_update_time(self):
     """XXX: move this somewhere else!"""
     if self.updatetime:
         return format_date(parse_date(self.updatetime), '%d.%m.%Y, %H:%M:%S')
     if self.creationtime:
         return format_date(parse_date(self.creationtime), '%d.%m.%Y, %H:%M:%S')
     return ''
开发者ID:mediatum,项目名称:mediatum,代码行数:7,代码来源:node.py

示例2: getStatFile

    def getStatFile(col_id, timestamp, type, period=period):
        f = None
        node = col_id.collection
        orig_file = None
        for file in node.getFiles():
            if file.getType() == u"statistic":
                try:
                    if file.getName() == u"stat_{}_{}_{}.xml".format(node.id, timestamp, type):
                        if timestamp == format_date(now(), "yyyy-mm") or timestamp == period:  # update current month or given period
                            # orig_file = file.retrieveFile()
                            if os.path.exists(file.retrieveFile()):
                                print 'removing %s' % file.retrieveFile()
                                os.remove(file.retrieveFile())
                                orig_file = file.retrieveFile()
                            # node.files.remove(file)
                            f = None
                            break
                        else:  # old month, do nothing
                            print 'old file doing nothing'
                            return None
                except:
                    return None
        if not f:
            # create new file
            f_name = config.get("paths.tempdir") + u"stat_{}_{}_{}.xml".format(node.id, timestamp, type)
            # create new file and write header:j
            print 'creating writing headers %s' % f_name
            f = codecs.open(f_name, "w", encoding='utf8')
            f.write('<?xml version="1.0" encoding="utf-8" ?>\n')
            f.write('<nodelist created="' + format_date(now(), "yyyy-mm-dd HH:MM:SS") + '">\n')

            if f_name not in col_id.statfiles:
                col_id.statfiles.append((f_name, orig_file))
            return f
开发者ID:mediatum,项目名称:mediatum,代码行数:34,代码来源:stats.py

示例3: archive_thread

    def archive_thread(self):
        if not time:
            return
        while True:
            time.sleep(int(config.get("archive.interval", 60)))
            archive_nodes_3 = db.getNodeIdByAttribute("archive_state", "3")
            archive_nodes_2 = []

            date_now = format_date(now(), "yyymmddhhmmss")

            for manager in self.manager:
                # search for nodes to archive after access over period (state 2)
                for n in db.getNodeIdByAttribute("archive_state", "2"):
                    try:
                        node = tree.getNode(n)
                        if node.get("archive_date"):
                            date_archive = format_date(parse_date(node.get("archive_date"), "%Y-%m-%dT%H:%M:%S"), "yyymmddhhmmss")
                            if date_now >= date_archive:
                                archive_nodes_2.append(long(node.id))
                    except:
                        pass

                # union to get all nodes with state 3 and 2 with over period
                archive_nodes = union((archive_nodes_3, archive_nodes_2))
                nodes = intersection((db.getNodeIdByAttribute("archive_type", str(manager)), archive_nodes))

                # run action defined in manager
                try:
                    self.manager[manager].actionArchive(nodes)
                except:
                    pass
开发者ID:agromsl,项目名称:mediatum,代码行数:31,代码来源:archive.py

示例4: getStatFile

    def getStatFile(node, timestamp, type, period=period):
        f = None
        for file in node.getFiles():
            if file.getType() == "statistic":
                try:
                    if file.getName() == "stat_{}_{}_{}.xml".format(node.id, timestamp, type):
                        if timestamp == str(format_date(now(), "yyyy-mm")) or timestamp == period:  # update current month or given period
                            if os.path.exists(file.retrieveFile()):
                                print 'removing %s' % file.retrieveFile()
                                os.remove(file.retrieveFile())
                            node.removeFile(file)  # remove old file and create new
                            f = None
                            break
                        else:  # old month, do nothing
                            print 'old file doing nothing'
                            return None
                except:
                    return None
        if not f:
            # create new file
            f_name = config.get("paths.tempdir") + "stat_{}_{}_{}.xml".format(node.id, timestamp, type)
            if os.path.exists(f_name):
                f = open(f_name, "a")
            else:
                # create new file and write header:
                print 'creating writing headers %s' % f_name
                f = open(f_name, "w")
                f.write('<?xml version="1.0" encoding="utf-8" ?>\n')
                f.write('<nodelist created="' + str(format_date(now(), "yyyy-mm-dd HH:MM:SS")) + '">\n')

            if f_name not in statfiles:
                statfiles.append(f_name)
            return f
开发者ID:agromsl,项目名称:mediatum,代码行数:33,代码来源:stats.py

示例5: get_datelists

def get_datelists(nodes):
    '''
    helper funtion to update default context before calling TAL interpreter
    '''
    update_date = []
    if len(nodes) == 1:
        for node in nodes:
            if node.updatetime:
                try:
                    date = parse_date(
                        node.updatetime, "%Y-%m-%dT%H:%M:%S")
                    datestr = format_date(date, format='%d.%m.%Y %H:%M:%S')
                except:
                    datestr = node.updatetime
                update_date.append([node.get("updateuser"), datestr])

    creation_date = []
    if len(nodes) == 1:
        for node in nodes:
            if node.get("creationtime"):
                try:
                    date = parse_date(
                        node.get("creationtime"), "%Y-%m-%dT%H:%M:%S")
                    datestr = format_date(date, format='%d.%m.%Y %H:%M:%S')
                except:
                    datestr = node.get("creationtime")
                creation_date.append([node.get("creator"), datestr])

    return update_date, creation_date
开发者ID:mediatum,项目名称:mediatum,代码行数:29,代码来源:metadata.py

示例6: runAction

    def runAction(self, node, op=""):
        """
        The actual proccessing of the node object takes place here.

        Read out the values of attrname and accesstype if any. Generate the
        ACL-rule, and save it.
        """
        l_date = node.get(self.get('attrname'))
        if l_date:
            if date.validateDateString(l_date):
                try:
                    node.set('updatetime', date.format_date(date.parse_date(l_date)))
                    formated_date = date.format_date(date.parse_date(l_date), "dd.mm.yyyy")
                    for item in self.get('accesstype').split(';'):
                        node.setAccess(item, "{date >= %s}" % formated_date)
                    node.getLocalRead()

                    if self.get('recipient'):  # if the recipient-email was entered, create a scheduler
                        attr_dict = {'single_trigger': l_date, 'function': "test_sendmail01",
                                     'nodelist': list(node.id), 'attr_recipient': self.get('recipient'),
                                     'attr_subject': "{} ID: {}".format(self.get('subject'),
                                                                        node.id),
                                     'attr_body': self.get('body')}

                        schedules.create_schedule("WorkflowStep_Defer", attr_dict)

                except ValueError as e:
                    print "Error: %s" % e
开发者ID:agromsl,项目名称:mediatum,代码行数:28,代码来源:defer.py

示例7: getUpdatedDate

 def getUpdatedDate(self, format=None):
     if format is None:
         format = STANDARD_FORMAT
     if self.get('updatetime'):
         return format_date(parse_date(self.get('updatetime')), '%d.%m.%Y, %H:%M:%S')
     if self.get('creationtime'):
         return format_date(parse_date(self.get('creationtime')), '%d.%m.%Y, %H:%M:%S')
     return ''
开发者ID:anx-astocker,项目名称:mediatum,代码行数:8,代码来源:tree.py

示例8: replace_or_add_defer_date

def replace_or_add_defer_date(node, iso_date_old, iso_date_new, access_types=[u'read', u'data']):
    """
    examples:
        # set new date in the future (for read and data access)
        replace_or_add_defer_date(node, u"2016-11-03T00:00:00", u"2017-11-03T00:00:00")

        # remove existing rule
        replace_or_add_defer_date(node, u"2016-11-03T00:00:00", u"")

        # add new rule
        replace_or_add_defer_date(node, u"", u"2017-11-03T00:00:00")
    """

    if (not (iso_date_old or iso_date_new)) or (not access_types):
        print ("noting to be done")
        return

    import utils.date as date
    from psycopg2.extras import DateRange
    import datetime
    from core import AccessRule, AccessRulesetToRule, db

    q = db.query
    from core.permission import get_or_add_access_rule

    if iso_date_old:
        formatted_date_old = date.format_date(date.parse_date(iso_date_old), "dd.mm.yyyy")
        day_old, month_old, year_old = map(int, formatted_date_old.split('.'))
        dateranges_old = set([DateRange(datetime.date(year_old, month_old, day_old),
                                        datetime.date(9999, 12, 31), '[)')])
        # !!! exit if more than one rule for this daterange exists, should be fixed by looping through the nodes rules
        rule_old = q(AccessRule).filter_by(group_ids=None, dateranges=dateranges_old, subnets=None,
                                           invert_group=False, invert_date=False, invert_subnet=False).one()
        if not rule_old:
            raise ValueError('rule not found for old date {}'.format(iso_date_old))
        print("found old rule {}".format(rule_old.to_dict()))
    else:
        rule_old = None

    if iso_date_new:

        formatted_date_new = date.format_date(date.parse_date(iso_date_new), "dd.mm.yyyy")
        day_new, month_new, year_new = map(int, formatted_date_new.split('.'))
        dateranges_new = set([DateRange(datetime.date(year_new, month_new, day_new),
                                        datetime.date(9999, 12, 31), '[)')])

        rule_new = get_or_add_access_rule(dateranges=dateranges_new)
    else:
        rule_new = None

    for access_type in access_types:
        special_access_ruleset = node.get_or_add_special_access_ruleset(ruletype=access_type)
        if rule_old:
            arr_old = q(AccessRulesetToRule).filter_by(ruleset=special_access_ruleset, rule=rule_old).one()
            special_access_ruleset.rule_assocs.remove(arr_old)
        if rule_new:
            special_access_ruleset.rule_assocs.append(AccessRulesetToRule(rule=rule_new))
开发者ID:mediatum,项目名称:mediatum,代码行数:57,代码来源:mediatumipython.py

示例9: try_node_date

def try_node_date(node, attr_list=attr_list):
    for key in attr_list:
        timevalue = node.get(key)
        if date_pattern_standard.match(timevalue):
            rfc822_time = format_date(parse_date(timevalue), 'rfc822')
            break
        elif date_pattern_armus.match(timevalue):
            rfc822_time = format_date(parse_date(timevalue, format="%m/%d/%Y"), 'rfc822')
            break
        else:
            rfc822_time = ''
    return rfc822_time
开发者ID:agromsl,项目名称:mediatum,代码行数:12,代码来源:rssnode.py

示例10: show_workflow_node

    def show_workflow_node(self, node, req):
        attrname = self.get("attrname")
        niss = self.get("niss")

        if attrname == "":
            attrname = "urn"

        # create urn only for nodes with files
        if len(node.files) > 0:
            urn = node.get(attrname)
            if urn:
                node.set(attrname, utilsurn.increaseURN(node.get(attrname)))
            else:
                for var in re.findall(r'\[(.+?)\]', niss):
                    if var == "att:id":
                        niss = niss.replace("[" + var + "]", unicode(node.id))
                    elif var.startswith("att:"):
                        val = node.get(var[4:])
                        try:
                            val = date.format_date(date.parse_date(val), '%Y%m%d')
                        except:
                            logg.exception("exception in workflow step urn, date formatting failed, ignoring")
                            
                        niss = niss.replace("[" + var + "]", val)
                node.set(attrname, utilsurn.buildNBN(self.get("snid1"), self.get("snid2"), niss))
        db.session.commit()
        return self.forwardAndShow(node, True, req)
开发者ID:mediatum,项目名称:mediatum,代码行数:27,代码来源:urn.py

示例11: show_workflow_node

    def show_workflow_node(self, node, req):
        attrname = self.get("attrname")
        niss = self.get("niss")

        if attrname == "":
            attrname = "urn"

        # create urn only for nodes with files
        if len(node.getFiles()) > 0:
            urn = node.get(attrname)
            if urn:
                node.set(attrname, utilsurn.increaseURN(node.get(attrname)))
            else:
                for var in re.findall(r"\[(.+?)\]", niss):
                    if var == "att:id":
                        niss = niss.replace("[" + var + "]", node.id)
                    elif var.startswith("att:"):
                        val = node.get(var[4:])
                        try:
                            val = date.format_date(date.parse_date(val), "%Y%m%d")
                        except:
                            pass
                        niss = niss.replace("[" + var + "]", val)
                node.set(attrname, utilsurn.buildNBN(self.get("snid1"), self.get("snid2"), niss))
        return self.forwardAndShow(node, True, req)
开发者ID:hibozzy,项目名称:mediatum,代码行数:25,代码来源:urn.py

示例12: createNewVersion

    def createNewVersion(self, user):
        if self.get('system.version.id') == '':
            self.set('system.version.id', '1')

        n = Node(name=self.name, type=self.type)
        n.set("creator", self.get('creator'))
        n.set("creationtime", self.get('creationtime'))
        n.set("updateuser", user.getName())
        n.set("edit.lastmask", self.get('edit.lastmask'))

        if self.get('updatetime') < str(now()):
            n.set("updatetime", str(format_date()))
        else:
            n.set("updatetime", str(self.get('updatetime')))

        for f in self.getFiles():
            n.addFile(f)

        activeNode = self.getActiveVersion()
        for pid in db.getParents(activeNode.id):
            parentNode = getNode(pid)
            parentNode.addChild(n)
            parentNode.removeChild(activeNode)

        for cid in db.getChildren(activeNode.id):
            if cid != activeNode.prev_nid:
                n.addChild(getNode(cid))
        n.set("system.version.id", self.getLastVersionID() + 1)

        n.setPrevID(activeNode.id)
        activeNode.setNextID(n.id)
        n.addChild(activeNode)
        return n
开发者ID:anx-astocker,项目名称:mediatum,代码行数:33,代码来源:tree.py

示例13: getFormatedValue

    def getFormatedValue(self, field, node, language=None, html=1):
        value = node.get(field.getName())

        if not value or value == "0000-00-00T00:00:00":  # dummy for unknown
            return (field.getLabel(), "")
        else:
            try:
                d = parse_date(value)
            except ValueError:
                return (field.getLabel(), value)
            value = format_date(d, format=field.getValues())

        value_list = []

        if re.search(r'\d{2}\W\d{2}\W', value):
            day_month = re.sub(r'00\W', '', re.search(r'\d{2}\W\d{2}\W', value).group())
            value_list.append(day_month)

        if re.search(r'\d{4}\W\d{2}', value):
            year_month = re.sub(r'\W00', '', re.search(r'\d{4}-\d{2}', value).group())
            value_list.append(year_month)
        elif re.search(r'\d{4}', value):
            value_list.append(re.search(r'\d{4}', value).group())

        return (field.getLabel(), ''.join(value_list))
开发者ID:agromsl,项目名称:mediatum,代码行数:25,代码来源:date.py

示例14: formatdate

def formatdate(value, f='%d.%m.%Y %H:%M:%S'):
    if not isinstance(value, unicode):
        value = unicode(value)
    try:
        return format_date(parse_date(value, "%Y-%m-%dT%H:%M:%S"), format=f)
    except ValueError:
        return value
开发者ID:mediatum,项目名称:mediatum,代码行数:7,代码来源:admin.py

示例15: createLDAPUser

        def createLDAPUser(data, uname):
            user = tree.Node(uname, "user")
            user.set("lastname", self._getAttribute(config.get("ldap.user_lastname"), data))
            user.set("firstname", self._getAttribute(config.get("ldap.user_firstname"), data))
            user.set("email", self._getAttribute(config.get("ldap.user_email"), data))
            user.set("organisation", self._getAttribute(config.get("ldap.user_org"), data))
            user.set("comment", self._getAttribute(config.get("ldap.user_comment"), data))
            user.set("identificator", self._getAttribute(config.get("ldap.user_identificator"), data))
            user.set("ldapuser.creationtime", date.format_date())

            if user.get("lastname") != "" and user.get("firstname") != "":
                user.setName("%s %s" % (user.get("lastname"), user.get("firstname")))

            added_to_groups = 0
            for group in self._getAttribute(config.get("ldap.user_group"), data, ",").split(","):
                if group != "" and not usergroups.existGroup(group):
                    #res = usergroups.create_group(group, description="LDAP Usergroup", option="")
                    #res.set("ldapusergroup.creationtime", date.format_date())
                    logging.getLogger('usertracing').info("skipped creation of ldap user group: " + group)
                    continue
                g = usergroups.getGroup(group)
                if g:
                    g.addChild(user)
                    added_to_groups += 1

            logging.getLogger('usertracing').info("created ldap user: " + uname)
            if not added_to_groups:
                logging.getLogger('usertracing').warning("created ldap user %r, %r not added to any group" % (uname, user.id))
            return user
开发者ID:agromsl,项目名称:mediatum,代码行数:29,代码来源:userldap.py


注:本文中的utils.date.format_date函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。