Exemple #1
0
def view_inbox(request):
    objects = paginate(request,
                       request.user.messages.incoming,
                       request.user.messages.incoming.count(),
                       10)
    return direct_to_template(request, 'user_messages/inbox.html',
                              { 'objects': objects })
Exemple #2
0
def view_sent(request):
    objects = paginate(request,
                       request.user.messages.sent,
                       request.user.messages.sent.count(),
                       10)
    return direct_to_template(request, 'user_messages/sent.html',
                              { 'objects': objects })
Exemple #3
0
def group_view(request, id):
    group = get_document_or_404(Group, id=id)
    is_active = group.is_active(request.user)

    is_ajax = request.is_ajax()

    if request.POST:
        if not is_active:
            if is_ajax:
                return HttpResponse('')
            else:
                messages.add_message(request, messages.ERROR,
                                 _('To send a message, you need to join the group.'))
                return redirect(reverse('groups:group_view', args=[id]))
        form = MessageTextForm(request.POST)
        if form.is_valid():
            message = GroupMessage(
                group=group,
                sender=request.user,
                text=form.cleaned_data['text'],
            )
            message.save()
            if not is_ajax:
                return redirect(reverse('groups:group_view', args=[id]))
        elif is_ajax:
            return HttpResponse('')
    elif not is_ajax:
        form = MessageTextForm()

    objects = paginate(request,
                       GroupMessage.objects(group=group),
                       GroupMessage.objects(group=group).count(),
                       settings.MESSAGES_ON_PAGE)

    if is_ajax:
        return direct_to_template(request, 'groups/_comments.html', dict(
            group=group,
            is_admin=group.is_admin(request.user) or request.user.is_superuser,
            objects=objects,
        ))
    else:
        admins = []
        members = []
        for info in GroupUser.objects(group=group, status=GroupUser.STATUS.ACTIVE):
            if info.is_admin:
                admins.append(info.user)
            else:
                members.append(info.user)
        return direct_to_template(request, 'groups/view.html', dict(
            group=group,
            admins=admins,
            members=members,
            is_admin=group.is_admin(request.user) or request.user.is_superuser,
            can_view_private=group.public or is_active or request.user.is_superuser,
            can_view_conference=is_active or request.user.is_superuser,
            can_send_message=is_active,
            is_status_request=group.is_request(request.user),
            objects=objects,
            form=form,
        ))
Exemple #4
0
def view_message_by_user(request, user_id, action=''):
    by_user = get_document_or_404(User, id=user_id)
    owner  = request.user
    template = 'by_user.html'
    
    if action == 'sent':
        messages = Message.objects(sender=owner,
                               recipient=by_user,
                               sender_delete=None)
        template = 'by_user_sent.html'

    elif action == 'inbox':
        messages = Message.objects(recipient=request.user,
                               sender=by_user,
                               recipient_delete=None)
        template = 'by_user_inbox.html'

    else:
        messages = Message.objects(
                            Q(sender=owner, recipient=by_user, sender_delete=None) |
                            Q(sender=by_user, recipient=owner, recipient_delete=None),
                               )
    objects = paginate(request,
                       messages,
                       messages.count(),
                       10)
    return direct_to_template(request, 'user_messages/%s' % template,
                              { 'objects': objects,
                                'by_user': by_user,
                                'action': action,
                                })
Exemple #5
0
def log_list(request):
    filter_data = {}

    logger = request.GET.get('logger', '')

    if logger:
        filter_data['logger_name'] = logger

    message = request.GET.get('message', '')

    if message:
        filter_data['message__icontains'] = message

    level = request.GET.get('level', '')

    if level:
        filter_data['levelname'] = level.upper()

    if filter_data:
        query_list = LogEntry.objects.filter(**filter_data).order_by('-date')
    else:
        query_list = LogEntry.objects.order_by('-date')

    query_count = len(query_list)
    objects = paginate(request, query_list, query_count, settings.LOGS_PER_PAGE)

    return direct_to_template(request, 'logging/log_list.html',
                              {
                               'objects': objects,
                               'loggers': LogEntry.objects.distinct('logger_name'),
                               'current_logger': logger,
                               'levels': ['info', 'debug', 'warning', 'error', 'critical'],
                               'current_level': level,
                               'current_message': message,
                              })
Exemple #6
0
def list(request):
    form = AdsFilterForm(request.GET or None)
    if form.is_valid():
        filter_data = {}
        fields = [
            'country',
            'city',
            'section',
            'category',
            'currency',
            'has_photo',
        ]
        for field in fields:
            if form.cleaned_data[field]:
                filter_data[field] = form.cleaned_data[field]

        if form.cleaned_data['price_from']:
            filter_data['price__gte'] = form.cleaned_data['price_from']

        if form.cleaned_data['price_to']:
            filter_data['price__lte'] = form.cleaned_data['price_to']
        ads = Ad.objects.filter(**filter_data)
    else:
        ads = Ad.objects.all()

    objects = paginate(request, ads, ads.count(), 12)

    return direct_to_template(request, 'ads/list.html',
                              dict(
                                      objects=objects,
                                      form=form,
                                  )
                              )
Exemple #7
0
def cam_list(request):
    private_tags = ",".join(["'%s'" % i.id for i in CameraTag.objects(is_private=True)])
    if request.GET:
        form = CamFilterForm(request.GET)
        if form.is_valid():
            data = dict(form.cleaned_data)
            if data['name']:
                data['name__icontains'] = data['name']
            del data['name']
            if data['tags']:
                data['tags'] = CameraTag.objects(id=data['tags']).first()
            else:
                private_tags = [i.id for i in CameraTag.objects(is_private=True)]
                data.update(dict(tags__not__in=private_tags))
                del data['tags']
            if data['order']:
                order = data['order']
            else:
                order = 'popularity-desc'
            del data['order']
            if not data['is_managed']:
                del data['is_management_enabled']
                del data['is_management_public']
                del data['is_management_paid']
            for k, v in data.items():
                if not v: del data[k]
            cams = Camera.objects(**data)
            if order:
                try:
                    name, type = order.split('-')
                except ValueError:
                    name, type = 'popularity', 'desc'
                order = ''
                if name == 'time':
                    order = 'date_created'
                    if type == 'desc':
                        order = '-%s' % order
                if name == 'popularity':
                    order = 'view_count'
                    if type == 'desc':
                        order = '-%s' % order
                cams = cams.order_by(order)
            cams = paginate(request,
                            cams,
                            cams.count(),
                            12)
        else:
            cams = None
        if request.is_ajax():
            return direct_to_template(request, 'cam/_cameras.html', dict(cams=cams))
        else:
            return direct_to_template(request, 'cam/cam_list.html', dict(form=form,cams=cams,private_tags=private_tags))
    else:
        form = CamFilterForm()
        tags = []
        for tag in CameraTag.objects.order_by('-count')[:4]:
            cams = list(Camera.objects(tags=tag.id).order_by('-view_count')[:4])
            tags.append((tag, cams))
        return direct_to_template(request, 'cam/cam_list.html', dict(form=form,tags=tags,private_tags=private_tags) )
Exemple #8
0
def user_list(request):
    users = User.objects.order_by('-date_joined')
    users.snapshot(True)
    objects = paginate(request,
                       users,
                       users.count(),
                       25)
    return direct_to_template(request, 'admin/user_list.html', {'objects': objects})
Exemple #9
0
 def process_request(self, request):
     params = dict(
         is_view_public=True,
         is_view_enabled=True,
     )
     private_tags = [i.id for i in CameraTag.objects(is_private=True)]
     params.update(dict(tags__not__in=private_tags))
     request.places = paginate(
         request,
         Camera.objects(**params).order_by('-view_count'),
         Camera.objects(**params).count(), 10,
         reverse('cam:place_update', args=['time', 'asc']))
     request.places_all_count = Camera.objects.count()
Exemple #10
0
 def process_request(self, request):
     params = dict(
         is_view_public=True,
         is_view_enabled=True,
     )
     private_tags = [i.id for i in CameraTag.objects(is_private=True)]
     params.update(dict(tags__not__in=private_tags))
     request.places = paginate(request,
                               Camera.objects(**params).order_by('-view_count'),
                               Camera.objects(**params).count(),
                               10,
                               reverse('cam:place_update', args=['time', 'asc']))
     request.places_all_count = Camera.objects.count()
Exemple #11
0
def delete_message(request, group, message_id):
    get_document_or_404(GroupMessage, id=message_id).delete()
    if request.is_ajax():
        objects = paginate(request,
                           GroupMessage.objects(group=group),
                           GroupMessage.objects(group=group).count(),
                           settings.MESSAGES_ON_PAGE)
        return direct_to_template(request, 'groups/_comments.html', dict(
            group=group,
            is_admin=group.is_admin(request.user) or request.user.is_superuser,
            objects=objects,
        ))
    else:
        return redirect(reverse('groups:group_view', args=[group.id]))
Exemple #12
0
def list(request):
    can_manage = request.user.has_perm('themes')
    if can_manage:
        objects = Theme.objects()
    else:
        objects = Theme.objects(is_public=True)

    objects = paginate(request, objects, objects.count(), 25)

    form = ThemeAddForm()

    return direct_to_template(
        request, 'themes/list.html',
        dict(objects=objects, form=form, can_manage=can_manage))
Exemple #13
0
def delete_message(request, group, message_id):
    get_document_or_404(GroupMessage, id=message_id).delete()
    if request.is_ajax():
        objects = paginate(request, GroupMessage.objects(group=group),
                           GroupMessage.objects(group=group).count(),
                           settings.MESSAGES_ON_PAGE)
        return direct_to_template(
            request, 'groups/_comments.html',
            dict(
                group=group,
                is_admin=group.is_admin(request.user)
                or request.user.is_superuser,
                objects=objects,
            ))
    else:
        return redirect(reverse('groups:group_view', args=[group.id]))
Exemple #14
0
def member_list(request, id):
    group = get_document_or_404(Group, id=id)
    can_view = group.public or group.is_active(request.user) or request.user.is_superuser
    if not can_view:
        messages.add_message(request, messages.ERROR, _('You are not allowed.'))
        return redirect(reverse('groups:group_view', args=[id]))

    objects = paginate(request,
                       GroupUser.objects(group=group, status=GroupUser.STATUS.ACTIVE),
                       GroupUser.objects(group=group, status=GroupUser.STATUS.ACTIVE).count(),
                       settings.GROUP_USERS_ON_PAGE)
    return direct_to_template(request,
                              'groups/member_list.html',
                              dict(group=group,
                                   objects=objects),
                              )
Exemple #15
0
def video_index(request):
    library = get_library(LIBRARY_TYPE_VIDEO)
    if can_manage_library(request.user):
        form = VideoAddForm()
    else:
        form = None

    objects = paginate(request, library.files, len(library.files),
                       settings.LIBRARY_VIDEO_PER_PAGE)

    return direct_to_template(
        request, 'media_library/video_index.html',
        dict(
            objects=objects,
            form=form,
            can_manage=can_manage_library(request.user),
        ))
Exemple #16
0
def video_index(request):
    library = get_library(LIBRARY_TYPE_VIDEO)
    if can_manage_library(request.user):
        form = VideoAddForm()
    else:
        form = None

    objects = paginate(request,
                       library.files,
                       len(library.files),
                       settings.LIBRARY_VIDEO_PER_PAGE
                       )

    return direct_to_template(request, 'media_library/video_index.html',
                              dict(objects=objects,form=form,
                                      can_manage=can_manage_library(request.user),
                                   ))
Exemple #17
0
def list(request):
    form = ApplicationForm()
    items = Application.objects()
    form = ApplicationForm()
    objects = paginate(request,
                       items,
                       len(items),
                       settings.APPLICATIONS_PER_PAGE
                       )

    return direct_to_template(request, 'applications/list.html',
                              dict(
                                      objects=objects,
                                      can_manage=can_manage_applications(request.user),
                                      form=form,
                                   )

                              )
Exemple #18
0
def list(request):
    can_manage = request.user.has_perm('themes')
    if can_manage:
        objects = Theme.objects()
    else:
        objects = Theme.objects(is_public=True)

    objects = paginate(request, objects, objects.count(), 25)

    form = ThemeAddForm()

    return direct_to_template(request,
                              'themes/list.html',
                              dict(objects=objects,
                                   form=form,
                                   can_manage=can_manage
                                   )
                              )
Exemple #19
0
def member_list(request, id):
    group = get_document_or_404(Group, id=id)
    can_view = group.public or group.is_active(
        request.user) or request.user.is_superuser
    if not can_view:
        messages.add_message(request, messages.ERROR,
                             _('You are not allowed.'))
        return redirect(reverse('groups:group_view', args=[id]))

    objects = paginate(
        request, GroupUser.objects(group=group,
                                   status=GroupUser.STATUS.ACTIVE),
        GroupUser.objects(group=group, status=GroupUser.STATUS.ACTIVE).count(),
        settings.GROUP_USERS_ON_PAGE)
    return direct_to_template(
        request,
        'groups/member_list.html',
        dict(group=group, objects=objects),
    )
Exemple #20
0
def note_view(request, note_id):
    notes = Note.objects(id=note_id, author=request.user)[:] or \
        Note.objects(id=note_id, is_public=True)[:]
    if not notes:
        return HttpResponseNotFound()
    note = notes[0]

    form = CommentTextForm(request.POST or None)
    if form.is_valid():
        text = form.data['text']
        Comment(sender=request.user, note=note, text=text).save()
        system_messages.add_message(request, system_messages.SUCCESS, _('Comment sent'))

    objects = paginate(request,
                       note.comments(user=request.user),
                       note.comments().count(),
                       10)
    return direct_to_template(request, 'notes/note_view.html',
                              { 'note': note,
                                'objects': objects,
                                'msgform': form })
Exemple #21
0
def place_update(request, name, type):
    order = ''
    if name == 'time':
        order = 'date_created'
        if type == 'desc':
            order = '-%s' % order
    if name == 'popularity':
        order = 'view_count'
        if type == 'desc':
            order = '-%s' % order
    #request.places_all_count = Camera.objects.count()
    params = dict(
        is_view_public=True,
        is_view_enabled=True,
    )
    private_tags = [i.id for i in CameraTag.objects(is_private=True)]
    params.update(dict(tags__not__in=private_tags))
    request.places = paginate(request,
                              Camera.objects(**params).order_by(order),
                              Camera.objects(**params).count(),
                              10,
                              reverse('cam:place_update', args=[name, type]))
    return direct_to_template(request, '_places.html')
Exemple #22
0
def log_list(request):
    filter_data = {}

    logger = request.GET.get('logger', '')

    if logger:
        filter_data['logger_name'] = logger

    message = request.GET.get('message', '')

    if message:
        filter_data['message__icontains'] = message

    level = request.GET.get('level', '')

    if level:
        filter_data['levelname'] = level.upper()

    if filter_data:
        query_list = LogEntry.objects.filter(**filter_data).order_by('-date')
    else:
        query_list = LogEntry.objects.order_by('-date')

    query_count = len(query_list)
    objects = paginate(request, query_list, query_count,
                       settings.LOGS_PER_PAGE)

    return direct_to_template(
        request, 'logging/log_list.html', {
            'objects': objects,
            'loggers': LogEntry.objects.distinct('logger_name'),
            'current_logger': logger,
            'levels': ['info', 'debug', 'warning', 'error', 'critical'],
            'current_level': level,
            'current_message': message,
        })
Exemple #23
0
def group_list(request):
    objects = paginate(request, Group.objects.order_by('-count_members'),
                       Group.objects.count(), 24)
    return direct_to_template(request, 'groups/list.html',
                              dict(objects=objects))
Exemple #24
0
def index(request):
    if not request.user.is_authenticated():
        return _index_unreg(request)

    params = dict(request.GET.items())
    if 'page' in params:
        del params['page']

    form = PeopleFilterForm(params or None)

    if params and form.is_valid():
        filter_user_data = {}
        filter_profile_data = {}

        data = dict(form.cleaned_data)

        filter_user_data['is_active'] = True

        if data['first_name']:
            filter_user_data['first_name__icontains'] = data['first_name']

        if data['last_name']:
            filter_user_data['last_name__icontains'] = data['last_name']

        if data['gender']:
            filter_profile_data['sex'] = data['gender']

        if data['has_photo']:
            filter_user_data['avatar__exists'] = True

        if data['is_online']:
            filter_user_data.update({'last_access__gt': User.get_delta_time()})

        if filter_profile_data:
            profiles = Profile.objects.filter(
                **filter_profile_data).only('user')
            if filter_user_data:
                user_ids = [profile.user.id for profile in profiles]
                filter_user_data['id__in'] = user_ids
                users = User.objects.filter(**filter_user_data)
            else:
                users = [profile.user for profile in profiles]

        else:
            users = User.objects.filter(**filter_user_data)

        users_count = len(users)

    else:
        users = User.objects(last_access__gt=User.get_delta_time(),
                             is_active=True)
        users_count = User.objects(last_access__gt=User.get_delta_time(),
                                   is_active=True).count()

    objects = paginate(request, users, users_count, 24)

    if request.is_ajax():
        return direct_to_template(request, '_user_list.html', {
            'objects': objects,
        })
    else:
        return direct_to_template(request, 'index.html', {
            'objects': objects,
            'form': form
        })
Exemple #25
0
def group_view(request, id):
    group = get_document_or_404(Group, id=id)
    is_active = group.is_active(request.user)

    is_ajax = request.is_ajax()

    if request.POST:
        if not is_active:
            if is_ajax:
                return HttpResponse('')
            else:
                messages.add_message(
                    request, messages.ERROR,
                    _('To send a message, you need to join the group.'))
                return redirect(reverse('groups:group_view', args=[id]))
        form = MessageTextForm(request.POST)
        if form.is_valid():
            message = GroupMessage(
                group=group,
                sender=request.user,
                text=form.cleaned_data['text'],
            )
            message.save()
            if not is_ajax:
                return redirect(reverse('groups:group_view', args=[id]))
        elif is_ajax:
            return HttpResponse('')
    elif not is_ajax:
        form = MessageTextForm()

    objects = paginate(request, GroupMessage.objects(group=group),
                       GroupMessage.objects(group=group).count(),
                       settings.MESSAGES_ON_PAGE)

    if is_ajax:
        return direct_to_template(
            request, 'groups/_comments.html',
            dict(
                group=group,
                is_admin=group.is_admin(request.user)
                or request.user.is_superuser,
                objects=objects,
            ))
    else:
        admins = []
        members = []
        for info in GroupUser.objects(group=group,
                                      status=GroupUser.STATUS.ACTIVE):
            if info.is_admin:
                admins.append(info.user)
            else:
                members.append(info.user)
        return direct_to_template(
            request, 'groups/view.html',
            dict(
                group=group,
                admins=admins,
                members=members,
                is_admin=group.is_admin(request.user)
                or request.user.is_superuser,
                can_view_private=group.public or is_active
                or request.user.is_superuser,
                can_view_conference=is_active or request.user.is_superuser,
                can_send_message=is_active,
                is_status_request=group.is_request(request.user),
                objects=objects,
                form=form,
            ))
Exemple #26
0
def order_list(request):
    objects = paginate(request, UserOrder.objects.order_by('-timestamp'),
                       UserOrder.objects.count(), 25)
    return direct_to_template(request, 'billing/order_list.html',
                              {'objects': objects})
Exemple #27
0
def access_order_list(request):
    objects = paginate(request,
                       AccessCamOrder.objects.order_by('-create_on'),
                       AccessCamOrder.objects.count(),
                       25)
    return direct_to_template(request, 'billing/access_order_list.html', { 'objects': objects })
Exemple #28
0
def order_list(request):
    objects = paginate(request,
                       UserOrder.objects.order_by('-timestamp'),
                       UserOrder.objects.count(),
                       25)
    return direct_to_template(request, 'billing/order_list.html', { 'objects': objects })
Exemple #29
0
def access_order_list(request):
    objects = paginate(request, AccessCamOrder.objects.order_by('-create_on'),
                       AccessCamOrder.objects.count(), 25)
    return direct_to_template(request, 'billing/access_order_list.html',
                              {'objects': objects})
Exemple #30
0
def view_inbox(request):
    objects = paginate(request, request.user.messages.incoming,
                       request.user.messages.incoming.count(), 10)
    return direct_to_template(request, 'user_messages/inbox.html',
                              {'objects': objects})
Exemple #31
0
def view_sent(request):
    objects = paginate(request, request.user.messages.sent,
                       request.user.messages.sent.count(), 10)
    return direct_to_template(request, 'user_messages/sent.html',
                              {'objects': objects})
Exemple #32
0
def index(request):
    if not request.user.is_authenticated():
        return _index_unreg(request)

    params = dict(request.GET.items())
    if "kino" in params and params["kino"]:
        params["kino"] = request.GET.getlist("kino")

    if "page" in params:
        del params["page"]

    form = PeopleFilterForm(params or None)

    if params and form.is_valid():
        filter_user_data = {}
        filter_profile_data = {}

        data = dict(form.cleaned_data)

        filter_user_data["is_active"] = True

        if data["first_name"]:
            filter_user_data["first_name__icontains"] = data["first_name"]

        if data["last_name"]:
            filter_user_data["last_name__icontains"] = data["last_name"]

        if data["gender"]:
            filter_profile_data["sex"] = data["gender"]

        if data["is_dating"]:
            filter_profile_data["is_dating"] = True
            if data["age_from"]:
                filter_profile_data["age__gte"] = data["age_from"]

            if data["age_to"]:
                filter_profile_data["age__lte"] = data["age_to"]

            if data["interests"]:
                filter_profile_data["interests__icontains"] = data["interests"]

            if data["kino"]:
                filter_profile_data["kino__in"] = data["kino"]

        if data["has_photo"]:
            filter_user_data["avatar__exists"] = True

        if data["is_online"]:
            filter_user_data.update({"last_access__gt": User.get_delta_time()})

        if filter_profile_data:
            profiles = Profile.objects.filter(**filter_profile_data).only("user")
            if filter_user_data:
                user_ids = [profile.user.id for profile in profiles]
                filter_user_data["id__in"] = user_ids
                users = User.objects.filter(**filter_user_data)
            else:
                users = [profile.user for profile in profiles]

        else:
            users = User.objects.filter(**filter_user_data)

        users_count = len(users)

    else:
        users = User.objects(last_access__gt=User.get_delta_time(), is_active=True)
        users_count = User.objects(last_access__gt=User.get_delta_time(), is_active=True).count()

    objects = paginate(request, users, users_count, 24)

    if request.is_ajax():
        return direct_to_template(request, "_user_list.html", {"objects": objects})
    else:
        return direct_to_template(request, "index.html", {"objects": objects, "form": form})
Exemple #33
0
def index(request):
    if not request.user.is_authenticated():
        return _index_unreg(request)

    params = dict(request.GET.items())
    if 'page' in params:
        del params['page']

    form = PeopleFilterForm(params or None)

    if params and form.is_valid():
        filter_user_data = {}
        filter_profile_data = {}

        data = dict(form.cleaned_data)

        filter_user_data['is_active'] = True

        if data['first_name']:
            filter_user_data['first_name__icontains'] = data['first_name']

        if data['last_name']:
            filter_user_data['last_name__icontains'] = data['last_name']

        if data['gender']:
            filter_profile_data['sex'] = data['gender']

        if data['has_photo']:
            filter_user_data['avatar__exists'] = True

        if data['is_online']:
            filter_user_data.update(
            {'last_access__gt': User.get_delta_time()
            })

        if filter_profile_data:
            profiles = Profile.objects.filter(**filter_profile_data).only('user')
            if filter_user_data:
                user_ids = [profile.user.id for profile in profiles]
                filter_user_data['id__in'] = user_ids
                users = User.objects.filter(**filter_user_data)
            else:
                users = [profile.user for profile in profiles]

        else:
            users = User.objects.filter(**filter_user_data)

        users_count = len(users)
    
    else:
        users = User.objects(last_access__gt=User.get_delta_time(), is_active=True)
        users_count = User.objects(last_access__gt=User.get_delta_time(), is_active=True).count()

    objects = paginate(request,
                       users,
                       users_count,
                       24)

    if request.is_ajax():
        return direct_to_template(request, '_user_list.html', {
            'objects': objects,
        })
    else:
        return direct_to_template(request, 'index.html', {
            'objects': objects,
            'form': form
        })
Exemple #34
0
def group_list(request):
    objects = paginate(request,
                       Group.objects.order_by('-count_members'),
                       Group.objects.count(),
                       24)
    return direct_to_template(request, 'groups/list.html', dict(objects=objects))
Exemple #35
0
def user_list(request):
    objects = paginate(request,
                       User.objects.order_by('-date_joined'),
                       User.objects.count(),
                       25)
    return direct_to_template(request, 'admin/user_list.html', {'objects': objects})