コード例 #1
0
def craw_awards():
    from biostar.apps.users.models import User
    from biostar.awards import create_user_award
    import random

    ids = [ u[0] for u in User.objects.all().values_list("id") ]

    random.shuffle(ids)

    ids = ids[:100]

    for pk  in ids:
        user = User.objects.get(pk=pk)
        #logger.info("%s: %s" % (user.id, user.name))
        create_user_award.delay(user=user)
コード例 #2
0
def crawl_awards():
    from biostar.apps.users.models import User
    from biostar.awards import create_user_award
    import random

    ids = [u[0] for u in User.objects.all().values_list("id")]

    random.shuffle(ids)

    ids = ids[:100]

    for pk in ids:
        user = User.objects.get(pk=pk)
        #logger.info("%s: %s" % (user.id, user.name))
        create_user_award.delay(user=user)
コード例 #3
0
ファイル: middleware.py プロジェクト: soncco/biostar-central
    def process_request(self, request, weeks=settings.COUNT_INTERVAL_WEEKS):
        global SESSION_KEY, ANON_USER

        user, session = request.user, request.session

        # Suspended users are logged out immediately.
        if user.is_authenticated() and user.is_suspended:
            logout(request)
            messages.error(request, 'Lo sentimos,  esta cuenta ha sido suspendida. Por favor contacta a los administradores.')

        # Add attributes to anonymous users.
        if not user.is_authenticated():

            # This attribute is required inside templates.
            user.is_moderator = user.is_admin = False

            # Check external logins.
            if settings.EXTERNAL_AUTH and valid_external_login(request):
                messages.success(request, "Login completo")

            # We do this to detect when an anonymous session turns into a logged in one.
            if ANON_USER not in session:
                session[ANON_USER] = True

        # User attributes that refresh at given intervals.
        if user.is_authenticated():

            # The time between two count refreshes.
            elapsed = (const.now() - user.profile.last_login).seconds

            # The user has an anonymous session already.
            # Update the user login data now.
            if ANON_USER in session:
                del session[ANON_USER]
                elapsed = settings.SESSION_UPDATE_SECONDS + 1

            # The user session will be updated.
            if elapsed > settings.SESSION_UPDATE_SECONDS:
                # Set the last login time.
                Profile.objects.filter(user_id=user.id).update(last_login=const.now())

                # Compute the counts.
                counts = get_counts(request)

                # Store the counts in the session for later use.
                session[SESSION_KEY] = counts

                # Create user awards if possible.
                create_user_award.delay(user=user)

                # check user and fill in details
                check_user_profile.delay(ip=get_ip(request), user=user)


        # Get the counts from the session or the cache.
        counts = session.get(SESSION_KEY) or cache.get(SESSION_KEY)

        # No sessions found, set the them into the session.
        if not counts:
            # Compute the counts
            counts = get_counts(request)

            # Put them into the session.
            session[SESSION_KEY] = counts

            # Store them in the cache for the next anonymous user.
            cache.set(SESSION_KEY, counts, settings.SESSION_UPDATE_SECONDS)
コード例 #4
0
    def process_request(self, request, weeks=settings.COUNT_INTERVAL_WEEKS):
        global SESSION_KEY, ANON_USER

        user, session = request.user, request.session

        # Suspended users are logged out immediately.
        if user.is_authenticated() and user.is_suspended:
            logout(request)
            messages.error(request, 'Sorry, this account has been suspended. Please contact the administrators.')

        # Add attributes to anonymous users.
        if not user.is_authenticated():

            # This attribute is required inside templates.
            user.is_moderator = user.is_admin = False

            # Check external logins.
            if settings.EXTERNAL_AUTH and valid_external_login(request):
                messages.success(request, "Login completed")

            # We do this to detect when an anonymous session turns into a logged in one.
            if ANON_USER not in session:
                session[ANON_USER] = True

        # User attributes that refresh at given intervals.
        if user.is_authenticated():

            # The time between two count refreshes.
            elapsed = (const.now() - user.profile.last_login).seconds

            # The user has an anonymous session already.
            # Update the user login data now.
            if ANON_USER in session:
                del session[ANON_USER]
                elapsed = settings.SESSION_UPDATE_SECONDS + 1

            # The user session will be updated.
            if elapsed > settings.SESSION_UPDATE_SECONDS:
                # Set the last login time.
                Profile.objects.filter(user_id=user.id).update(last_login=const.now())

                # Compute the counts.
                counts = get_counts(request)

                # Store the counts in the session for later use.
                session[SESSION_KEY] = counts

                # Create user awards if possible.
                create_user_award.delay(user=user)

                # check user and fill in details
                check_user_profile.delay(ip=get_ip(request), user=user)


        # Get the counts from the session or the cache.
        counts = session.get(SESSION_KEY) or cache.get(SESSION_KEY)

        # No sessions found, set the them into the session.
        if not counts:
            # Compute the counts
            counts = get_counts(request)

            # Put them into the session.
            session[SESSION_KEY] = counts

            # Store them in the cache for the next anonymous user.
            cache.set(SESSION_KEY, counts, settings.SESSION_UPDATE_SECONDS)