def describe_filter__created(self, query_data, get_query, descriptions):
     created__gte = query_data.get('created__gte')
     created__lt = query_data.get('created__lt')
     if created__gte or created__lt:
         if created__gte and created__lt:
             label = 'Entered between %s and %s' % (format_date(
                 created__gte, 'j N Y'), format_date(created__lt, 'j N Y'))
         elif created__gte:
             label = 'Entered since %s' % format_date(created__gte, 'j N Y')
         else:
             label = 'Entered before %s' % format_date(created__lt, 'j N Y')
         descriptions.append((label, get_query('created__gte',
                                               'created__lt')))
     return {'created__gte', 'created__lt'}
示例#2
0
 def json(self):
     return {
         'text': self.text,
         'date_fmt': format_date(self.date, 'M j, H:i'),
         'author': user_name(self.user, default=settings.SYSTEM_USERNAME),
         'is_system': self.is_system,
     }
 def get_valid_data(self):
     # theoretically, a valid query for GET
     prisoner_location_index = random.randrange(self.prisoner_locations.count())
     prisoner_location = self.prisoner_locations[prisoner_location_index]
     return {
         'prisoner_number': prisoner_location.prisoner_number,
         'prisoner_dob': format_date(prisoner_location.prisoner_dob, 'Y-m-d'),
     }
示例#4
0
 def get_valid_data(self):
     # theoretically, a valid query for GET
     prisoner_location_index = random.randrange(self.prisoner_locations.count())
     prisoner_location = self.prisoner_locations[prisoner_location_index]
     return {
         'prisoner_number': prisoner_location.prisoner_number,
         'prisoner_dob': format_date(prisoner_location.prisoner_dob, 'Y-m-d'),
     }
 def credit_link(self, instance):
     link = reverse('admin:credit_credit_change', args=(instance.credit.pk,))
     description = '%(amount)s %(status)s, %(date)s' % {
         'amount': format_amount(instance.amount),
         'status': instance.credit.resolution,
         'date': format_date(timezone.localtime(instance.credit.created), 'd/m/Y'),
     }
     return format_html('<a href="{}">{}</a>', link, description)
示例#6
0
 def credit_link(self, instance):
     credit = instance.credit
     link = reverse('admin:credit_credit_change', args=(credit.pk, ))
     description = '%(amount)s %(status)s, %(date)s' % {
         'amount': format_amount(credit.amount),
         'status': credit.resolution,
         'date': format_date(timezone.localtime(credit.created), 'd/m/Y'),
     }
     return format_html('<a href="{}">{}</a>', link, description)
 def describe_filter__received_at(self, query_data, get_query,
                                  descriptions):
     received_at__gte = query_data.get('received_at__gte')
     received_at__lt = query_data.get('received_at__lt')
     if received_at__gte or received_at__lt:
         if received_at__gte and received_at__lt:
             label = 'Received between %s and %s' % (format_date(
                 received_at__gte,
                 'j N Y'), format_date(received_at__lt, 'j N Y'))
         elif received_at__gte:
             label = 'Received since %s' % format_date(
                 received_at__gte, 'j N Y')
         else:
             label = 'Received before %s' % format_date(
                 received_at__lt, 'j N Y')
         descriptions.append(
             (label, get_query('received_at__gte', 'received_at__lt')))
     return {'received_at__gte', 'received_at__lt'}
 def settlement_link(self, instance):
     settlement = instance.settlement_transaction
     if settlement is None:
         return '–'
     link = reverse('admin:transaction_transaction_change', args=(settlement.pk,))
     description = '%(amount)s, %(date)s' % {
         'amount': format_amount(settlement.amount),
         'date': format_date(timezone.localtime(settlement.received_at), 'd/m/Y'),
     }
     return format_html('<a href="{}">{}</a>', link, description)
 def settlement_link(self, instance):
     settlement = instance.settlement_transaction
     if settlement is None:
         return '–'
     link = reverse('admin:transaction_transaction_change',
                    args=(settlement.pk, ))
     description = '%(amount)s, %(date)s' % {
         'amount':
         format_amount(settlement.amount),
         'date':
         format_date(timezone.localtime(settlement.received_at), 'd/m/Y'),
     }
     return format_html('<a href="{}">{}</a>', link, description)
示例#10
0
def comment_details(request, comment):
    extension = comment.content_object
    gravatar = gravatar_url(request, comment.email)
    is_extension_creator = (comment.user == extension.creator)

    details = dict(gravatar = gravatar,
                   is_extension_creator = is_extension_creator,
                   comment = comment.comment,
                   author = dict(username=comment.user.username,
                                 url=reverse('auth-profile', kwargs=dict(user=comment.user.username))),
                   date = dict(timestamp = comment.submit_date.isoformat(),
                               standard = format_date(comment.submit_date, 'F j, Y')))

    if comment.rating > -1:
        details['rating'] = comment.rating

    return details
示例#11
0
def comment_details(request, comment):
    extension = comment.content_object
    gravatar = gravatar_url(request, comment.email)
    is_extension_creator = (comment.user == extension.creator)
    username = comment.user.username if comment.user else "nobody"

    details = dict(gravatar=gravatar,
                   is_extension_creator=is_extension_creator,
                   comment=linebreaks(comment.comment, autoescape=True),
                   author=dict(username=username,
                               url=reverse('auth-profile',
                                           kwargs=dict(user=username))),
                   date=dict(timestamp=comment.submit_date.isoformat(),
                             standard=format_date(comment.submit_date,
                                                  'F j, Y')))

    if comment.rating > -1:
        details['rating'] = comment.rating

    return details
示例#12
0
文件: models.py 项目: akx/kompassi
    payments_event_meta = event_meta_property('payments', 'payments.models:PaymentsEventMeta')
    sms_event_meta = event_meta_property('sms', 'sms.models:SMSEventMeta')

    def app_event_meta(self, app_label):
        return getattr(self, '{}_event_meta'.format(app_label))

    def as_dict(self):
        return pick_attrs(self,
            'slug',
            'name',
        )


EMAIL_LENGTH = PHONE_NUMBER_LENGTH = 255
BIRTH_DATE_HELP_TEXT = u'Syntymäaika muodossa {0}'.format(
    format_date(date(1994, 2, 24), settings.DATE_FORMAT)
)
NAME_DISPLAY_STYLE_CHOICES = [
    (u'firstname_nick_surname', u'Etunimi "Nick" Sukunimi'),
    (u'firstname_surname', u'Etunimi Sukunimi'),
    (u'firstname', u'Etunimi'),
    (u'nick', u'Nick'),
]
NAME_DISPLAY_STYLE_FORMATS = dict(
    firstname=u'{self.first_name}',
    firstname_nick_surname=u'{self.first_name} "{self.nick}" {self.surname}',
    firstname_surname=u'{self.first_name} {self.surname}',
    nick=u'{self.nick}',
)

示例#13
0
# encoding: utf-8

from datetime import date

from django.conf import settings
from django.utils.dateformat import format as format_date
from django.utils.translation import ugettext_lazy as _

EMAIL_LENGTH = PHONE_NUMBER_LENGTH = 255

# TODO how do I localize this
BIRTH_DATE_HELP_TEXT = 'Syntymäaika muodossa {0}'.format(
    format_date(date(1994, 2, 24), settings.DATE_FORMAT))

NAME_DISPLAY_STYLE_CHOICES = [
    ('firstname_nick_surname', _('Firstname "Nickname" Surname')),
    ('firstname_surname', _('Firstname Surname')),
    ('firstname', _('Firstname')),
    ('nick', _('Nickname')),
]

NAME_DISPLAY_STYLE_FORMATS = dict(
    firstname='{self.first_name}',
    firstname_nick_surname='{self.first_name} "{self.nick}" {self.surname}',
    firstname_surname='{self.first_name} {self.surname}',
    nick='{self.nick}',
)
示例#14
0
    async def receive(self, text_data=None, bytes_data=None):
        if not self.scope['user'].is_authenticated:
            await self.close(code=4001)
            return

        user_name = self.scope['user'].get_full_name()
        user_id = self.scope['user'].username
        json_data = json.loads(text_data)
        request_type = json_data['request_type']

        try:
            author_id = await self.get_content_author()

            if request_type == 'new_discussion':
                text = json_data['text']
                discussion = await self.save_discussion_message(text)
                date = format_date(discussion.date, settings.DATETIME_FORMAT)
                await self.channel_layer.group_send(
                    self.discussion_thread, {
                        'type': 'discussion_message',
                        'node_id': discussion.id,
                        'author_id': author_id,
                        'user_id': user_id,
                        'user_name': user_name,
                        'date': date,
                        'text': text
                    })
            elif request_type == 'new_reply':
                text = json_data['text']
                thread_id = json_data['target_id']
                # date = await self.save_reply_message(thread_id, text).strftime('%B %-d, %Y, %-I:%M %p')
                response = await self.save_reply_message(thread_id, text)
                date = format_date(response.date, settings.DATETIME_FORMAT)
                await self.channel_layer.group_send(
                    self.discussion_thread, {
                        'type': 'reply_message',
                        'target_id': thread_id,
                        'node_id': response.id,
                        'author_id': author_id,
                        'user_id': user_id,
                        'user_name': user_name,
                        'date': date,
                        'text': text
                    })
            elif request_type == 'edit_discussion':
                text = json_data['text']
                thread_id = json_data['node_id']
                discussion = await self.update_discussion_message(
                    thread_id, text)
                date = format_date(discussion.date, settings.DATETIME_FORMAT)
                await self.channel_layer.group_send(
                    self.discussion_thread, {
                        'type': 'update_discussion',
                        'author_id': author_id,
                        'user_id': user_id,
                        'node_id': thread_id,
                        'date': date,
                        'text': text
                    })
            elif request_type == 'edit_reply':
                text = json_data['text']
                thread_id = json_data['node_id']
                response = await self.update_reply_message(thread_id, text)
                date = format_date(response.date, settings.DATETIME_FORMAT)
                await self.channel_layer.group_send(
                    self.discussion_thread, {
                        'type': 'update_reply',
                        'author_id': author_id,
                        'user_id': user_id,
                        'node_id': thread_id,
                        'date': date,
                        'text': text
                    })
            elif request_type == 'delete_discussion':
                thread_id = json_data['node_id']
                await self.remove_discussion_message(thread_id)
                await self.channel_layer.group_send(
                    self.discussion_thread, {
                        'type': 'remove_discussion',
                        'author_id': author_id,
                        'user_id': user_id,
                        'node_id': thread_id,
                    })
            elif request_type == 'delete_reply':
                thread_id = json_data['node_id']
                await self.remove_reply_message(thread_id)
                await self.channel_layer.group_send(
                    self.discussion_thread, {
                        'type': 'remove_reply',
                        'author_id': author_id,
                        'user_id': user_id,
                        'node_id': thread_id,
                    })
            else:
                await self.close(code=4001)
        except (Content.DoesNotExist, DiscussionThread.DoesNotExist,
                RepliesThread.DoesNotExist, PermissionDenied):
            await self.close(code=4001)
def bank_transfer_reference(prisoner_number, prisoner_dob):
    return '%s/%s' % (prisoner_number, format_date(prisoner_dob, 'd/m/Y'))
def serialise_date(date):
    return format_date(date, 'Y-m-d')
示例#17
0
 def stats(self):
     return [
         ('enrolled on',
          format_date(self.enrollment_date, settings.DATETIME_FORMAT)),
     ]
示例#18
0
 def stats(self):
     return [
         ('registered on',
          format_date(self.registration_date, settings.DATETIME_FORMAT)),
     ]
示例#19
0
    def __str__(self):
        n = self.card_number
        d = format_date(self.expiration_date, settings.DATE_FORMAT)

        return "{n}, voimassa {d} asti".format(**locals())
示例#20
0
文件: models.py 项目: wizzu/kompassi
    def __str__(self):
        n = self.card_number
        d = format_date(self.expiration_date, settings.DATE_FORMAT)

        return "{n}, voimassa {d} asti".format(**locals())
示例#21
0
 def get_date(date_key):
     date = self.cleaned_data.get(date_key)
     if date:
         return format_date(date, 'd/m/Y')
示例#22
0
 def get_invalid_string_prisoner_dob(self, cannot_equal):
     while True:
         prisoner_dob = random_prisoner_dob()
         prisoner_dob = format_date(prisoner_dob, 'Y-m-d')
         if prisoner_dob != cannot_equal:
             return prisoner_dob
示例#23
0
    def get_date_range(self):
        date_range = self.cleaned_data['date_range'] or self[
            'date_range'].field.initial
        if date_range == 'custom' and (self.cleaned_data.get('start_date')
                                       or self.cleaned_data.get('end_date')):
            received_at_start = self.cleaned_data.get('start_date',
                                                      self.earliest)
            received_at_end = self.cleaned_data.get('end_date', self.latest)
            if received_at_start == received_at_end:
                short_title = format_date(received_at_start, 'j M Y')
            else:
                if received_at_start.replace(day=1) == received_at_end.replace(
                        day=1):
                    from_date_format = 'j'
                elif received_at_start.replace(
                        month=1, day=1) == received_at_end.replace(month=1,
                                                                   day=1):
                    from_date_format = 'j M'
                else:
                    from_date_format = 'j M Y'
                short_title = _('%(from)s to %(to)s') % {
                    'from': format_date(received_at_start, from_date_format),
                    'to': format_date(received_at_end, 'j M Y')
                }
            return {
                'range': (received_at_start, received_at_end),
                'short_title': short_title,
                'title': short_title,
            }
        elif date_range in ('this_week', 'last_week', 'four_weeks',
                            'this_month', 'last_month'):
            received_at_start, received_at_end = getattr(self, date_range)
            short_title = dict(self['date_range'].field.choices)[date_range]
            if date_range in ('this_month', 'last_month'):
                month = format_date(received_at_start, 'N Y')
                title = '%(title)s, %(month)s' % {
                    'title': short_title,
                    'month': month,
                }
                short_title = month
            else:
                title = '%(title)s, commencing %(day)s' % {
                    'title': short_title,
                    'day': format_date(received_at_start, 'j N'),
                }
            return {
                'range': (received_at_start, received_at_end),
                'short_title': short_title,
                'title': title,
            }
        elif date_range in ('today', 'yesterday'):
            received_at = getattr(self, date_range)
            short_title = dict(self['date_range'].field.choices)[date_range]
            return {
                'range': (received_at, ),
                'short_title': short_title,
                'title': '%(title)s, %(day)s' % {
                    'title': short_title,
                    'day': format_date(received_at, 'j N'),
                },
            }

        # all time
        return {
            'range': (),
            'short_title': _('Since the beginning'),
            'title': _('Since the beginning'),
        }
def serialise_date(date):
    return format_date(date, 'Y-m-d')
 def get_invalid_string_prisoner_dob(self, cannot_equal):
     while True:
         prisoner_dob = random_prisoner_dob()
         prisoner_dob = format_date(prisoner_dob, 'Y-m-d')
         if prisoner_dob != cannot_equal:
             return prisoner_dob
    def get_date_range(self):
        date_range = self.cleaned_data['date_range'] or self['date_range'].field.initial
        if date_range == 'custom' and (self.cleaned_data.get('start_date') or self.cleaned_data.get('end_date')):
            received_at_start = self.cleaned_data.get('start_date', self.earliest)
            received_at_end = self.cleaned_data.get('end_date', self.latest)
            if received_at_start == received_at_end:
                short_title = format_date(received_at_start, 'j M Y')
            else:
                if received_at_start.replace(day=1) == received_at_end.replace(day=1):
                    from_date_format = 'j'
                elif received_at_start.replace(month=1, day=1) == received_at_end.replace(month=1, day=1):
                    from_date_format = 'j M'
                else:
                    from_date_format = 'j M Y'
                short_title = _('%(from)s to %(to)s') % {
                    'from': format_date(received_at_start, from_date_format),
                    'to': format_date(received_at_end, 'j M Y')
                }
            return {
                'range': (received_at_start, received_at_end),
                'short_title': short_title,
                'title': short_title,
            }
        elif date_range in ('this_week', 'last_week', 'four_weeks', 'this_month', 'last_month'):
            received_at_start, received_at_end = getattr(self, date_range)
            short_title = dict(self['date_range'].field.choices)[date_range]
            if date_range in ('this_month', 'last_month'):
                month = format_date(received_at_start, 'N Y')
                title = '%(title)s, %(month)s' % {
                    'title': short_title,
                    'month': month,
                }
                short_title = month
            else:
                title = '%(title)s, commencing %(day)s' % {
                    'title': short_title,
                    'day': format_date(received_at_start, 'j N'),
                }
            return {
                'range': (received_at_start, received_at_end),
                'short_title': short_title,
                'title': title,
            }
        elif date_range in ('today', 'yesterday'):
            received_at = getattr(self, date_range)
            short_title = dict(self['date_range'].field.choices)[date_range]
            return {
                'range': (received_at,),
                'short_title': short_title,
                'title': '%(title)s, %(day)s' % {
                    'title': short_title,
                    'day': format_date(received_at, 'j N'),
                },
            }

        # all time
        return {
            'range': (),
            'short_title': _('Since the beginning'),
            'title': _('Since the beginning'),
        }
示例#27
0
 def _format_date(self, date):
     return format_date(date, 'Y-m-d')
 def _format_date(self, date):
     return format_date(date, 'Y-m-d')