0

I want to hide some section of interface from my django application. For example if I have a widget that shows some stats I don't want this widget to be appear on every user after they login to the site. I want to hide randomly. In addition lets say if I have an search results sorting function, I want randomly pick group of users to sort it in descending order by time and other group to see it ascending order.

My first task is how to pick users randomly after they login. How do you define this type of randomness in django application. I cann't really think what example I should include here but, this is a simple widget that I have to show top 5 contributors of the site.

{% cache 600 "contributors" contributors search_tags scope sort query context.page language_code %}
  <div id="contrib-users" class="box">
  <h2 class="contributorback">{% trans %}Top 5 Contributors{% endtrans %}</h2>
  {% spaceless %}
  {% for user in contributors %}
    <div class="contributor">
        <div class="contrib-thumb">{{ macros.gravatar(user, 32) }}</div>
        <div class="contrib-text">
            <span class="contrib-username">
                <a href="{{ user.get_absolute_url() }}">{{user.username|escape}}</a>
            </span>
            <span class="contrib-rep">{{ macros.user_score_and_badge_summary(user, settings.KARMA_MODE, settings.BADGES_MODE) }}
        </div>
    </div>
  {% endfor %}
  {% endspaceless %}
  </div>
{% endcache %}

Lets assume I have users from user0001 - user1000 in the system and I want randomly pick 25% users to see the widget. How can I accomplish that.

add-semi-colons
  • 18,094
  • 55
  • 145
  • 232

1 Answers1

1

It sounds like you're trying to do a/b split testing? In which case there are a few django apps out there to help you do that:

django-lean seems to be quite heavyweight, but has lots of useful tools in it.

django-experiments does what you're after and was updated fairly recently.

At the very least you could browse around their source and see how they divide up the users.

ptr
  • 3,292
  • 2
  • 24
  • 48
  • Thanks, These django apps are very heavy :( – add-semi-colons Mar 19 '14 at 16:27
  • Yup, but like I say if all you need to do is something very lightweight, you can have a look at those apps and see how they split the users up (a/b split testing is all about randomly dividing your users up based on percentages) – ptr Mar 19 '14 at 16:29