예제 #1
0
 def save(self, *args, **kwargs):
     if self.pk:
         old_instance = Page.objects.get(pk=self.pk)
         if self.published:
             if not old_instance.published_at and not old_instance.published:
                 self.published_at = utc_now()
     super(Page, self).save(*args, **kwargs) # Call the "real" save() method.
예제 #2
0
파일: api2.py 프로젝트: reverie/jotleaf.com
def _make_fulluser(request, meta_data={}):
    import dateutil.parser
    from common.shortcuts import utc_now
    from main.permissions import FullUser, INTERNAL_USERNAME
    user_agent = request.META.get('HTTP_USER_AGENT', '')
    if user_agent.startswith('Jotleaf-Internal'):
        _, timestamp, signature = user_agent.split('|')
        dt = dateutil.parser.parse(timestamp)
        sig_is_recent = within_five_minutes(dt, utc_now())
        sig_matches = (signature == make_internal_signature(timestamp))
        if sig_is_recent and sig_matches:
            request.user = User.objects.get_or_create(username=INTERNAL_USERNAME)[0]
    return FullUser(
        request.user, 
        request.META['REMOTE_ADDR'], 
        request.session.session_key,
        meta_data.get('window_id'),
        _get_extra_page_permissions(request)
    )
예제 #3
0
def get_active_users(now=None):
    """Returns the number of registered users who have viewed a page in the past two weeks."""
    if now is None:
        now = utc_now()
    two_weeks_ago = now - datetime.timedelta(days=14)
    return User.objects.filter(pageview__created_at__gte=two_weeks_ago).distinct().count()