Beispiel #1
0
def nowplaying(request):
    song = get_now_playing_song()

    return j2shim.r2r('webview/js/now_playing.html', {
        'now_playing': song,
        'user': request.user
    }, request)
Beispiel #2
0
def songupdate(request, song_id):
    song = Song.objects.get(id=song_id)
    return j2shim.r2r('webview/js/generic.html', {
        'song' : song,
        'event' : "a_queue_%i" % song.id,
        'template' : 'webview/t/songlist_span.html',
        },  request)
Beispiel #3
0
def nowplaying (request):
    song = get_now_playing_song ()

    return j2shim.r2r ('webview/js/now_playing.html',
                       {'now_playing'   : song,
                        'user'          : request.user},
                       request)
Beispiel #4
0
def countrybox(request):
    alpha2list = country_by_code2.keys()
    alpha2list.sort(
        lambda a, b: cmp(country_by_code2[a].name, country_by_code2[b].name))

    return j2shim.r2r('webview/t/countrybox.html', {'alpha2list': alpha2list},
                      request)
Beispiel #5
0
def countrybox (request):
    alpha2list = country_by_code2.keys ()
    alpha2list.sort (lambda a, b: cmp (country_by_code2[a].name, country_by_code2[b].name))

    return j2shim.r2r ('webview/t/countrybox.html',
                       {'alpha2list'   : alpha2list},
                       request)
Beispiel #6
0
def songupdate(request, song_id):
    song = Song.objects.get(id=song_id)
    return j2shim.r2r(
        'webview/js/generic.html', {
            'song': song,
            'event': "a_queue_%i" % song.id,
            'template': 'webview/t/songlist_span.html',
        }, request)
Beispiel #7
0
def songupdate(request, song_id):
    song = Song.objects.get(id=song_id)
    return HttpResponse("""<span style="display:none">l</span>
                <img class="song_tail" src="%slock.png" title="Locked" alt="Locked"/>""" %
                settings.MEDIA_URL)

    return j2shim.r2r('webview/js/generic.html', {
        'song' : song,
        'event' : "a_queue_%i" % song.id,
        'template' : 'webview/t/songlist_span.html',
        },  request)
Beispiel #8
0
def songupdate(request, song_id):
    song = Song.objects.get(id=song_id)
    return HttpResponse("""<span style="display:none">l</span>
                <img class="song_tail" src="%slock.png" title="Locked" alt="Locked"/>"""
                        % settings.MEDIA_URL)

    return j2shim.r2r(
        'webview/js/generic.html', {
            'song': song,
            'event': "a_queue_%i" % song.id,
            'template': 'webview/t/songlist_span.html',
        }, request)
Beispiel #9
0
def forum(request, slug):
    """
    Displays a list of threads within a forum.
    Threads are sorted by their sticky flag, followed by their
    most recent post.
    """
    f = get_object_or_404(Forum, slug=slug)

    # If the user is not authorized to view the thread, then redirect
    if f.is_private and request.user.is_staff != True:
        return HttpResponseRedirect('/forum')

    # Process new thread form if data was sent
    if request.method == 'POST':
        if not request.user.is_authenticated():
            return HttpResponseServerError()
        thread_form = ThreadForm(request.POST)
        if thread_form.is_valid():
            new_thread = thread_form.save(commit=False)
            new_thread.forum = f
            new_thread.save()
            Post.objects.create(thread=new_thread,
                                author=request.user,
                                body=thread_form.cleaned_data['body'],
                                time=datetime.now())
            if (thread_form.cleaned_data['subscribe'] == True):
                Subscription.objects.create(author=request.user,
                                            thread=new_thread)
            return HttpResponseRedirect(new_thread.get_absolute_url())
    else:
        thread_form = ThreadForm()

    # Pagination
    t = f.thread_set.all()
    paginator = Paginator(t, settings.FORUM_PAGINATE)
    try:
        page = int(request.GET.get('page', 1))
    except:
        page = 1
    try:
        threads = paginator.page(page)
    except (EmptyPage, InvalidPage):
        threads = paginator.page(paginator.num_pages)

    return j2shim.r2r(
        'forum/thread_list.html', {
            'forum': f,
            'threads': threads.object_list,
            'page_range': paginator.page_range,
            'page': page,
            'thread_form': thread_form
        }, request)
Beispiel #10
0
def edit(request, post_id):
    P = get_object_or_404(Post, id=post_id)
    t = P.thread
    if request.user != P.author:
        return HttpResponseRedirect(t.get_absolute_url())
    if request.method == 'POST':
        edit_form = EditForm(request.POST, instance=P)
        if edit_form.is_valid():
            edit_form.save()
            return HttpResponseRedirect(t.get_absolute_url())
    else:
        edit_form = EditForm(instance=P)
    return j2shim.r2r('forum/post_edit.html',{'edit_form' : edit_form, 'thread': t, 'forum': t.forum}, request)
Beispiel #11
0
def forum(request, slug):
    """
    Displays a list of threads within a forum.
    Threads are sorted by their sticky flag, followed by their
    most recent post.
    """
    f = get_object_or_404(Forum, slug=slug)

    # If the user is not authorized to view the thread, then redirect
    if f.is_private and request.user.is_staff != True:
         return HttpResponseRedirect('/forum')

    # Process new thread form if data was sent
    if request.method == 'POST':
        if not request.user.is_authenticated():
            return HttpResponseServerError()
        thread_form = ThreadForm(request.POST)
        if thread_form.is_valid():
            new_thread = thread_form.save(commit = False)
            new_thread.forum = f
            new_thread.save()
            Post.objects.create(thread=new_thread, author=request.user,
                body=thread_form.cleaned_data['body'],
                time=datetime.now())
            if (thread_form.cleaned_data['subscribe'] == True):
                Subscription.objects.create(author=request.user,
                    thread=new_thread)
            return HttpResponseRedirect(new_thread.get_absolute_url())
    else:
        thread_form = ThreadForm()

    # Pagination
    t = f.thread_set.all()
    paginator = Paginator(t, settings.FORUM_PAGINATE)
    try:
        page = int(request.GET.get('page', 1))
    except:
        page = 1
    try:
        threads = paginator.page(page)
    except (EmptyPage, InvalidPage):
        threads = paginator.page(paginator.num_pages)

    return j2shim.r2r('forum/thread_list.html',
        {
            'forum': f,
            'threads': threads.object_list,
            'page_range': paginator.page_range,
            'page': page,
            'thread_form': thread_form
        }, request)
Beispiel #12
0
def edit(request, post_id):
    P = get_object_or_404(Post, id=post_id)
    t = P.thread
    if request.user != P.author:
        return HttpResponseRedirect(t.get_absolute_url())
    if request.method == 'POST':
        edit_form = EditForm(request.POST, instance=P)
        if edit_form.is_valid():
            edit_form.save()
            return HttpResponseRedirect(t.get_absolute_url())
    else:
        edit_form = EditForm(instance=P)
    return j2shim.r2r('forum/post_edit.html', {
        'edit_form': edit_form,
        'thread': t,
        'forum': t.forum
    }, request)
Beispiel #13
0
def forum_list(request):
    """
    Modified to show Forum lists, but also the most recent posts from any
    Forums. Secret forums are hidden from public view.
    """
    forums = Forum.objects.filter(parent__isnull=True)

    # Add a filter is the user isn't staff (users normally can't see 'Secret' forums)
    if request.user.is_staff:
        posts = Post.objects.all().order_by('-time')[:NUM_LAST_FORUM_POSTS]
    else:
        posts = Post.objects.filter(thread__forum__is_private=False).order_by(
            '-time')[:NUM_LAST_FORUM_POSTS]

    return j2shim.r2r(
        'forum/forum_list.html', {
            'object_list': forums,
            'posts': posts,
            'preview_size': TRUNCATED_THREAD_SIZE,
        }, request)
Beispiel #14
0
def updatesubs(request):
    """
    Allow users to update their subscriptions all in one shot.
    """
    if not request.user.is_authenticated():
        return HttpResponseForbidden(_('Sorry, you need to login.'))

    subs = Subscription.objects.filter(author=request.user)

    if request.POST:
        # remove the subscriptions that haven't been checked.
        post_keys = [k for k in request.POST.keys()]
        for s in subs:
            if not str(s.thread.id) in post_keys:
                s.delete()
        return HttpResponseRedirect(reverse('forum_subscriptions'))

    return j2shim.r2r('forum/updatesubs.html', {
        'subs': subs,
    }, request)
Beispiel #15
0
def updatesubs(request):
    """
    Allow users to update their subscriptions all in one shot.
    """
    if not request.user.is_authenticated():
        return HttpResponseForbidden(_('Sorry, you need to login.'))

    subs = Subscription.objects.filter(author=request.user)

    if request.POST:
        # remove the subscriptions that haven't been checked.
        post_keys = [k for k in request.POST.keys()]
        for s in subs:
            if not str(s.thread.id) in post_keys:
                s.delete()
        return HttpResponseRedirect(reverse('forum_subscriptions'))

    return j2shim.r2r('forum/updatesubs.html',
        {
            'subs': subs,
        }, request)
Beispiel #16
0
 def deny_permission(self):
     return j2shim.r2r('base/error.html',
                       {'error': "Sorry, you're not allowed to see this"},
                       request=self.request)
Beispiel #17
0
 def deny_permission(self):
     return j2shim.r2r('base/error.html', { 'error' : "Sorry, you're not allowed to see this" }, request=self.request)
Beispiel #18
0
 def render_template(self, template, context, request):
     return j2shim.r2r(template, context, request, mimetype=self.content_type)
Beispiel #19
0
def thread(request, thread):
    """
    Increments the viewed count on a thread then displays the
    posts for that thread, in chronological order.
    """
    t = get_object_or_404(Thread, pk=thread)
    p = t.post_set.all().order_by('time')
    if request.user.is_authenticated():
        s = t.subscription_set.filter(author=request.user)
    else:
        s = False

    # If the user is not authorized to view, we redirect them
    if t.forum.is_private and request.user.is_staff != True:
        return HttpResponseRedirect('/forum')

    # Process reply form if it was sent
    if (request.method == 'POST'):
        if not request.user.is_authenticated() or t.closed:
            return HttpResponseServerError()
        reply_form = ReplyForm(request.POST)
        if reply_form.is_valid():
            new_post = reply_form.save(commit=False)
            new_post.author = request.user
            new_post.thread = t
            new_post.time = datetime.now()
            new_post.save()
            # Change subscription
            if reply_form.cleaned_data['subscribe']:
                Subscription.objects.get_or_create(thread=t,
                                                   author=request.user)
            else:
                Subscription.objects.filter(thread=t,
                                            author=request.user).delete()
            # Send email
            forum_email_notification(new_post)
            return HttpResponseRedirect(new_post.get_absolute_url())
    else:
        reply_form = ReplyForm(initial={'subscribe': s})

    # Pagination
    paginator = Paginator(p, settings.FORUM_PAGINATE)
    try:
        page = int(request.GET.get('page', paginator.num_pages))
    except:
        page = paginator.num_pages

    try:
        posts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        posts = paginator.page(paginator.num_pages)

    t.views += 1
    t.save()
    #{'object_list' : artistic.object_list, 'page_range' : paginator.page_range, 'page' : page, 'letter' : letter, 'al': alphalist}, \
    return j2shim.r2r(
        'forum/thread.html', {
            'forum': t.forum,
            'thread': t,
            'posts': posts.object_list,
            'page_range': paginator.page_range,
            'page': page,
            'reply_form': reply_form
        }, request)
Beispiel #20
0
def register(request, success_url=None,
             form_class=RegistrationFormNoFreeEmailFromSetting, profile_callback=None,
             template_name='registration/registration_form.html',
             extra_context=None):
    """
    Allow a new user to register an account.

    Following successful registration, issue a redirect; by default,
    this will be whatever URL corresponds to the named URL pattern
    ``registration_complete``, which will be
    ``/accounts/register/complete/`` if using the included URLConf. To
    change this, point that named pattern at another URL, or pass your
    preferred URL as the keyword argument ``success_url``.

    By default, ``registration.forms.RegistrationForm`` will be used
    as the registration form; to change this, pass a different form
    class as the ``form_class`` keyword argument. The form class you
    specify must have a method ``save`` which will create and return
    the new ``User``, and that method must accept the keyword argument
    ``profile_callback`` (see below).

    To enable creation of a site-specific user profile object for the
    new user, pass a function which will create the profile object as
    the keyword argument ``profile_callback``. See
    ``RegistrationManager.create_inactive_user`` in the file
    ``models.py`` for details on how to write this function.

    By default, use the template
    ``registration/registration_form.html``; to change this, pass the
    name of a template as the keyword argument ``template_name``.

    **Required arguments**

    None.

    **Optional arguments**

    ``form_class``
        The form class to use for registration.

    ``extra_context``
        A dictionary of variables to add to the template context. Any
        callable object in this dictionary will be called to produce
        the end result which appears in the context.

    ``profile_callback``
        A function which will be used to create a site-specific
        profile instance for the new ``User``.

    ``success_url``
        The URL to redirect to on successful registration.

    ``template_name``
        A custom template to use.

    **Context:**

    ``form``
        The registration form.

    Any extra variables supplied in the ``extra_context`` argument
    (see above).

    **Template:**

    registration/registration_form.html or ``template_name`` keyword
    argument.

    """
    if request.method == 'POST':
        userip = request.META["REMOTE_ADDR"]
        r = OnelinerMuted.objects.filter(ip_ban=userip, muted_to__gt=datetime.datetime.now())
        if r:
            d = {
                "reason": r[0].reason,
                "time": r[0].muted_to,
            }
            return j2shim.r2r('webview/muted.html', {'muted' : d}, request)
        form = form_class(data=request.POST, files=request.FILES)
        if form.is_valid():
            new_user = form.save(profile_callback=profile_callback)
            # success_url needs to be dynamically generated here; setting a
            # a default value using reverse() will cause circular-import
            # problems with the default URLConf for this application, which
            # imports this file.
            return HttpResponseRedirect(success_url or reverse('registration_complete'))
    else:
        form = form_class()

    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value
    return render_to_response(template_name,
                              { 'form': form },
                              context_instance=context)
Beispiel #21
0
def register(request, success_url=None,
             form_class=RegistrationFormNoFreeEmailFromSetting, profile_callback=None,
             template_name='registration/registration_form.html',
             extra_context=None):
    """
    Allow a new user to register an account.

    Following successful registration, issue a redirect; by default,
    this will be whatever URL corresponds to the named URL pattern
    ``registration_complete``, which will be
    ``/accounts/register/complete/`` if using the included URLConf. To
    change this, point that named pattern at another URL, or pass your
    preferred URL as the keyword argument ``success_url``.

    By default, ``registration.forms.RegistrationForm`` will be used
    as the registration form; to change this, pass a different form
    class as the ``form_class`` keyword argument. The form class you
    specify must have a method ``save`` which will create and return
    the new ``User``, and that method must accept the keyword argument
    ``profile_callback`` (see below).

    To enable creation of a site-specific user profile object for the
    new user, pass a function which will create the profile object as
    the keyword argument ``profile_callback``. See
    ``RegistrationManager.create_inactive_user`` in the file
    ``models.py`` for details on how to write this function.

    By default, use the template
    ``registration/registration_form.html``; to change this, pass the
    name of a template as the keyword argument ``template_name``.

    **Required arguments**

    None.

    **Optional arguments**

    ``form_class``
        The form class to use for registration.

    ``extra_context``
        A dictionary of variables to add to the template context. Any
        callable object in this dictionary will be called to produce
        the end result which appears in the context.

    ``profile_callback``
        A function which will be used to create a site-specific
        profile instance for the new ``User``.

    ``success_url``
        The URL to redirect to on successful registration.

    ``template_name``
        A custom template to use.

    **Context:**

    ``form``
        The registration form.

    Any extra variables supplied in the ``extra_context`` argument
    (see above).

    **Template:**

    registration/registration_form.html or ``template_name`` keyword
    argument.

    """
    if request.method == 'POST':
        userip = request.META["REMOTE_ADDR"]
        r = OnelinerMuted.objects.filter(ip_ban=userip, muted_to__gt=datetime.datetime.now())
        if r:
            d = {
                "reason": r[0].reason,
                "time": r[0].muted_to,
            }
            return j2shim.r2r('webview/muted.html', {'muted' : d}, request)
        form = form_class(data=request.POST, files=request.FILES)
        """
        cform = captcha.get_form(forms, request.POST)
        """
        if form.is_valid():
            new_user = form.save(profile_callback=profile_callback)
            return HttpResponseRedirect(success_url or reverse('registration_complete'))
        """if form.is_valid():
            if cform.is_valid():
                new_user = form.save(profile_callback=profile_callback)
                # success_url needs to be dynamically generated here; setting a
                # a default value using reverse() will cause circular-import
                # problems with the default URLConf for this application, which
                # imports this file.
                L.info("New user %s - gave captcha answer %s, IP %s", new_user.username, cform.cleaned_data["answer"], userip)
                return HttpResponseRedirect(success_url or reverse('registration_complete'))
            else:
                a = request.POST.get("answer")
                if a:
                    L.info("Captcha failed - answer was '%s'. IP %s", a, userip)
        """

    else:
        form = form_class()
        """
        cform = captcha.get_form(forms)
        """
    
    """
    cform.auto_set_captcha()
    L.info("Setting captcha %s", cform.fields['answer'].label)
    """

    if extra_context is None:
        extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value
    return render_to_response(template_name,
                              { 'form': form },
                              context_instance=context)
Beispiel #22
0
def thread(request, thread):
    """
    Increments the viewed count on a thread then displays the
    posts for that thread, in chronological order.
    """
    t = get_object_or_404(Thread, pk=thread)
    p = t.post_set.all().order_by('time')
    if request.user.is_authenticated():
        s = t.subscription_set.filter(author=request.user)
    else:
        s = False

    # If the user is not authorized to view, we redirect them
    if t.forum.is_private and request.user.is_staff != True:
         return HttpResponseRedirect('/forum')

    # Process reply form if it was sent
    if (request.method == 'POST'):
        if not request.user.is_authenticated() or t.closed:
            return HttpResponseServerError()

        r = check_muted(request)
        if r: return r

        reply_form = ReplyForm(request.POST)
        if reply_form.is_valid():
            new_post = reply_form.save(commit = False)
            new_post.author = request.user
            new_post.thread = t
            new_post.time=datetime.now()
            new_post.save()
            # Change subscription
            if reply_form.cleaned_data['subscribe']:
                Subscription.objects.get_or_create(thread=t,
                    author=request.user)
            else:
                Subscription.objects.filter(thread=t, author=request.user).delete()
            # Send email
            
            if new_post.is_visible(None):
                forum_email_notification(new_post)
                if NOTIFY_POST and not t.forum.is_private:
                    wm.send_notification("%s posted a reply to \"<a href='%s#post%s'>%s</a>\" in forum \"%s\"" % (
                        escape(request.user.username),
                        new_post.thread.get_absolute_url(),
                        new_post.id,
                        escape(new_post.thread.title),
                        escape(new_post.thread.forum.title),
                    ), None, 1)
            return HttpResponseRedirect(new_post.get_absolute_url())
    else:
        reply_form = ReplyForm(initial={'subscribe': s})

    # Pagination
    paginator = Paginator(p, settings.FORUM_PAGINATE)
    try:
        page = int(request.GET.get('page', paginator.num_pages))
    except:
        page = paginator.num_pages

    try:
        posts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        posts = paginator.page(paginator.num_pages)

    t.views += 1
    t.save()
    #{'object_list' : artistic.object_list, 'page_range' : paginator.page_range, 'page' : page, 'letter' : letter, 'al': alphalist}, \
    return j2shim.r2r('forum/thread.html',
            {
            'forum': t.forum,
            'thread': t,
            'posts': posts.object_list,
            'page_range': paginator.page_range,
            'page': page,
            'reply_form': reply_form
        }, request)
Beispiel #23
0
 def render_template(self, template, context, request):
     return j2shim.r2r(template,
                       context,
                       request,
                       mimetype=self.content_type)