Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3666786
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:55:21+00:00 2026-05-19T01:55:21+00:00

I have some middleware which takes a tuple (of usernames… it only allows usernames

  • 0

I have some middleware which takes a tuple (of usernames… it only allows usernames in the tuple to pass through certain areas of the site).

I have a UserProfile model which contains information about each user, and I want to filter it so that it returns a tuple of usernames for use with this middleware — in otherwords, set a variable BETA_USERS = (dynamically-generated-tuple).

Have you got any suggestions for accomplishing this?

Edit:

So, the tuple really isn’t an important detail — here’s an example:

Generally, I would just hard-code this into settings:

BETA_USERS = ('username1', 'username2', 'username3', 'username4')

However, I have a UserProfile model which contains a Beta column, which can be set to 1. The first 50 people to sign up for the beta will be set to 1, everyone else 0. So, I can easily filter this by calling a filter method on a model object:

users = UserProfile.objects.filter(beta='1')

and I can make that a nice tuple with this strange little loop:

for user in users:
    list.append((user.user.username).upper())
return tuple(list)

I guess my real question is, what is the best way for me to call this in my settings file?

or, stated another way, what’s the best way to assign dynamically created variables in the settings file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:55:21+00:00Added an answer on May 19, 2026 at 1:55 am

    You can also use the @user_passes_test decorator to restrict views to particular subsets of users. Or create your own decorator:

    from django.utils.functional import wraps
    
    def beta(view):
        @wraps(view)
        def inner(request, *args, **kwargs):
            if request.user.user_profile.beta:
                return view(request, *args, **kwargs)
            # Up to you how you return failure...
        return inner
    

    Now you can use it as:

    @beta
    def my_view(request):
        # do something new here.
    

    The alternative is:

    @user_passes_test(lambda u: u.profile.beta)
    def my_view(request):
        # do something clever
    

    The advantage of the @beta form is that it is a bit easier to re-use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have middleware which do some work for me. Is it possible to pass
I have a middleware that does some processing. On certain conditions it raises an
I have some custom render_to_response methods which now needs request object, I could pass
I'm new to Java EE and have been struggling with some basic middleware concepts
I have converted my web service to wcf service which has some datacontracts. As
Using Apache Felix, I have an OSGi component I've authored that wraps some middleware
I have a Pyramid application which uses request.environ['REMOTE_ADDR'] in some places. The application is
I have a Rails 3 application of which some controllers are normal rails controllers
I have written some code using express.js which I'd like to put on the
Suppose I have a view in which some of the column names are aliases,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.