Esempio n. 1
0
def message_detail(request, username, page=1, paginate_by=10,
                   template_name="umessages/message_detail.html",
                   extra_context=None, **kwargs):
    """
    Returns a conversation between two users

    :param username:
        String containing the username of :class:`User` of whom the
        conversation is with.

    :param page:
        Integer of the active page used for pagination. Defaults to the first
        page.

    :param paginate_by:
        Integer defining the amount of displayed messages per page.
        Defaults to 50 messages per per page.

    :param extra_context:
        Dictionary of variables that will be made available to the template.

    :param template_name:
        String of the template that is rendered to display this view.

    If the result is paginated, the context will also contain the following
    variables.

    ``paginator``
        An instance of ``django.core.paginator.Paginator``.

    ``page_obj``
        An instance of ``django.core.paginator.Page``.

    """
    recipient = get_object_or_404(User,
                                  username__iexact=username)
    queryset = Message.objects.get_conversation_between(request.user,
                                                        recipient)

    # Update all the messages that are unread.
    message_pks = [m.pk for m in queryset]
    unread_list = MessageRecipient.objects.filter(message__in=message_pks,
                                                  user=request.user,
                                                  read_at__isnull=True)
    now = timezone.now()
    unread_list.update(read_at=now)

    if not extra_context: extra_context = dict()
    extra_context['recipient'] = recipient
    return ProfileListView.as_view(queryset=queryset,
                                   paginate_by=paginate_by,
                                   page=page,
                                   template_name=template_name,
                                   extra_context=extra_context,
                                   context_object_name="message",
                                   **kwargs)(request)
Esempio n. 2
0
def message_list(request, page=1, paginate_by=50,
                 template_name="umessages/message_list.html",
                 extra_context=None, **kwargs):
    """

    Returns the message list for this user. This is a list contacts
    which at the top has the user that the last conversation was with. This is
    an imitation of the iPhone SMS functionality.

    :param page:
        Integer of the active page used for pagination. Defaults to the first
        page.

    :param paginate_by:
        Integer defining the amount of displayed messages per page.
        Defaults to 50 messages per per page.

    :param template_name:
        String of the template that is rendered to display this view.

    :param extra_context:
        Dictionary of variables that will be made available to the template.

    If the result is paginated, the context will also contain the following
    variables.

    ``paginator``
        An instance of ``django.core.paginator.Paginator``.

    ``page_obj``
        An instance of ``django.core.paginator.Page``.

    """
    queryset = MessageContact.objects.get_contacts_for(request.user)

    if not extra_context: extra_context = dict()
    return ProfileListView.as_view(queryset=queryset,
                                   paginate_by=paginate_by,
                                   page=page,
                                   template_name=template_name,
                                   extra_context=extra_context,
                                   context_object_name="message",
                                   **kwargs)(request)
Esempio n. 3
0
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import TemplateView

from userena.views import ProfileListView

from trip.views import SkaterTripListView, TripListView, TripDetailView, TripCreateView, TripUpdateView
from ldp.views import skater_activities

admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    url(r'^$', 'ldp.views.home', name='home'),
    url('^activity/', include('actstream.urls')),
    url(r'^about/', TemplateView.as_view(template_name="about.html"), name='about'),
    url(r'^impressum/', TemplateView.as_view(template_name="impressum.html"), name='impressum'),
    url(r'^trips/?$', TripListView.as_view() , name='trip_list'),
    url(r'^trip/(?P<pk>\d+)/?$', TripDetailView.as_view() , name='trip_detail'),
    url(r'^trip/new/?$', TripCreateView.as_view() , name='trip_create'),
    url(r'^trip/edit/(?P<pk>\d+)/?$', TripUpdateView.as_view() , name='trip_edit'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^(?P<username>(?!signout|signup|signin)[\.\w-]+)/activities/$', skater_activities, name='skater_activities'),
    url(r'^(?P<username>(?!signout|signup|signin)[\.\w-]+)/trips/$', SkaterTripListView.as_view() , name='skater_trip_list'),
    url(r'^skater/', ProfileListView.as_view(), name='ldp3_profile_list'),
    url(r'^a/', include(admin.site.urls)),
    url(r'^', include('userena.urls')),
)