コード例 #1
0
ファイル: notices.py プロジェクト: JonnyFunFun/pyParty
def get_notices(request):
    notices = []
    # upcoming tournament notices
    if get_setting('enable_tournaments') == '1':
        upcoming = Tournament.objects.filter(starts__lte=(datetime.now() + timedelta(hours=1)))
        if upcoming.count() == 1:
            notices.append("The tournament %s is starting within the hour" % upcoming[0].name)
        elif upcoming.count() > 1:
            notices.append("%d tournaments are starting within the hour" % upcoming.count())
    # get admin notices
    if request.user.is_admin:
        # servers needing approval
        servers_unapproved = Server.objects.filter(mod_approved=False)
        if servers_unapproved.count() is not 0:
            notices.append("%d servers require admin approval." % servers_unapproved.count())
        # jukebox is not running
        if get_setting('enable_music') == '1' and Music.currently_playing() is None:
            notices.append("No music is currently playing!")
    # and return the lot of them
    return HttpResponse(json.dumps(notices), content_type='application/json')
コード例 #2
0
def settings_for_view(context):
    return {'SITE_NAME': get_setting('site_name'),
            'SITE_TITLE': get_setting('site_title'),
            'ENABLE_MUSIC': get_setting('enable_music'),
            'ENABLE_BENCHMARKS': get_setting('enable_benchmarks'),
            'ENABLE_GALLERY': get_setting('enable_gallery'),
            'ENABLE_TOURNAMENTS': get_setting('enable_tournaments'),
            'ENABLE_SERVERS': get_setting('enable_servers'),
            'ENABLE_NOMS': get_setting('enable_noms'),
            'THUMB_X': settings.THUMBNAIL_SIZE[0],
            'THUMB_Y': settings.THUMBNAIL_SIZE[1],
            'MUSIC_PLAYING': Music.currently_playing()
    }
コード例 #3
0
ファイル: views.py プロジェクト: JonnyFunFun/pyParty
def do_departure(request):
    if request.method == 'POST' and get_setting('goodbye_survey') == '1':
        survey = DepartingSurvey(data=request.POST)
        try:
            survey.save()
        except:
            pass  # don't fail here
    profile = request.user.profile
    profile.departed = True
    profile.save(force_update=True)
    logout(request)
    return locals()
コード例 #4
0
ファイル: middleware.py プロジェクト: JonnyFunFun/pyParty
 def process_request(self, request):
     if request.user.is_authenticated():
         return
     PartyHooks.execute_hook('user.prelogin', request=request)
     hostname = request.META['REMOTE_HOST'] or request.META['REMOTE_ADDR']
     try:
         # reverse the profile back to user based on hostname
         up = UserProfile.objects.get(hostname=hostname)
         user = up.user
         user.backend = 'django.contrib.auth.backends.ModelBackend'
         request.user = user
         auth.login(request, up.user)
         if request.path not in ['/favicon.ico'] and not settings.STATIC_URL in request.path:
             if up.departed:
                 up.departed = False
                 up.save()
                 PartyHooks.execute_hook('user.returns')
                 messages.success(request, "Welcome back to the LAN!")
     except UserProfile.DoesNotExist:
         # if we're the first user, we're always an admin
         first_admin = (User.objects.count() == 0)
         # add a new user
         random_password = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(12))
         username = request.META['REMOTE_HOST'] or 'User-'+''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(6))
         user = User.objects.create_user(username, None, random_password)
         user.save()
         profile = UserProfile()
         profile.user = user
         profile.hostname = hostname
         if first_admin:
             profile.set_flag(FLAG_ADMIN)
         profile.save()
         request.user = user
         user = auth.authenticate(username=username, password=random_password)
         auth.login(request, user)
         if first_admin:
             # redirect to admin panel for setup
             messages.success(request, "Welcome to pyParty!  As the first user, you're automatically an admin.  Please continue setting up pyParty as you normally would!")
             return HttpResponseRedirect('/admin/')
         else:
             messages.success(request, "Welcome to %s!  We set up an account for you.  There's no need for a password, you will be recognized by your computer.  Feel free to <a href='/accounts/profile/'>continue setting up your profile</a>." % get_setting('lan_name'))
コード例 #5
0
ファイル: views.py プロジェクト: JonnyFunFun/pyParty
def index(request):
    message = get_setting('welcome_msg')
    title = "Dashboard"
    icon = "home"
    announcements = Announcement.latest(3)
    return locals()
コード例 #6
0
ファイル: views.py プロジェクト: JonnyFunFun/pyParty
def departing(request):
    title = "Leaving the LAN?"
    icon = "signout"
    do_survey = get_setting('goodbye_survey') == '1'
    survey = DepartingSurvey()
    return locals()
コード例 #7
0
 def wrapper(request, *args, **kw):
     if get_setting('enable_%s' % section_name) != '1':
         warning(request, "That module is not enabled.")
         return HttpResponseRedirect('/')
     return func(request, *args, **kw)