コード例 #1
0
    def email_user(self):
        """
        Email this news item to the user.
        """
        if not self.user.email():
            return

        headers = {
            'Precedence': 'bulk',
            'Auto-Submitted': 'auto-generated',
            'X-coursys-topic': self.source_display(),
        }

        if self.course:
            subject = u"%s: %s" % (self.course.name(), self.title)
            headers['X-course'] = self.course.slug
        else:
            subject = self.title
        to_email = self.user.full_email()
        from_email = self.email_from()
        if self.author:
            headers['Sender'] = self.author.email()
        else:
            headers['Sender'] = settings.DEFAULT_SENDER_EMAIL

        if self.url:
            url = self.absolute_url()
        else:
            url = settings.BASE_ABS_URL + reverse('news:news_list')

        text_content = u"For more information, see " + url + "\n"
        text_content += u"\n--\nYou received this email from %s. If you do not wish to receive\nthese notifications by email, you can edit your email settings here:\n  " % (
            product_name(hint='course'))
        text_content += settings.BASE_ABS_URL + reverse('config:news_config')

        if self.course:
            html_content = u'<h3>%s: <a href="%s">%s</a></h3>\n' % (
                self.course.name(), url, self.title)
        else:
            html_content = u'<h3><a href="%s">%s</a></h3>\n' % (url,
                                                                self.title)
        html_content += self.content_xhtml()
        html_content += u'\n<p style="font-size: smaller; border-top: 1px solid black;">You received this email from %s. If you do not wish to receive\nthese notifications by email, you can <a href="%s">change your email settings</a>.</p>' \
                        % (product_name(hint='course'), settings.BASE_ABS_URL + reverse('config:news_config'))

        msg = EmailMultiAlternatives(subject,
                                     text_content,
                                     from_email, [to_email],
                                     headers=headers)
        msg.attach_alternative(html_content, "text/html")
        msg.send()
コード例 #2
0
ファイル: views.py プロジェクト: skyemason/coursys
def student_info(request, userid=None):
    # old student search view: new search is better in every way.
    messages.add_message(
        request, messages.INFO,
        'The old student search has been replaced with an awesome site search, accessible from the search box at the top of every page in %s.'
        % (product_name(request), ))
    return HttpResponsePermanentRedirect(reverse('dashboard:site_search'))
コード例 #3
0
ファイル: models.py プロジェクト: tjkind/coursys
 def notify_message(self, message):
     "Called when a reply is posted anywhere for this course."
     if self.status in ['NONE', 'MAIL'] or self.member.role == 'DROP':
         pass
     elif self.status == 'ALLM':
         url = settings.BASE_ABS_URL + message.get_absolute_url()
         editurl = settings.BASE_ABS_URL + reverse(
             'offering:discussion:manage_discussion_subscription',
             kwargs={'course_slug': self.member.offering.slug})
         subject = 'New discussion on "%s" in %s' % (
             message.topic.title, message.topic.offering.name())
         context = {
             'topic': message.topic,
             'message': message,
             'url': url,
             'editurl': editurl,
             'offering': message.topic.offering,
             'subject': subject,
             'to': self.member.person,
             'author': message.author,
             'topic_sub': False,
             'CourSys': product_name(hint='course')
         }
         if self.member.person != message.author.person:
             self.email_user('discuss/topic_notify.txt',
                             'discuss/topic_notify.html', context)
コード例 #4
0
ファイル: models.py プロジェクト: sfu-fas/coursys
    def send(self):
        """
        Send email for this ReminderMessage
        """
        assert not self.sent

        today = datetime.date.today()
        if self.date < today - datetime.timedelta(days=MAX_LATE):
            raise ValueError('ReminderMessage has not been sent, but is alarmingly past-due.')

        content_html = self.reminder.html_content()
        content_text = self.reminder.content # the creole/markdown is good enough for the plain-text version?

        hint = 'admin' if self.reminder.reminder_type == 'ROLE' else 'other'
        message_context = {
            'content_html': content_html,
            'content_text': content_text,
            'coursys': product_name(hint=hint),
            'when': self.reminder.when_description(),
            'who': self.reminder.who_description(),
            'url': settings.BASE_ABS_URL + self.reminder.get_absolute_url(),
        }

        subject = 'Reminder: ' + self.reminder.title
        message = REMINDER_TEXT_TEMPLATE.substitute(message_context)
        html_message = REMINDER_HTML_TEMPLATE.substitute(message_context)
        from_ = self.reminder.person.full_email()
        to = self.person.full_email()

        send_mail(subject=subject, message=message, html_message=html_message, from_email=from_, recipient_list=[to])

        self.sent_at = datetime.datetime.now()
        self.sent = True
        self.save()
コード例 #5
0
ファイル: models.py プロジェクト: sfu-fas/coursys
 def email_memo(self):
     """
     Emails the person to whom the booking is assigned.
     """
     subject = 'Booking notification'
     from_email = settings.DEFAULT_FROM_EMAIL
     template = get_template('space/emails/memo.txt')
     context = {'booking': self.booking_record, 'CourSys': product_name(hint='admin')}
     msg = EmailMultiAlternatives(subject, template.render(context), from_email,
                                  [self.booking_record.person.email()], headers={'X-coursys-topic': 'space'})
     msg.send()
コード例 #6
0
 def email_memo(self):
     """
     Emails the person to whom the booking is assigned.
     """
     subject = 'Booking notification'
     from_email = settings.DEFAULT_FROM_EMAIL
     template = get_template('space/emails/memo.txt')
     context = {'booking': self.booking_record, 'CourSys': product_name(hint='admin')}
     msg = EmailMultiAlternatives(subject, template.render(context), from_email,
                                  [self.booking_record.person.email()], headers={'X-coursys-topic': 'space'})
     msg.send()
コード例 #7
0
ファイル: models.py プロジェクト: sfu-fas/coursys
 def notify(self, topic):
     if self.status == 'NONE' or self.member.role == 'DROP':
         pass
     elif self.status in ['MAIL', 'ALLM']:
         url = settings.BASE_ABS_URL + topic.get_absolute_url()
         editurl = settings.BASE_ABS_URL + reverse('offering:discussion:manage_discussion_subscription', 
                 kwargs={'course_slug': self.member.offering.slug})
         subject = 'New discussion in %s' % (topic.offering.name())
         context = {'topic': topic, 'url': url, 'editurl': editurl,
                    'offering': self.member.offering, 'subject': subject,
                    'to': self.member.person, 'author': topic.author, 'CourSys': product_name(hint='course')}
         if self.member.person != topic.author.person:
             self.email_user('discuss/discuss_notify.txt', 'discuss/discuss_notify.html', context)
コード例 #8
0
ファイル: models.py プロジェクト: sfu-fas/coursys
 def notify_message(self, message):
     "Called when a reply is posted anywhere for this course."
     if self.status in ['NONE', 'MAIL'] or self.member.role == 'DROP':
         pass
     elif self.status == 'ALLM':
         url = settings.BASE_ABS_URL + message.get_absolute_url()
         editurl = settings.BASE_ABS_URL + reverse('offering:discussion:manage_discussion_subscription',
                 kwargs={'course_slug': self.member.offering.slug})
         subject = 'New discussion on "%s" in %s' % (message.topic.title, message.topic.offering.name())
         context = {'topic': message.topic, 'message': message, 'url': url, 'editurl': editurl,
                    'offering': message.topic.offering, 'subject': subject,
                    'to': self.member.person, 'author': message.author, 'topic_sub': False,
                    'CourSys': product_name(hint='course')}
         if self.member.person != message.author.person:
             self.email_user('discuss/topic_notify.txt', 'discuss/topic_notify.html', context)
コード例 #9
0
ファイル: models.py プロジェクト: sfu-fas/coursys
    def email_user(self):
        """
        Email this news item to the user.
        """
        if not self.user.email():
            return

        headers = {
                'Precedence': 'bulk',
                'Auto-Submitted': 'auto-generated',
                'X-coursys-topic': self.source_display(),
                }

        if self.course:
            subject = "%s: %s" % (self.course.name(), self.title)
            headers['X-course'] = self.course.slug
        else:
            subject = self.title
        to_email = self.user.full_email()
        from_email = self.email_from()
        if self.author:
            headers['Sender'] = self.author.email()
        else:
            headers['Sender'] = settings.DEFAULT_SENDER_EMAIL

        if self.url:
            url = self.absolute_url()
        else:
            url = settings.BASE_ABS_URL + reverse('news:news_list')
        
        text_content = "For more information, see " + url + "\n"
        text_content += "\n--\nYou received this email from %s. If you do not wish to receive\nthese notifications by email, you can edit your email settings here:\n  " % (product_name(hint='course'))
        text_content += settings.BASE_ABS_URL + reverse('config:news_config')
        
        if self.course:
            html_content = '<h3>%s: <a href="%s">%s</a></h3>\n' % (self.course.name(), url, self.title)
        else:
            html_content = '<h3><a href="%s">%s</a></h3>\n' % (url, self.title)
        html_content += self.content_xhtml()
        html_content += '\n<p style="font-size: smaller; border-top: 1px solid black;">You received this email from %s. If you do not wish to receive\nthese notifications by email, you can <a href="%s">change your email settings</a>.</p>' \
                        % (product_name(hint='course'), settings.BASE_ABS_URL + reverse('config:news_config'))
        
        msg = EmailMultiAlternatives(subject, text_content, from_email, [to_email], headers=headers)
        msg.attach_alternative(html_content, "text/html")
        msg.send()
コード例 #10
0
def media(request):
    """
    Add context things that we need
    """
    # A/B testing: half of instructors and TAs see a different search box
    instr_ta = is_instr_ta(request.user.username)
    instr_ta_ab = instr_ta and request.user.is_authenticated and request.user.id % 2 == 0
    # GRAD_DATE(TIME?)_FORMAT for the grad/ra/ta apps
    return {
        'GRAD_DATE_FORMAT': settings.GRAD_DATE_FORMAT,
        'GRAD_DATETIME_FORMAT': settings.GRAD_DATETIME_FORMAT,
        'LOGOUT_URL': settings.LOGOUT_URL,
        'LOGIN_URL': settings.LOGIN_URL,
        'STATIC_URL': settings.STATIC_URL,
        'is_instr_ta': instr_ta,
        'instr_ta_ab': instr_ta_ab,
        'request_path': request.path,
        'CourSys': product_name(request),
        'help_email': help_email(request),
    }
コード例 #11
0
ファイル: models.py プロジェクト: vanthaiunghoa/coursys
    def send(self):
        """
        Send email for this ReminderMessage
        """
        assert not self.sent

        today = datetime.date.today()
        if self.date < today - datetime.timedelta(days=MAX_LATE):
            raise ValueError(
                'ReminderMessage has not been sent, but is alarmingly past-due.'
            )

        content_html = self.reminder.html_content()
        content_text = self.reminder.content  # the creole/markdown is good enough for the plain-text version?

        hint = 'admin' if self.reminder.reminder_type == 'ROLE' else 'other'
        message_context = {
            'content_html': content_html,
            'content_text': content_text,
            'coursys': product_name(hint=hint),
            'when': self.reminder.when_description(),
            'who': self.reminder.who_description(),
            'url': settings.BASE_ABS_URL + self.reminder.get_absolute_url(),
        }

        subject = 'Reminder: ' + self.reminder.title
        message = REMINDER_TEXT_TEMPLATE.substitute(message_context)
        html_message = REMINDER_HTML_TEMPLATE.substitute(message_context)
        from_ = self.reminder.person.full_email()
        to = self.person.full_email()

        send_mail(subject=subject,
                  message=message,
                  html_message=html_message,
                  from_email=from_,
                  recipient_list=[to])

        self.sent_at = datetime.datetime.now()
        self.sent = True
        self.save()
コード例 #12
0
ファイル: models.py プロジェクト: tjkind/coursys
 def notify(self, topic):
     if self.status == 'NONE' or self.member.role == 'DROP':
         pass
     elif self.status in ['MAIL', 'ALLM']:
         url = settings.BASE_ABS_URL + topic.get_absolute_url()
         editurl = settings.BASE_ABS_URL + reverse(
             'offering:discussion:manage_discussion_subscription',
             kwargs={'course_slug': self.member.offering.slug})
         subject = 'New discussion in %s' % (topic.offering.name())
         context = {
             'topic': topic,
             'url': url,
             'editurl': editurl,
             'offering': self.member.offering,
             'subject': subject,
             'to': self.member.person,
             'author': topic.author,
             'CourSys': product_name(hint='course')
         }
         if self.member.person != topic.author.person:
             self.email_user('discuss/discuss_notify.txt',
                             'discuss/discuss_notify.html', context)
コード例 #13
0
ファイル: views.py プロジェクト: sfu-fas/coursys
from django.conf import settings

from oauth_provider.models import Token
from oauth_provider.forms import AuthorizeRequestTokenForm
from api.models import ConsumerInfo
from coredata.models import Person
from courselib.branding import product_name

EMAIL_INFORM_TEMPLATE = """
The application "{consumername}" has requested access to %s on your
behalf. You can approve this request using the interface the application
provided (and may have already done so).

You can review permissions given to third-party applications (removing access
if you wish) at this URL:
{url}""" % (product_name(hint='course'),)


@login_required
def oauth_authorize(request, request_token, callback, params):
    """
    The callback view for oauth_provider's OAUTH_AUTHORIZE_VIEW.
    """
    consumer = request_token.consumer
    consumerinfo = ConsumerInfo.objects.filter(consumer_id=request_token.consumer_id).order_by('-timestamp').first()
    form = AuthorizeRequestTokenForm(initial={'oauth_token': request_token.key})

    # email the user so we're super-sure they know this is happening
    person = get_object_or_404(Person, userid=request.user.username)
    manage_url = request.build_absolute_uri(reverse('config:manage_tokens'))
    message = EMAIL_INFORM_TEMPLATE.format(consumername=consumer.name, url=manage_url)
コード例 #14
0
ファイル: views.py プロジェクト: sfu-fas/coursys
def student_info(request, userid=None):
    # old student search view: new search is better in every way.
    messages.add_message(request, messages.INFO, 'The old student search has been replaced with an awesome site search, accessible from the search box at the top of every page in %s.' % (product_name(request),))
    return HttpResponsePermanentRedirect(reverse('dashboard:site_search'))
コード例 #15
0
from django.conf import settings

from oauth_provider.models import Token
from oauth_provider.forms import AuthorizeRequestTokenForm
from api.models import ConsumerInfo
from coredata.models import Person
from courselib.branding import product_name

EMAIL_INFORM_TEMPLATE = """
The application "{consumername}" has requested access to %s on your
behalf. You can approve this request using the interface the application
provided (and may have already done so).

You can review permissions given to third-party applications (removing access
if you wish) at this URL:
{url}""" % (product_name(hint='course'), )


@login_required
def oauth_authorize(request, request_token, callback, params):
    """
    The callback view for oauth_provider's OAUTH_AUTHORIZE_VIEW.
    """
    consumer = request_token.consumer
    consumerinfo = ConsumerInfo.objects.filter(
        consumer_id=request_token.consumer_id).order_by('-timestamp').first()
    form = AuthorizeRequestTokenForm(
        initial={'oauth_token': request_token.key})

    # email the user so we're super-sure they know this is happening
    person = get_object_or_404(Person, userid=request.user.username)