Beispiel #1
0
def notify_user(user, instance, **kwargs):
    from curia.notifications.models import Notification, Watcher
    content_type = get_content_type(instance)
    
    from curia.authentication import has_perm    
    if has_perm(user, instance, 'view'):
        # handle negations on this specific object (this is redundant if this function was called for a specific notification on this object)
        if Watcher.objects.filter(user=user, content_type=content_type, object_id=instance.pk, inverse=True).count() != 0:
            return
    
        # handle negations on this content type for this user/group
        if Watcher.objects.filter(user=user, content_type=content_type, object_id__isnull=True, inverse=True).count() != 0:
            return
        
        owner_user = None
        owner_group = None
        if hasattr(instance, 'owner'):
            owner_user = instance.owner
        if hasattr(instance, 'owner_user'):
            owner_user = instance.owner_user
        if hasattr(instance, 'owner_group'):
            owner_group = instance.owner_group
            
        try:
            new_notification = Notification(user=user, object_id=instance.pk, content_type=content_type, title=unicode(instance), url=instance.get_absolute_url(), originator_user=get_current_user(), originator_group=get_current_community())
            new_notification.save()
            
            if user.notification_style == 'E': # notify on every event
                            send_notification_mail(user, new_notification)
        except:
            pass
Beispiel #2
0
    def render(self, context):
        try:
            parameters = resolve_parameters_from_context(self.parameters, context)
                
            obj = None
            if 'obj' in parameters:
                obj = parameters['obj']

            if obj is None:
                obj = context['user']

            if callable(obj):
                obj = obj()

            url = obj.get_absolute_url()

            command = 'view'
            if 'command' in parameters:
                command = parameters['command']

            css_command = command
            if css_command == 'edit':
                css_command = 'change'

            if 'title' in parameters:
                title = _(parameters['title'])
            elif command == 'view':
                title = _(capfirst(unicode(obj)))
            else:
                title = _(capfirst(command))

            if command != 'view':
                url += command+'/' 

            if 'add ' in command:
                foo = command.split(' ')
                if foo[1] == 'member':
                    url = '/groups/'+unicode(obj.id)+'/add_member/'
                elif foo[1] == 'friend':
                    url = '/users/'+unicode(obj.id)+'/add_friend/'
                else:    
                    url = '/'+foo[1]+'s/add/'
                    if isinstance(obj, Group):
                        url += '?group_id='+unicode(obj.id)
                    else:
                        url += '?user_id='+unicode(obj.id)
            from curia.authentication import has_perm
            
            perm = has_perm(user=context['user'], obj=obj, command=command)
            
            if perm:
                return self.has_permission(context, url, css_command, title, perm.motivation)
            else:
                return self.no_permission(context, url, css_command, title, perm.motivation)

        except TemplateSyntaxError:
            if settings.TEMPLATE_DEBUG:
                raise
            return ''
Beispiel #3
0
def search(request):
    tags_result = None
    users_result = None
    groups_result = None
    search_words = ''
    search_words = request.REQUEST['search']
    q = None
    q2 = None
    for word in map(lambda x: x.strip(), search_words.split(',')):
        if q == None:
            q = Q(name__iexact=word)
        else:
            q |= Q(name__iexact=word)

        if q2 == None:
            q2 = Q(username__iexact=word)
        else:
            q2 |= Q(username__iexact=word)

    users_result = User.objects.filter(q2)
    groups_result = Group.objects.filter(q)
    tags_result = Label.objects.filter(q)
    if len(tags_result) > 1:
        tags_result = [tags_result[0]]

    if len(users_result) == 1 and len(groups_result) == 0 and len(
            tags_result) == 0:
        has_access = has_perm(request.user, users_result[0], 'view')
        if has_access:
            return HttpResponseRedirect(users_result[0].get_absolute_url())

    if len(users_result) == 0 and len(groups_result) == 1 and len(
            tags_result) == 0:
        has_access = has_perm(request.user, groups_result[0], 'view')
        if has_access:
            return HttpResponseRedirect(groups_result[0].get_absolute_url())

    return render_to_response(
        request, 'search.html', {
            'search_words': search_words,
            'tags_result': tags_result,
            'users_result': users_result,
            'groups_result': groups_result
        })
Beispiel #4
0
def search(request):
    tags_result = None
    users_result = None
    groups_result = None
    search_words = ''
    search_words = request.REQUEST['search']
    q = None
    q2 = None
    for word in map(lambda x: x.strip(), search_words.split(',')):
        if q == None:
            q = Q(name__iexact=word)
        else:
            q |= Q(name__iexact=word)

        if q2 == None:
            q2 = Q(username__iexact=word)
        else:
            q2 |= Q(username__iexact=word)

    users_result = User.objects.filter(q2)
    groups_result = Group.objects.filter(q)
    tags_result = Label.objects.filter(q)
    if len(tags_result) > 1:
        tags_result = [tags_result[0]]
    
    if len(users_result) == 1 and len(groups_result) == 0 and len(tags_result) == 0:
        has_access = has_perm(request.user, users_result[0], 'view')
        if has_access:    
            return HttpResponseRedirect(users_result[0].get_absolute_url())
    
    if len(users_result) == 0 and len(groups_result) == 1 and len(tags_result) == 0:
        has_access = has_perm(request.user, groups_result[0], 'view')
        if has_access:
            return HttpResponseRedirect(groups_result[0].get_absolute_url())

    return render_to_response(request, 'search.html', {'search_words': search_words, 'tags_result': tags_result, 'users_result':users_result, 'groups_result':groups_result})
Beispiel #5
0
    def render(self, context):
        try:
            parameters = resolve_parameters_from_context(
                self.parameters, context)

            obj = None
            if 'obj' in parameters:
                obj = parameters['obj']

            if obj is None:
                obj = context['user']

            if callable(obj):
                obj = obj()

            url = obj.get_absolute_url()

            command = 'view'
            if 'command' in parameters:
                command = parameters['command']

            css_command = command
            if css_command == 'edit':
                css_command = 'change'

            if 'title' in parameters:
                title = _(parameters['title'])
            elif command == 'view':
                title = _(capfirst(unicode(obj)))
            else:
                title = _(capfirst(command))

            if command != 'view':
                url += command + '/'

            if 'add ' in command:
                foo = command.split(' ')
                if foo[1] == 'member':
                    url = '/groups/' + unicode(obj.id) + '/add_member/'
                elif foo[1] == 'friend':
                    url = '/users/' + unicode(obj.id) + '/add_friend/'
                else:
                    url = '/' + foo[1] + 's/add/'
                    if isinstance(obj, Group):
                        url += '?group_id=' + unicode(obj.id)
                    else:
                        url += '?user_id=' + unicode(obj.id)
            from curia.authentication import has_perm

            perm = has_perm(user=context['user'], obj=obj, command=command)

            if perm:
                return self.has_permission(context, url, css_command, title,
                                           perm.motivation)
            else:
                return self.no_permission(context, url, css_command, title,
                                          perm.motivation)

        except TemplateSyntaxError:
            if settings.TEMPLATE_DEBUG:
                raise
            return ''