Esempio n. 1
0
File: views.py Progetto: boxed/curia
def navigation_ajax(request, template='navigation_core.html'):
    try:
        if 'current_url' in request.REQUEST:
            current_url = request.REQUEST['current_url']
        else:
            current_url = None

        notifications = []
        event_invites = []
        group_invites = []
        bookmarks = []
        subscription_entries = []
        communities = []
        unread_other_communities = False

        if request.user.is_authenticated():
            notifications = Notification.objects.filter(user=request.user, originator_group=request.community)
            event_invites = Reply.objects.filter(choice='-', user=request.user) 
            group_invites = Invite.objects.filter(choice='-', user=request.user)
            bookmarks = Bookmark.objects.filter(user=request.user)
            communities = request.user.groups.exclude(name='everyone')
        
            for community in communities:
                community.number_of_notifications = Notification.objects.filter(user=request.user, originator_group=community).count()
                community.number_of_new_objects = SubscriptionResult.objects.filter(user=request.user, originator_group=community).count()
            
                if (community.number_of_new_objects != 0 or community.number_of_notifications != 0) and community != request.community:
                    unread_other_communities = True
        
            from curia.notifications import get_subscription_entries
            subscription_entries = get_subscription_entries(request.user, request.community)
        
        from django.template import loader, Context
        from django.utils.simplejson import dumps
        from django.template import RequestContext

        c = RequestContext(request)
        c.update({
            'current_url_is_bookmarked':current_url in [x.url for x in bookmarks],
            'notifications':notifications,
            'event_invites':event_invites, 
            'group_invites':group_invites, 
            'bookmarks':bookmarks,
            'subscription_entries':subscription_entries,    
            'communities':communities,
            'unread_other_communities':unread_other_communities,
            })
    
        button = ''
        if len(communities) > 1:
            button = loader.get_template('community_selector_button.html').render(c)
        
        return HttpResponse(dumps([
            loader.get_template('community_selector.html').render(c), 
            button, 
            loader.get_template(template).render(c),
            ], ensure_ascii=False), mimetype="text/json; charset=UTF-8")
        # return render_to_response(request, template, {
        #     'current_url_is_bookmarked':current_url in [x.url for x in bookmarks],
        #     'notifications':notifications,
        #     'event_invites':event_invites, 
        #     'group_invites':group_invites, 
        #     'bookmarks':bookmarks,
        #     'subscription_entries':subscription_entries,    
        # })
    except IOError:
        pass
Esempio n. 2
0
File: views.py Progetto: boxed/curia
def navigation_ajax(request, template='navigation_core.html'):
    try:
        if 'current_url' in request.REQUEST:
            current_url = request.REQUEST['current_url']
        else:
            current_url = None

        notifications = []
        event_invites = []
        group_invites = []
        bookmarks = []
        subscription_entries = []
        communities = []
        unread_other_communities = False

        if request.user.is_authenticated():
            notifications = Notification.objects.filter(
                user=request.user, originator_group=request.community)
            event_invites = Reply.objects.filter(choice='-', user=request.user)
            group_invites = Invite.objects.filter(choice='-',
                                                  user=request.user)
            bookmarks = Bookmark.objects.filter(user=request.user)
            communities = request.user.groups.exclude(name='everyone')

            for community in communities:
                community.number_of_notifications = Notification.objects.filter(
                    user=request.user, originator_group=community).count()
                community.number_of_new_objects = SubscriptionResult.objects.filter(
                    user=request.user, originator_group=community).count()

                if (community.number_of_new_objects != 0
                        or community.number_of_notifications != 0
                    ) and community != request.community:
                    unread_other_communities = True

            from curia.notifications import get_subscription_entries
            subscription_entries = get_subscription_entries(
                request.user, request.community)

        from django.template import loader, Context
        from django.utils.simplejson import dumps
        from django.template import RequestContext

        c = RequestContext(request)
        c.update({
            'current_url_is_bookmarked':
            current_url in [x.url for x in bookmarks],
            'notifications':
            notifications,
            'event_invites':
            event_invites,
            'group_invites':
            group_invites,
            'bookmarks':
            bookmarks,
            'subscription_entries':
            subscription_entries,
            'communities':
            communities,
            'unread_other_communities':
            unread_other_communities,
        })

        button = ''
        if len(communities) > 1:
            button = loader.get_template(
                'community_selector_button.html').render(c)

        return HttpResponse(dumps([
            loader.get_template('community_selector.html').render(c),
            button,
            loader.get_template(template).render(c),
        ],
                                  ensure_ascii=False),
                            mimetype="text/json; charset=UTF-8")
        # return render_to_response(request, template, {
        #     'current_url_is_bookmarked':current_url in [x.url for x in bookmarks],
        #     'notifications':notifications,
        #     'event_invites':event_invites,
        #     'group_invites':group_invites,
        #     'bookmarks':bookmarks,
        #     'subscription_entries':subscription_entries,
        # })
    except IOError:
        pass
Esempio n. 3
0
from curia.notifications import get_users_to_email
from curia.notifications.models import Notification, SubscriptionResult
users = get_users_to_email()
#from django.contrib.auth.models import User
#users = [User.objects.get(pk=1)]

import codecs
log = codecs.open('curia_schedule.log', 'w', 'utf-8')

for user in users:
    if user.email != '':
        new_stuff = {}
        for community in user.groups.exclude(name='everyone'):
            notifications = Notification.objects.filter(user=user, originator_group=community)
            from curia.notifications import get_subscription_entries
            subscription_entries = get_subscription_entries(user, community)
    
            if len(notifications) != 0 or len(subscription_entries) != 0:
                new_stuff[community] = {'notifications':notifications, 'subscription_entries':subscription_entries}
        
        if len(new_stuff) != 0:
            communities = u', '.join([unicode(x) for x in new_stuff.keys()])
            c = {'new_stuff':new_stuff, 'communities':communities}
            subject =  _("%s has something new for you") % communities
            html_message = loader.get_template('notification_email.html').render(Context(c))
            text_message = loader.get_template('notification_email.txt').render(Context(c))
            send_html_mail_with_attachments(subject=subject, message=text_message, html_message=html_message, from_email='*****@*****.**', recipient_list=[user.email])
            meta = user.meta
            meta.last_notification_email_time = datetime.now()
            meta.save()
            log.write(u'sent to %s\n' % user)