Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import datetime
from django.utils import timezone
from django.db import models
from lino.api import dd
class Poll(dd.Model):
question = models.CharField("Question text", max_length=200)
hidden = models.BooleanField(
"Hidden",
help_text="Whether this poll should not be shown in the main window.",
default=False)
#~ pub_date = models.DateTimeField('Date published',auto_now_add=True)
pub_date = models.DateTimeField('Date published', default=dd.today)
class Meta:
verbose_name = 'Poll'
verbose_name_plural = 'Polls'
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(dd.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField("Choice text", max_length=200)
votes = models.IntegerField("No. of votes", default=0)
def param_defaults(self, ar, **kw):
mi = ar.master_instance
kw = super(TicketsBySite, self).param_defaults(ar, **kw)
kw.update(interesting_for=mi)
kw.update(end_date=dd.today())
kw.update(observed_event=TicketEvents.todo)
return kw
def full_clean(self, *args, **kw):
if not self.start_date:
self.start_date = dd.today()
super(Board, self).full_clean(*args, **kw)
def get_default_start_date(self):
return dd.today().replace(month=1, day=1)
# D = datetime.date
"Oops, %s returned %d rows." % (qs.query, qs.count()))
ar.success(refresh=True)
# dd.logger.info("20140930 %s", obj)
@dd.python_2_unicode_compatible
class Response(UserAuthored, mixins.Registrable):
class Meta(object):
app_label = 'polls'
verbose_name = _("Response")
verbose_name_plural = _("Responses")
ordering = ['date']
poll = dd.ForeignKey('polls.Poll', related_name='responses')
date = models.DateField(_("Date"), default=dd.today)
state = ResponseStates.field(default=ResponseStates.draft.as_callable)
remark = models.TextField(verbose_name=_("My general remark"), blank=True)
partner = dd.ForeignKey('contacts.Partner', blank=True, null=True)
toggle_choice = ToggleChoice()
@dd.chooser()
def poll_choices(cls):
return Poll.objects.filter(state=PollStates.published)
def __str__(self):
if self.partner is None:
return _("%(user)s's response to %(poll)s") % dict(
user=self.user, poll=self.poll)
return _("{poll} {partner} {date}").format(
user=self.user.initials,
if qs2.count():
# i = (cct, Cycler(qs2))
l.append(Cycler(qs2))
RECIPIENTS = Cycler(l)
ACCOUNTS = Cycler(Account.objects.filter(
chart=AccountCharts.default, type=AccountTypes.expenses))
AMOUNTS = Cycler(10, '12.50', 25, '29.95', 120, '5.33')
ses = rt.login('robin')
PRC = Journal.get_by_ref('PRC')
for i in range(20):
kw = dict()
kw.update(partner=RECIPIENTS.pop())
if i % 9 != 0:
kw.update(project=CLIENTS.pop())
kw.update(date=dd.today(-5*i))
kw.update(journal=PRC)
kw.update(user=ses.get_user())
obj = Invoice(**kw)
yield obj
yield InvoiceItem(
voucher=obj, amount=AMOUNTS.pop(), account=ACCOUNTS.pop())
if i % 5 == 0:
yield InvoiceItem(
voucher=obj, amount=AMOUNTS.pop(), account=ACCOUNTS.pop())
obj.register(ses)
obj.save()
if ar is None:
return E.div(**attrs)
must_read = False
elems = []
if self.card_number:
elems += ["%s %s (%s)" %
(ugettext("Card no."), self.card_number, self.card_type)]
if self.card_issuer:
elems.append(", %s %s" %
(ugettext("issued by"), self.card_issuer))
#~ card_issuer = _("issued by"),
if self.card_valid_until is not None:
valid = ", %s %s %s %s" % (
ugettext("valid from"), dd.dtos(self.card_valid_from),
ugettext("until"), dd.dtos(self.card_valid_until))
if self.card_valid_until < dd.today():
must_read = True
elems.append(E.b(valid))
elems.append(E.br())
else:
elems.append(valid)
else:
must_read = True
else:
must_read = True
if must_read:
msg = _("Must read eID card!")
if config:
elems.append(ar.instance_action_button(
self.read_beid, msg, icon_name=None))
else:
def objects():
ar = rt.login('robin')
now = datetime.datetime.combine(dd.today(), i2t(548))
for u in rt.models.users.User.objects.all():
yield rt.models.notify.Message.create_message(
ar, u, subject="Database initialized",
created=now,
body="Hello world", sent=now)
def date(self):
"Used in templates"
if self.build_time:
return self.build_time.date()
return dd.today()
"""
required_roles = dd.login_required(LedgerStaff)
item_class = FiscalYear
verbose_name = _("Fiscal Year")
verbose_name_plural = _("Fiscal Years")
# ~ preferred_width = 4 # would be 2 otherwise
@classmethod
def from_int(cls, year):
return cls.get_by_value(str(year)[2:])
@classmethod
def from_date(cls, date):
return cls.from_int(date.year)
for y in range(settings.SITE.start_year, dd.today().year + 5):
s = str(y)
FiscalYears.add_item(s[2:], s)
class VoucherType(dd.Choice):
def __init__(self, model, table_class):
self.table_class = table_class
model = dd.resolve_model(model)
self.model = model
value = dd.full_model_name(model)
text = model._meta.verbose_name + ' (%s)' % dd.full_model_name(model)
# text = model._meta.verbose_name + ' (%s.%s)' % (
# model.__module__, model.__name__)
name = None
super(VoucherType, self).__init__(value, text, name)