Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from django.db import models
from django.contrib.contenttypes.models import ContentType
from lino.api import dd
from lino.core.gfks import GenericForeignKey
class Member(dd.Model):
name = models.CharField(max_length=200)
email = models.EmailField(max_length=200, blank=True)
def __unicode__(self):
return self.name
class Comment(dd.Model):
allow_cascaded_delete = ['owner']
owner_type = dd.ForeignKey(ContentType)
owner_id = models.PositiveIntegerField()
owner = GenericForeignKey('owner_type', 'owner_id')
text = models.CharField(max_length=200)
class Note(dd.Model):
owner_type = dd.ForeignKey(ContentType)
owner_id = models.PositiveIntegerField()
owner = GenericForeignKey('owner_type', 'owner_id')
text = models.CharField(max_length=200)
from __future__ import unicode_literals
from django.db import models
from lino.api import dd
@dd.python_2_unicode_compatible
class Person(dd.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
@ddpython_2_unicode_compatible
class Place(dd.Model):
name = models.CharField(max_length=50)
owners = models.ManyToManyField(Person, related_name="owned_places")
ceo = models.ForeignKey(Person, related_name="managed_places")
def __str__(self):
if self.get_restaurant():
if self.get_bar():
what = "Restaurant & Bar "
else:
what = "Restaurant "
elif self.get_bar():
what = "Bar "
else:
what = ''
return "%s %s(ceo=%s,owners=%s)" % (
self.name, what, self.ceo,
from __future__ import unicode_literals
from __future__ import print_function
from builtins import object
from django.utils.translation import ugettext_lazy as _
from lino.api import rt, dd
from lino.utils.xmlgen.html import E
from lino.core.utils import ChangeWatcher
from lino.modlib.plausibility.choicelists import Checker
from .choicelists import AddressTypes
class AddressOwner(dd.Model):
"""Base class for the "addressee" of any address.
"""
class Meta(object):
abstract = True
def get_address_by_type(self, address_type):
Address = rt.modules.addresses.Address
try:
return Address.objects.get(
partner=self, address_type=address_type)
except Address.DoesNotExist:
return self.get_primary_address()
except Address.MultipleObjectsReturned:
return self.get_primary_address()
from django.db import models
from lino.api import dd
from lino.utils import join_elems
from lino.utils.xmlgen.html import E
from lino.mixins.polymorphic import Polymorphic
class Place(dd.Model):
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Member(Polymorphic):
name = models.CharField(max_length=200)
place = models.ForeignKey(Place, blank=True, null=True)
email = models.EmailField(max_length=200, blank=True)
def __unicode__(self):
return self.name
class Customer(Member):
fkw.update(satisfied=False)
if partner:
fkw.update(partner=partner)
qs = rt.modules.ledger.Movement.objects.filter(**fkw)
qs = qs.order_by('voucher__date')
#~ qs = qs.distinct('match')
return qs
# return qs.values_list('match', flat=True)
@dd.chooser()
def match_choices(cls, journal, partner):
# todo: move this to implementing classes?
return cls.get_match_choices(journal, partner)
class VoucherItem(dd.Model):
"""Base class for items of a voucher.
Subclasses must define the following fields:
.. attribute:: voucher
Pointer to the voucher which contains this item. Non
nullable. The voucher must be a subclass of
:class:`ledger.Voucher`.
The `related_name` must be `'items'`.
.. attribute:: title
The title of this voucher.
return
existing = set([g.partner.pk for g in obj.guest_set.all()])
if len(existing) == 0:
suggested = list(obj.suggest_guests())
if len(suggested) > 0:
msg = _("No participants although {0} suggestions exist.")
yield (True, msg.format(len(suggested)))
if fix:
for g in suggested:
g.save()
EventChecker.activate()
@dd.python_2_unicode_compatible
class Guest(dd.Model):
"""Represents the fact that a given person is expected to attend to a
given event.
TODO: Rename this to "Presence".
"""
workflow_state_field = 'state'
allow_cascaded_delete = ['event']
class Meta(object):
app_label = 'cal'
abstract = dd.is_abstract_model(__name__, 'Guest')
verbose_name = _("Participant")
verbose_name_plural = _("Participants")
from django.db import models
from lino.api import dd
class PartnerType(dd.Model):
name = models.CharField("Name", max_length=20)
class Partner(dd.Model):
class Meta:
verbose_name = "Partner"
verbose_name_plural = "Partners"
type = models.ForeignKey(PartnerType)
name = models.CharField("Name", max_length=30)
class Person(Partner):
first_name = models.CharField("First name", max_length=20)
last_name = models.CharField("Last name", max_length=20)
class Meta:
verbose_name = "Person"
verbose_name_plural = "Persons"
from lino.modlib.ledger.mixins import (
PartnerRelated, ProjectRelated, VoucherItem)
from .utils import ZERO, ONE
from .choicelists import VatClasses, VatRegimes
def get_default_vat_regime():
return dd.plugins.vat.default_vat_regime
def get_default_vat_class():
return dd.plugins.vat.default_vat_class
class VatTotal(dd.Model):
"""Model mixin which defines the fields `total_incl`, `total_base`
and `total_vat`. Used for both the document header
(:class:`VatDocument`) and for each item (:class:`VatItemBase`).
.. attribute:: total_incl
A :class:`lino.core.fields.PriceField` which stores the total
amount VAT *included*.
.. attribute:: total_base
A :class:`lino.core.fields.PriceField` which stores the total
amount VAT *excluded*.
.. attribute:: total_vat
# app_label = 'lino'
verbose_name = _("Change Type")
verbose_name_plural = _("Change Types")
add = ChangeTypes.add_item
add('C', _("Create"), 'create')
add('U', _("Update"), 'update')
add('D', _("Delete"), 'delete')
add('R', _("Remove child"), 'remove_child')
add('A', _("Add child"), 'add_child')
add('M', _("Merge"), 'merge')
class Change(dd.Model):
"""A registered change in the database.
Each database change of a watched object will generate one Change
record.
.. attribute:: master
The database object which acts as "master".
.. attribute:: object
The database object which has been modified.
"""
p = Posting(
user=ar.user, owner=elem,
partner=rec,
date=dd.today(),
state=PostingStates.ready)
p.full_clean()
p.save()
kw.update(refresh=True)
ar.success(**kw)
msg = _("Going to create %(num)d postings for %(elem)s") % dict(
num=len(recs), elem=elem)
ar.confirm(ok, msg)
class Postable(dd.Model):
"""
Mixin for models that provide a "Post" button.
"""
class Meta(object):
abstract = True
create_postings = CreatePostings()
#~ def print_from_posting(self,posting,ar,**kw):
#~ return ar.error("Not implemented")
def get_postable_recipients(self):
return []
def get_recipients(self):