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


Python timezone.now函数代码示例

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


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

示例1: render

 def render(self, context):
     featured = FeaturedProject.objects.filter(
                     featured_start_date__lte=now(),
                     project__publish_date__lte=now(),
                     project__status=CONTENT_STATUS_PUBLISHED
                     )
     context['featured_projects'] = featured[:self.num]
     return ''
开发者ID:Edinunzio,项目名称:raspberryio,代码行数:8,代码来源:project_tags.py

示例2: save

 def save(self, *args, **kwargs):
     # Set project as draft by default
     if not self.id:
         self.status = CONTENT_STATUS_DRAFT
     # Set created and modified datetimes if not provided.
     if not self.id:
         self.created_datetime = now()
     self.modified_datetime = now()
     super(Project, self).save(*args, **kwargs)
开发者ID:transformersprimeabcxyz,项目名称:raspberryio-python,代码行数:9,代码来源:models.py

示例3: published

 def published(self, for_user=None):
     """
     For non-staff users, return items with a published status and
     whose publish and expiry dates fall before and after the
     current date when specified.
     """
     from mezzanine.core.models import CONTENT_STATUS_PUBLISHED
     if for_user is not None and for_user.is_staff:
         return self.all()
     return self.filter(
         Q(publish_date__lte=now()) | Q(publish_date__isnull=True),
         Q(expiry_date__gte=now()) | Q(expiry_date__isnull=True),
         Q(status=CONTENT_STATUS_PUBLISHED))
开发者ID:kienmohu,项目名称:mezzanine,代码行数:13,代码来源:managers.py

示例4: save

 def save(self, *args, **kwargs):
     self.modified_date = now()
     if not self.content_type:
         ct = ContentType.objects
         ct = ct.get_for_model(self.__class__)
         self.content_type = ct
     super(BlogProxy, self).save(*args, **kwargs)
开发者ID:RossiAndrea,项目名称:mezzanine-beer-recipes,代码行数:7,代码来源:models.py

示例5: from_request

 def from_request(self, request):
     """
     Return a cart by ID stored in the session, creating it if not
     found as well as removing old carts prior to creating a new
     cart.
     """
     n = now()
     expiry_minutes = timedelta(minutes=settings.SHOP_CART_EXPIRY_MINUTES)
     expiry_time = n - expiry_minutes
     cart_id = request.session.get("cart", None)
     cart = None
     if cart_id:
         try:
             cart = self.get(last_updated__gte=expiry_time, id=cart_id)
         except self.model.DoesNotExist:
             request.session["cart"] = None
         else:
             # Update timestamp and clear out old carts.
             cart.last_updated = n
             cart.save()
             self.filter(last_updated__lt=expiry_time).delete()
     if not cart:
         from cartridge.shop.utils import EmptyCart
         cart = EmptyCart(request)
     return cart
开发者ID:AkademieOlympia,项目名称:cartridge,代码行数:25,代码来源:managers.py

示例6: save

 def save(self, **kwargs):
     """
     Create a ``FormEntry`` instance and related ``FieldEntry``
     instances for each form field.
     """
     entry = super(FormForForm, self).save(commit=False)
     entry.form = self.form
     entry.entry_time = now()
     entry.save()
     entry_fields = entry.fields.values_list("field_id", flat=True)
     new_entry_fields = []
     for field in self.form_fields:
         field_key = "field_%s" % field.id
         value = self.cleaned_data[field_key]
         if value and self.fields[field_key].widget.needs_multipart_form:
             value = fs.save(join("forms", str(uuid4()), value.name), value)
         if isinstance(value, list):
             value = ", ".join([v.strip() for v in value])
         if field.id in entry_fields:
             field_entry = entry.fields.get(field_id=field.id)
             field_entry.value = value
             field_entry.save()
         else:
             new = {"entry": entry, "field_id": field.id, "value": value}
             new_entry_fields.append(FieldEntry(**new))
     if new_entry_fields:
         if django.VERSION >= (1, 4, 0):
             FieldEntry.objects.bulk_create(new_entry_fields)
         else:
             for field_entry in new_entry_fields:
                 field_entry.save()
     return entry
开发者ID:422053362,项目名称:mezzanine,代码行数:32,代码来源:forms.py

示例7: get_active_users

def get_active_users(days=7, number=4):
    """
    Return a queryset of the most active users for the given `days` and limited
    to `number` users. Defaults to 7 days and 4 users.
    """
    yester_date = now() - timedelta(days=days)
    actions = Action.objects.model_actions(User) \
        .filter(timestamp__gte=yester_date) \
        .values_list('actor_object_id', flat=True)
    # Create a counter for user pks with the most associated actions
    action_counter = Counter(actions).most_common(number)
    # Sort the most active users on the number of actions
    action_counter.sort(key=itemgetter(1), reverse=True)
    # Use the user pk's to query for the user data
    most_active_user_pks = map(
        lambda user_action: int(user_action[0]), action_counter
    )
    users = User.objects.filter(
        pk__in=most_active_user_pks, is_active=True, profile__isnull=False
    )
    # Return a list of users sorted on the number of actions (desc.)
    pk_user_mapping = dict((user.pk, user) for user in users)
    return [
        pk_user_mapping[pk]
        for pk in most_active_user_pks
        if pk in pk_user_mapping
    ]
开发者ID:Edinunzio,项目名称:raspberryio,代码行数:27,代码来源:utils.py

示例8: test_is_published_false

 def test_is_published_false(self):
     self.project.publish_date = now() + timedelta(minutes=1)
     self.project.save()
     self.assertFalse(self.project.is_published(),
         'Should return False if publish_date is in the future'
     )
     self.project.publish_date = now() - timedelta(minutes=1)
     self.project.status = CONTENT_STATUS_DRAFT
     self.project.save()
     self.assertFalse(self.project.is_published(),
         'Should return False if status is "Draft"'
     )
     self.project_publish_date = now() + timedelta(minutes=1)
     self.project.save()
     self.assertFalse(self.project.is_published(),
         'Should return False if status is "Draft" and publish_date is in the future'
     )
开发者ID:JigsawYang,项目名称:raspberryio,代码行数:17,代码来源:test_models.py

示例9: on_sale

 def on_sale(self):
     """
     Returns True if the sale price is applicable.
     """
     n = now()
     valid_from = self.sale_from is None or self.sale_from < n
     valid_to = self.sale_to is None or self.sale_to > n
     return self.sale_price is not None and valid_from and valid_to
开发者ID:GozoLabs,项目名称:cartridge,代码行数:8,代码来源:models.py

示例10: save

 def save(self, *args, **kwargs):
     """
     Set default for ``publish_date``. We can't use ``auto_now_add`` on
     the field as it will be blank when a blog post is created from
     the quick blog form in the admin dashboard.
     """
     if self.publish_date is None:
         self.publish_date = now()
     super(Displayable, self).save(*args, **kwargs)
开发者ID:boardman,项目名称:mezzanine,代码行数:9,代码来源:models.py

示例11: active

 def active(self, *args, **kwargs):
     """
     Items flagged as active and in valid date range if date(s) are
     specified.
     """
     n = now()
     valid_from = Q(valid_from__isnull=True) | Q(valid_from__lte=n)
     valid_to = Q(valid_to__isnull=True) | Q(valid_to__gte=n)
     return self.filter(valid_from, valid_to, active=True)
开发者ID:eedeep,项目名称:cartridge,代码行数:9,代码来源:managers.py

示例12: add_item

 def add_item(self, *args, **kwargs):
     """
     Create a real cart object, add the items to it and store
     the cart ID in the session.
     """
     from cartridge.shop.models import Cart
     cart = Cart.objects.create(last_updated=now())
     cart.add_item(*args, **kwargs)
     self._request.session["cart"] = cart.id
开发者ID:AkademieOlympia,项目名称:cartridge,代码行数:9,代码来源:utils.py

示例13: published

    def published(self, for_user=None):
        """
        For non-staff/permissionless users, return items with a published status and
        whose publish and expiry dates fall before and after the
        current date when specified.
        :param for_user:
        """
        from mezzanine.core.models import CONTENT_STATUS_PUBLISHED
        from widget.utilities import widget_extra_permission

        #This allows a callback for extra user validation, eg. check if a user passes a test (has a subscription)
        if for_user is not None and bool(for_user.is_staff
            or bool(for_user.has_perm("widget.change_widget") and widget_extra_permission(for_user))):
            return self.all()
        return self.filter(
            Q(publish_date__lte=now()) | Q(publish_date__isnull=True),
            Q(expiry_date__gte=now()) | Q(expiry_date__isnull=True),
            Q(status=CONTENT_STATUS_PUBLISHED))
开发者ID:gelliravi,项目名称:mezzanine_widgets,代码行数:18,代码来源:models.py

示例14: is_published

    def is_published(self, request=None):
        """
        Returns True/False if the Project is published for the user in the
        given request. Staff users can see any projects while regular users can
        see any of their own projects

        If no request is given, or the user is not staff and viewing another
        user's project, returns True if publish_date <= now() and status ==
        CONTENT_STATUS_PUBLISHED otherwise False.
        """
        if request is not None:
            if request.user.is_staff or request.user == self.user:
                return True
        return self.publish_date <= now() and self.status == CONTENT_STATUS_PUBLISHED
开发者ID:transformersprimeabcxyz,项目名称:raspberryio-python,代码行数:14,代码来源:models.py

示例15: clean_card_expiry_year

 def clean_card_expiry_year(self):
     """
     Ensure the card expiry doesn't occur in the past.
     """
     try:
         month = int(self.cleaned_data["card_expiry_month"])
         year = int(self.cleaned_data["card_expiry_year"])
     except ValueError:
         # Haven't reached payment step yet.
         return
     n = now()
     if year == n.year and month < n.month:
         raise forms.ValidationError(_("A valid expiry date is required."))
     return str(year)
开发者ID:skyfion,项目名称:cartridge,代码行数:14,代码来源:forms.py


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