コード例 #1
0
ファイル: views.py プロジェクト: xhacker/coursys
def browse(request):
    units = request.units
    hiring_choices = [('all', 'All')] + possible_supervisors(units)
    project_choices = [('all', 'All')] + [
        (p.id, unicode(p))
        for p in Project.objects.filter(unit__in=units, hidden=False)
    ]
    account_choices = [('all', 'All')] + [
        (a.id, unicode(a))
        for a in Account.objects.filter(unit__in=units, hidden=False)
    ]
    if 'data' in request.GET:
        # AJAX query for data
        ras = RAAppointment.objects.filter(unit__in=units, deleted=False) \
                .select_related('person', 'hiring_faculty', 'project', 'account')
        if 'hiring_faculty' in request.GET and request.GET[
                'hiring_faculty'] != 'all':
            ras = ras.filter(hiring_faculty__id=request.GET['hiring_faculty'])
        if 'project' in request.GET and request.GET['project'] != 'all':
            ras = ras.filter(project__id=request.GET['project'],
                             project__unit__in=units)
        if 'account' in request.GET and request.GET['account'] != 'all':
            ras = ras.filter(account__id=request.GET['account'],
                             account__unit__in=units)

        truncated = False
        if ras.count() > 200:
            ras = ras[:200]
            truncated = True
        data = []
        for ra in ras:
            radata = {
                'slug': ra.slug,
                'name': ra.person.sortname(),
                'hiring': ra.hiring_faculty.sortname(),
                'project': unicode(ra.project),
                'project_hidden': ra.project.hidden,
                'account': unicode(ra.account),
                'account_hidden': ra.account.hidden,
                'start': datefilter(ra.start_date, settings.GRAD_DATE_FORMAT),
                'end': datefilter(ra.end_date, settings.GRAD_DATE_FORMAT),
                'amount': '$' + unicode(ra.lump_sum_pay),
            }
            data.append(radata)

        response = HttpResponse(content_type="application/json")
        json.dump({'truncated': truncated, 'data': data}, response, indent=1)
        return response

    else:
        # request for page
        form = RABrowseForm()
        form.fields['hiring_faculty'].choices = hiring_choices
        form.fields['account'].choices = account_choices
        form.fields['project'].choices = project_choices
        context = {'form': form}
        return render(request, 'ra/browse.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: tedkirkpatrick/coursys
def browse(request):
    units = Unit.sub_units(request.units)
    hiring_choices = [('all', 'All')] + possible_supervisors(units)
    project_choices = [('all', 'All')] + [(p.id, unicode(p)) for p in Project.objects.filter(unit__in=units, hidden=False)]
    account_choices = [('all', 'All')] + [(a.id, unicode(a)) for a in Account.objects.filter(unit__in=units, hidden=False)]
    if 'data' in request.GET:
        # AJAX query for data
        ras = RAAppointment.objects.filter(unit__in=units, deleted=False) \
                .select_related('person', 'hiring_faculty', 'project', 'account')
        if 'hiring_faculty' in request.GET and request.GET['hiring_faculty'] != 'all':
            ras = ras.filter(hiring_faculty__id=request.GET['hiring_faculty'])
        if 'project' in request.GET and request.GET['project'] != 'all':
            ras = ras.filter(project__id=request.GET['project'], project__unit__in=units)
        if 'account' in request.GET and request.GET['account'] != 'all':
            ras = ras.filter(account__id=request.GET['account'], account__unit__in=units)

        truncated = False
        if ras.count() > 200:
            ras = ras[:200]
            truncated = True
        data = []
        for ra in ras:
            radata = {
                'slug': ra.slug,
                'name': ra.person.sortname(),
                'hiring': ra.hiring_faculty.sortname(),
                'project': unicode(ra.project),
                'project_hidden': ra.project.hidden,
                'account': unicode(ra.account),
                'account_hidden': ra.account.hidden,
                'start': datefilter(ra.start_date, settings.GRAD_DATE_FORMAT),
                'end': datefilter(ra.end_date, settings.GRAD_DATE_FORMAT),
                'amount': '$'+unicode(ra.lump_sum_pay),
                }
            data.append(radata)
        
        response = HttpResponse(content_type="application/json")
        json.dump({'truncated': truncated, 'data': data}, response, indent=1)
        return response

    else:
        # request for page
        form = RABrowseForm()
        form.fields['hiring_faculty'].choices = hiring_choices
        form.fields['account'].choices = account_choices
        form.fields['project'].choices = project_choices
        context = {
            'form': form
            }
        return render(request, 'ra/browse.html', context)
コード例 #3
0
def _send_notification(subscriptions, expiry_days):
    site = Site.objects.get_current()
    if expiry_days == 30:
        subject = 'Action required: Your GGC subscription will expire in 1 month'
    elif expiry_days == 7:
        subject = 'Action required: Your GGC subscription will expire in 1 week'
    else:
        subject = 'Action required: Your GGC subscription has expired'

    for subscription in subscriptions:
        organisation = subscription.order.organisation
        users = subscription.order.organisation.user_set.all()
        end_date = subscription.end_date
        for user in users:
            if has_role(user, ['admin']):
                if expiry_days == 0:
                    renewal_message = "has expired"
                else:
                    renewal_message = "is due for renewal on {}".format(
                        datefilter(end_date))
                context = {
                    'site': site,
                    'site_domain': site.domain,
                    'site_name': site.name,
                    'email': user.email,
                    'organisation_name': organisation.legal_name,
                    'renewal_message': renewal_message,
                    'user_name': user.name
                }
                send(to=user.email,
                     subject=subject,
                     template_name='subscriptions/emails/order_renewal.txt',
                     context=context,
                     sender=settings.DEFAULT_SUBSCRIPTION_FROM_EMAIL)
コード例 #4
0
    def get_context_data(self, *args, **kwargs):

        ctx = super(PostArchive, self).get_context_data(*args, **kwargs)

        page = self.request.GET.get('p', 1)
        year = self.kwargs.get('year', None)
        month = self.kwargs.get('month', None)
        day = self.kwargs.get('day', None)
        msg = ""

        try:
            if day and month and year:
                lower_limit = date(int(year), int(month), int(day))
                upper_limit = lower_limit + relativedelta(days=+1)
                msg = "%s" % datefilter(lower_limit, "jS M Y")
            elif month and year:
                lower_limit = date(int(year), int(month), 1)
                upper_limit = lower_limit + relativedelta(months=+1)
                msg = "%s" % datefilter(lower_limit, "F Y")
            elif year:
                lower_limit = date(int(year), 1, 1)
                upper_limit = lower_limit + relativedelta(years=+1)
                msg = "%s" % year
        except ValueError:
            raise Http404

        if self.request.user.is_authenticated():
            gql = "WHERE post_date >= :1 AND post_date <= :2 ORDER BY post_date DESC"
        else:
            gql = "WHERE is_published = true AND post_date >= :1 AND post_date <= :2 ORDER BY post_date DESC"

        objects = Post.gql(gql, lower_limit, upper_limit)

        pager = Paginator(objects, PAGE_SIZE)
        page_obj = pager.page(page)

        ctx.update({
            'display_message': msg,
            'paginator': pager,
            'page_obj': page_obj,
            'year': year,
            'month': month,
            'day': day
        })

        return ctx
コード例 #5
0
ファイル: models.py プロジェクト: StelaDD/survey
 def status(self):
     if not self.visible:
         return _("private")
     if self.open:
         return _("open")
     if datetime.now() < self.opens:
         return unicode(_("opens ")) + datefilter(self.opens)
     return _("closed")
コード例 #6
0
ファイル: test_shows.py プロジェクト: roperi/myband
    def test_shows_displays_upcoming_gigs_before_past_gigs(self):
        self.get_url('/live')
        self.assertIn('Live', self.browser.title)

        from time import sleep
        sleep(10)

        displayed_dates = [x.text for x in self.find_css('.gig .date')]
        upcoming_dates = [datefilter(x.date) for x in self.upcoming_gigs]
        past_dates = [datefilter(x.date) for x in self.past_gigs]

        displayed_descriptions = [x.text for x in
                                  self.find_css('.gig .description')]
        upcoming_descriptions = [x.description for x in self.upcoming_gigs]
        past_descriptions = [x.description for x in self.past_gigs]

        self.assertEqual(displayed_dates, upcoming_dates + past_dates)
        self.assertEqual(displayed_descriptions,
                         upcoming_descriptions + past_descriptions)
コード例 #7
0
ファイル: models.py プロジェクト: yasardolugan/boarddirector
 def __unicode__(self):
     if self.meeting is not None:
         # Replace meeting id with date in name
         date_str = datefilter(self.meeting.start, 'N j, Y')
         return u'{0} ({1})'.format(self.meeting.name, date_str)
     if self.committee is not None:
         return self.committee.name
     if self.membership is not None:
         return unicode(self.membership)
     return self.name
コード例 #8
0
ファイル: dates.py プロジェクト: banterability/secretary
def timeago(datetime):
    """
    Inserts <abbr> tag that works with timeago js script.
    """    
    iso_date = datetime.isoformat()
    # cut off nasty milliseconds that confusion timeago
    index = iso_date.find('.')
    if index != -1:
        iso_date = iso_date[:index]
    
    pretty_date = datefilter(datetime, "P")
    return {'iso_date':iso_date, 'pretty_date':pretty_date}
コード例 #9
0
ファイル: models.py プロジェクト: caiosalim/cheddar
    def captured_at_display(self):
        u'''Returns a prettier date format'''

        now = datetime.datetime.now(utc if is_aware(self.captured_at) else None)
        if self.captured_at < now:
            delta = now - self.captured_at
        else:
            delta = self.captured_at - now        
        
        if delta.days >= 1:
            return datefilter(self.captured_at)
        else:
            return timefilter(self.captured_at)
コード例 #10
0
ファイル: models.py プロジェクト: rafaelsierra/cheddar
    def captured_at_display(self):
        u'''Returns a prettier date format'''

        now = timezone.now()
        if self.captured_at < now:
            delta = now - self.captured_at
        else:
            delta = self.captured_at - now

        if delta.days >= 1:
            return datefilter(self.captured_at)
        else:
            return timefilter(self.captured_at)
コード例 #11
0
ファイル: commontags.py プロジェクト: kabirh/riotvine
def std_date(value, format):
    '''Reformat standard date.

    Supported date format example:
        Tue, 19 Dec 2008 21:41:47 +0000

    '''
    try:
        d, dt = value.split(', ')
        dt, d = dt.split(' +')
        dt = datetime.strptime(dt, "%d %b %Y %H:%M:%S")
        return datefilter(dt, format)
    except:
        return value
コード例 #12
0
ファイル: timeago.py プロジェクト: banterability/django-reeds
def timeago(datetime):
    """
    Inserts <abbr> tag that works with timeago js script.
    More info: http://timeago.yarp.com/
    """
    
    html = '<abbr class="timeago" title="{{ISODATE}}">{{PRETTYDATE}}</abbr>'
    iso_date = datetime.isoformat()
    # cut off nasty milliseconds that confuse timeago
    index = iso_date.find('.')
    if index != -1:
        iso_date = iso_date[:index]
    pretty_date = datefilter(datetime, "F j, Y, P")
    return html.replace("{{ISODATE}}", iso_date).replace("{{PRETTYDATE}}", pretty_date)
コード例 #13
0
ファイル: test_shows.py プロジェクト: roperi/myband
    def test_home_displays_upcoming_gigs(self):
        self.get_url('')

        displayed_dates = [x.text for x in self.find_css('.gig .date')]
        upcoming_dates = [datefilter(x.date) for x in self.upcoming_gigs]

        displayed_descriptions = [x.text for x in
                                  self.find_css('.gig .description')]
        upcoming_descriptions = [x.description for x in self.upcoming_gigs]

        displayed_details = [x.text for x in self.find_css('.gig .details')]
        upcoming_details = [x.details for x in self.upcoming_gigs]

        self.assertEqual(displayed_dates, upcoming_dates)
        self.assertEqual(displayed_descriptions, upcoming_descriptions)
        self.assertEqual(displayed_details, upcoming_details)
コード例 #14
0
def timeago(datetime, format=None):
    utc_datetime = utils.naive_to_utc(datetime)
    return mark_safe(
        '<time class="timeago" pubdate="" datetime="%s">%s</time>' %
        (datetime_isoformat(utc_datetime), datefilter(utc_datetime, format)))
コード例 #15
0
ファイル: models.py プロジェクト: justquick/bic
def format(d):
	if d.year == date.today().year:
		s = "F j"
	else:
		s = "F j, Y"
	return mark_safe(datefilter(d, s))
コード例 #16
0
def dateago(date, format=None):
    return mark_safe(
        '<time class="timeago" pubdate="" datetime="%s">%s</time>' %
        (date_isoformat(date), datefilter(date, format)))
コード例 #17
0
    def prepare_pdf(self):
        from clublink.certificates.models import CertificateType

        cert = self.certificate

        effective_header = cert.effective_header
        if effective_header:
            header_img = self.read_image(effective_header)
        else:
            img = 'certificate-header-double.jpg' if cert.club_secondary else 'certificate-header.jpg'
            header_img = finders.find('certificates/{}'.format(img))

        # Draw the header image
        self.canvas.drawImage(header_img,
                              x=0,
                              y=self.pagesize[1] - (1.883 * inch),
                              width=self.pagesize[0],
                              height=1.883 * inch)

        # Draw the logo(s)
        if cert.type.category == CertificateType.PLAYERS_CLUB_CATEGORY:
            logo_file = finders.find('certificates/players-club-logo.png')
        elif cert.type.category == CertificateType.MERCHANDISE_CATEGORY:
            logo_file = finders.find('certificates/cl-logo-{}.png'.format(
                cert.batch.language))
        else:
            try:
                logo_file = default_storage.open(cert.club.logo.name)
            except:
                logo_file = finders.find('certificates/logo-25.jpg')

        if cert.club.logo or cert.type.category in (
                CertificateType.PLAYERS_CLUB_CATEGORY,
                CertificateType.MERCHANDISE_CATEGORY):
            self.canvas.drawImage(self.resize_image(logo_file, (300, 300)),
                                  x=0.487 * inch,
                                  y=9.753 * inch,
                                  width=1.107 * inch,
                                  height=1.107 * inch,
                                  mask='auto',
                                  preserveAspectRatio=True)

        if (cert.club_secondary and cert.club_secondary != cert.club
                and cert.club_secondary.logo and cert.type.category
                not in (CertificateType.PLAYERS_CLUB_CATEGORY,
                        CertificateType.MERCHANDISE_CATEGORY)):
            try:
                logo_file = default_storage.open(cert.club_secondary.logo.name)
            except:
                logo_file = finders.find('certificates/logo-25.jpg')

            self.canvas.drawImage(self.resize_image(logo_file, (300, 300)),
                                  x=6.906 * inch,
                                  y=9.753 * inch,
                                  width=1.107 * inch,
                                  height=1.107 * inch,
                                  mask='auto',
                                  preserveAspectRatio=True)

        # Headline
        self.canvas.setFillColorRGB(1, 1, 1)

        headline_font_size = 26
        cert_name = cert.type.localized('name', cert.batch.language)
        while pdfmetrics.stringWidth(cert_name, 'Garamond',
                                     headline_font_size) > 4.25 * inch:
            headline_font_size -= 0.1

        self.canvas.setFont('Garamond', headline_font_size)
        self.canvas.drawCentredString(4.25 * inch, 9.78 * inch, cert_name)

        # Define text styles
        self.canvas.setFillColorRGB(0, 0, 0)

        # Member Details
        y_offset = 2.25 * inch

        if not cert.type.hide_recipient_name:
            y_offset = self.print_paragraphs(
                _('NAME: {name}').format(name=cert.batch.recipient_name),
                offset=y_offset + (0.25 * inch),
                x=0.35 * inch,
                width=3.747 * inch)

        # Message to recipient
        message = cert.message
        if not message:
            message = cert.type.localized('message', cert.batch.language)
        message = self.format_message(sanitize_string(message))

        if message:
            y_offset = self.print_paragraphs(message,
                                             offset=y_offset + (0.25 * inch),
                                             x=0.35 * inch,
                                             width=3.747 * inch)

        # Restrictions
        if cert.type.category != CertificateType.LEFT_SIDE_CUSTOM:
            restrictions = self.format_message(
                sanitize_string(
                    cert.type.localized('restrictions', cert.batch.language)))

            self.print_paragraphs(restrictions,
                                  offset=y_offset + (0.25 * inch),
                                  x=0.35 * inch,
                                  width=3.747 * inch)

        # Divider
        self.canvas.setStrokeColorRGB(0, 0, 0)
        self.canvas.setLineWidth(0.0035 * inch)
        self.canvas.line(4.443 * inch, 8.475 * inch, 4.443 * inch, 5.79 * inch)

        # Expiry Date
        y_offset = 2.25 * inch

        if cert.expiry_date:
            y_offset = self.print_paragraphs(_('CERTIFICATE EXPIRES:'),
                                             offset=y_offset + (0.25 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Medium')

            y_offset = self.print_paragraphs(datefilter(
                cert.expiry_date, 'F j, Y').upper(),
                                             offset=y_offset - (0.1 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Light')

        # Club Details
        if cert.type.category in (CertificateType.PLAYERS_CLUB_CATEGORY,
                                  CertificateType.MERCHANDISE_CATEGORY):
            title = _('CLUBS:')
        elif cert.type.category == CertificateType.RESORT_STAY_CATEGORY:
            title = _('RESORT:')
        else:
            title = _('CLUB:')

        y_offset = self.print_paragraphs(title,
                                         offset=y_offset + (0.25 * inch),
                                         x=4.81 * inch,
                                         width=3.357 * inch,
                                         style='Gotham-Medium')

        if cert.type.category == CertificateType.PLAYERS_CLUB_CATEGORY:
            for club in cert.type.players_club_clubs.all():
                daily_fee = cert.type.players_club_daily_fee_listing and club.daily_fee_location
                name_str = '{} - Daily Fee' if daily_fee else '{}'
                y_offset = self.print_paragraphs(name_str.format(club.name),
                                                 offset=y_offset -
                                                 (0.1 * inch),
                                                 x=4.81 * inch,
                                                 width=3.357 * inch)
        elif cert.type.category == CertificateType.MERCHANDISE_CATEGORY:
            y_offset = self.print_paragraphs(
                _('ClubLink Wide<br /> All Canadian locations'),
                offset=y_offset - (0.1 * inch),
                x=4.81 * inch,
                width=3.357 * inch)
        else:

            club_details = cert.club.name

            if cert.club.address:
                club_details += ', <br />{}'.format(cert.club.address)

            if cert.club.city and cert.club.state:
                club_details += ', <br />{}, {}'.format(
                    cert.club.city, cert.club.state)

            y_offset = self.print_paragraphs(club_details,
                                             offset=y_offset - (0.1 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch)

            if cert.club_secondary and (cert.club_secondary != cert.club):
                club_details = '{}, <br />{}, <br />{}, {}'.format(
                    cert.club_secondary.name, cert.club_secondary.address,
                    cert.club_secondary.city, cert.club_secondary.state)

                y_offset = self.print_paragraphs(title,
                                                 offset=y_offset +
                                                 (0.25 * inch),
                                                 x=4.81 * inch,
                                                 width=3.357 * inch,
                                                 style='Gotham-Medium')

                y_offset = self.print_paragraphs(club_details,
                                                 offset=y_offset -
                                                 (0.1 * inch),
                                                 x=4.81 * inch,
                                                 width=3.357 * inch)

            # output_str = '{} <br/>'.format(cert.club.name)

            # # if cert.club_secondary:
            # #     output_str + '{} <br/>'.format(
            # #         cert.club_secondary.name
            # #     )

            # y_offset = self.print_paragraphs(
            #     output_str,
            #     offset=y_offset - (0.1 * inch),
            #     x=4.81 * inch,
            #     width=3.357 * inch,
            #     style='Gotham-Light')

        # Num Players
        if cert.num_players:
            y_offset = self.print_paragraphs(_('NUMBER OF PLAYERS:'),
                                             offset=y_offset + (0.25 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Medium')

            y_offset = self.print_paragraphs(str(int(cert.num_players)),
                                             offset=y_offset - (0.1 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Light')

        # Num Nights
        if cert.num_nights:
            y_offset = self.print_paragraphs(_('NUMBER OF NIGHTS:'),
                                             offset=y_offset + (0.25 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Medium')

            y_offset = self.print_paragraphs(str(int(cert.num_nights)),
                                             offset=y_offset - (0.1 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Light')

        # Dollar Amount
        if cert.dollar_amount:
            y_offset = self.print_paragraphs(_('DOLLAR AMOUNT:'),
                                             offset=y_offset + (0.25 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Medium')

            y_offset = self.print_paragraphs(str(cert.dollar_amount),
                                             offset=y_offset - (0.1 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Light')

        # Redemption Details
        redemption_details = cert.type.localized('redemption_details',
                                                 cert.batch.language)
        if redemption_details:
            y_offset = self.print_paragraphs('{}:'.format(
                cert.type.get_redemption_location_display().upper()),
                                             offset=y_offset + (0.25 * inch),
                                             x=4.81 * inch,
                                             width=3.357 * inch,
                                             style='Gotham-Medium')

            self.print_paragraphs(sanitize_string(redemption_details),
                                  offset=y_offset - (0.1 * inch),
                                  x=4.81 * inch,
                                  width=3.357 * inch)

        # ClubLink Logo
        self.canvas.drawImage(finders.find(
            'certificates/cl-logo-{}.png'.format(cert.batch.language)),
                              x=4.793 * inch,
                              y=3.517 * inch,
                              width=1.2 * inch,
                              height=0.35 * inch,
                              mask='auto',
                              preserveAspectRatio=True)

        # Barcode
        code = self.fix_barcode_value(cert.code)
        barcode = code128.Code128(code,
                                  barHeight=0.4 * inch,
                                  barWidth=0.01 * inch)
        barcode.drawOn(self.canvas,
                       x=(8.15 * inch) - barcode.width,
                       y=3.65 * inch)

        self.canvas.setFont('Courier', 10)
        self.canvas.drawCentredString(text=code,
                                      x=(8.15 * inch) - (barcode.width / 2),
                                      y=3.517 * inch)

        # Footer text
        self.canvas.setFont('Gotham-Medium', 9)

        self.canvas.drawCentredString(text=_(
            'This certificate is valid for one time use only and must be presented at the '
            'time of redemption.'),
                                      x=4.25 * inch,
                                      y=2.953 * inch)

        self.canvas.drawCentredString(text=_(
            'ClubLink is not responsible for lost, stolen, or duplicate certificates.'
        ),
                                      x=4.25 * inch,
                                      y=2.783 * inch)

        # Divider
        self.canvas.setStrokeColorRGB(0, 0, 0)
        self.canvas.setLineWidth(0.005 * inch)
        self.canvas.line(0.35 * inch, 2.565 * inch, 8.15 * inch, 2.565 * inch)

        # Advertisement
        if cert.type.advertisement:
            try:
                ad = cert.type.advertisement
                image = ad.image if cert.batch.language == 'en' else ad.image_fr
                self.canvas.drawImage(self.read_image(image),
                                      x=0.35 * inch,
                                      y=0.35 * inch,
                                      width=7.80 * inch,
                                      height=2.1 * inch,
                                      preserveAspectRatio=True)
            except:
                logging.error('Could not draw ad')
コード例 #18
0
def format(d):
    if d.year == date.today().year:
        s = "F j"
    else:
        s = "F j, Y"
    return mark_safe(datefilter(d, s))
コード例 #19
0
def timeago(datetime, format=None):
    utc_datetime = utils.naive_to_utc(datetime)
    return mark_safe(
        '<time class="timeago" pubdate="" datetime="%s">%s</time>' % (
            datetime_isoformat(utc_datetime),
            datefilter(utc_datetime, format)))
コード例 #20
0
 def get_created(self, obj):
     """ Renvoyer la date de création du contenu """
     return datefilter(obj.created, "j M Y G:i")
コード例 #21
0
 def status(self):
     if not self.visible: return _('private')
     if self.open: return _('open')
     if datetime.now() < self.opens:
         return unicode(_('opens ')) + datefilter(self.opens)
     return _('closed')
コード例 #22
0
ファイル: datetime.py プロジェクト: artscoop/scoop
 def get_datetime_format(self, format_string="j F Y H:i"):
     """ Renvoyer une représentation texte du timestamp """
     return datefilter(self.get_datetime(), format_string)
コード例 #23
0
    def prepare_pdf(self):
        from clublink.certificates.models import CertificateType

        cert = self.certificate

        effective_header = cert.effective_header
        if effective_header:
            header_img = self.read_image(effective_header)
        else:
            header_img = finders.find('certificates/ag30-header-{}.jpg'.format(
                cert.batch.language))

        # Header Image
        self.canvas.drawImage(header_img,
                              x=0.35 * inch,
                              y=self.pagesize[1] - (3.537 * inch),
                              width=self.pagesize[0] - (0.7 * inch),
                              height=3.187 * inch,
                              preserveAspectRatio=True)

        # Headline
        CONTENT_TOP = 3.787 * inch

        y_offset = self.print_paragraphs(
            _('YOUR 30-DAY CLUBLINK MEMBERSHIP EXPERIENCE AWAITS.'),
            offset=CONTENT_TOP,
            x=0.35 * inch,
            width=5.36 * inch,
            style='headline')

        # Body

        y_offset = self.print_paragraphs(_(
            'With access to over 40* courses in Ontario and Quebec along with the many other '
            'benefits of a ClubLink membership including:'),
                                         offset=y_offset,
                                         x=0.35 * inch,
                                         width=5.36 * inch,
                                         style='body-bold')

        message = _("""
            •\tTee time booking privileges up to seven days in advance

            •\tAccount privileges

            •\tClubLink Advantage Pricing on golf merchandise

            •\tPreferred access and discounts at ClubLink resorts in Muskoka

            •\tComplimentary use of practice facilities (excluding Glen Abbey)

            •\tAccess to dining at all locations
            """)

        y_offset = self.print_paragraphs(message,
                                         offset=y_offset - (0.2 * inch),
                                         x=0.35 * inch,
                                         width=5.36 * inch)

        y_offset = self.print_paragraphs(_(
            '* An additional fee applies to play golf at Glen Abbey, RattleSnake Point, '
            'Greystone and King Valley.'),
                                         offset=y_offset + (0.15 * inch),
                                         x=0.35 * inch,
                                         width=5.36 * inch,
                                         style='body-italic')

        message = cert.message
        if not message:
            message = cert.type.localized('message', cert.batch.language)
        message = self.format_message(sanitize_string(message))

        self.print_paragraphs(message,
                              offset=y_offset,
                              x=0.35 * inch,
                              width=5.36 * inch,
                              style='body-bold')

        # Sidebar

        y_offset = self.print_paragraphs(
            _('Certificate: <br/>{code}').format(code=cert.code),
            offset=CONTENT_TOP,
            x=6.06 * inch,
            width=2.09 * inch,
            style='featured')

        if cert.expiry_date:
            y_offset = self.print_paragraphs(
                _('Membership must be activated by: <br/>{date}').format(
                    date=datefilter(cert.expiry_date, 'j/n/Y')),
                offset=y_offset + (0.15 * inch),
                x=6.06 * inch,
                width=2.09 * inch,
                style='featured')

        if cert.type.category != CertificateType.LEFT_SIDE_CUSTOM:
            restrictions = self.format_message(
                sanitize_string(
                    cert.type.localized('restrictions', cert.batch.language)))

            self.print_paragraphs(restrictions,
                                  offset=y_offset + (0.15 * inch),
                                  x=6.06 * inch,
                                  width=2.09 * inch,
                                  style='fineprint')

        # Divider
        self.canvas.setStrokeColorRGB(0, 0, 0)
        self.canvas.setLineWidth(0.005 * inch)
        self.canvas.line(0.35 * inch, 2.565 * inch, 8.15 * inch, 2.565 * inch)

        # Advertisement
        if cert.type.advertisement:
            ad = cert.type.advertisement
            try:
                image = ad.image if cert.batch.language == 'en' else ad.image_fr
                self.canvas.drawImage(self.read_image(image),
                                      x=0.35 * inch,
                                      y=0.35 * inch,
                                      width=7.80 * inch,
                                      height=2.1 * inch,
                                      preserveAspectRatio=True)
            except:
                logging.error('Could not draw ad')
コード例 #24
0
 def item_title(self, item):
     return u"%s (%s - %s)" % (item.name,
                               datefilter(item.lc_event.time, "F j"),
                               datefilter(item.lc_event.expires, "F j, Y"))
コード例 #25
0
ファイル: feeds.py プロジェクト: mcr/ietfdb
 def item_title(self, item):
     return u"%s (%s - %s)" % (item.name,
                             datefilter(item.lc_event.time, "F j"),
                             datefilter(item.lc_event.expires, "F j, Y"))
コード例 #26
0
    def prepare_pdf(self):
        cert = self.certificate

        effective_header = cert.effective_header
        if effective_header:
            header_img = self.read_image(effective_header)
        else:
            header_img = finders.find('certificates/prestige50-header.jpg')

        # Header Image
        self.canvas.drawImage(header_img,
                              x=0.35 * inch,
                              y=self.pagesize[1] - (3.537 * inch),
                              width=self.pagesize[0] - (0.7 * inch),
                              height=3.187 * inch,
                              preserveAspectRatio=True)

        # Headline
        CONTENT_TOP = 3.787 * inch

        from .models import CertificateType

        if cert.type.template == CertificateType.GOLF_FOR_LIFE_TEMPLATE:
            msg = ''
        else:
            msg = 'Welcome back for another great season!'

        y_offset = self.print_paragraphs(_(msg),
                                         offset=CONTENT_TOP,
                                         x=0.35 * inch,
                                         width=5.2 * inch,
                                         style='headline')

        #### DO NOT REPEAT YOURSELF ####

        # Body
        message = cert.message
        if not message:
            message = cert.type.localized('message', cert.batch.language)
        message = self.format_message(sanitize_string(message))

        self.print_paragraphs(message,
                              offset=y_offset + (0.05 * inch),
                              x=0.35 * inch,
                              width=5.2 * inch)

        # Sidebar
        if cert.expiry_date:
            y_offset = self.print_paragraphs(_('Expires: {date}').format(
                date=datefilter(cert.expiry_date, 'F j, Y')),
                                             offset=CONTENT_TOP +
                                             (0.125 * inch),
                                             x=6.06 * inch,
                                             width=2.09 * inch,
                                             style='sidebar-bold')

        from clublink.certificates.models import CertificateType

        if cert.type.category != CertificateType.LEFT_SIDE_CUSTOM:
            restrictions = self.format_message(
                sanitize_string(
                    cert.type.localized('restrictions', cert.batch.language)))

            y_offset = self.print_paragraphs(restrictions,
                                             offset=y_offset + (0.15 * inch),
                                             x=6.06 * inch,
                                             width=2.09 * inch,
                                             style='sidebar')

        # Barcode
        code = self.fix_barcode_value(cert.code)
        barcode = code128.Code128(code,
                                  barHeight=1 * inch,
                                  barWidth=0.01 * inch)
        barcode.drawOn(self.canvas,
                       x=(7.95 * inch) - barcode.width,
                       y=(10.75 * inch) - y_offset - barcode.height)

        self.canvas.setFont('Courier', 10)
        self.canvas.drawCentredString(text=code,
                                      x=(7.95 * inch) - (barcode.width / 2),
                                      y=(10.6 * inch) - y_offset -
                                      barcode.height)

        #### END DO NOT REPEAT YOURSELF ####

        # Advertisement
        if cert.type.advertisement:
            ad = cert.type.advertisement
            image = ad.image if cert.batch.language == 'en' else ad.image_fr
            self.canvas.drawImage(self.read_image(image),
                                  x=0.35 * inch,
                                  y=0.35 * inch,
                                  width=7.80 * inch,
                                  height=2.1 * inch,
                                  preserveAspectRatio=True)
コード例 #27
0
def dateago(date, format=None):
    return mark_safe(
        '<time class="timeago" pubdate="" datetime="%s">%s</time>' % (
            date_isoformat(date),
            datefilter(date, format)))
コード例 #28
0
ファイル: models.py プロジェクト: scanner/my-django-survey
 def status(self):
     if not self.visible: return _('private')
     if self.open: return _('open')
     if datetime.now() < self.opens:
         return unicode(_('opens ')) + datefilter(self.opens)
     return _('closed')
コード例 #29
0
 def get_updated_date(self, obj):
     """ Renvoyer la date de dernière mise à jour """
     return '<span title="{title}">{anchor}</span>'.format(
         anchor=datefilter(localtime(obj.updated), "H:i"),
         title=datefilter(localtime(obj.updated), "d F Y H:i"))