How to use the lino.api.dd.required function in lino

To help you get started, we’ve selected a few lino examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lino-framework / lino / lino / modlib / tickets / ui.py View on Github external
column_names = "ref name *"


class ProjectsByType(Projects):
    master_key = 'type'
    column_names = "ref name *"


class ProjectsByCompany(Projects):
    master_key = 'company'
    column_names = "ref name *"


class Links(dd.Table):
    model = 'tickets.Link'
    required_roles = dd.required(dd.SiteStaff)
    stay_in_grid = True
    detail_layout = dd.FormLayout("""
    parent
    type
    child
    """, window_size=(40, 'auto'))


class LinksByTicket(Links):

    label = _("Dependencies")
    required_roles = dd.required()
    master = 'tickets.Ticket'
    column_names = 'parent type_as_parent:10 child'
    slave_grid_format = 'summary'
github lino-framework / lino / lino / modlib / rooms / models.py View on Github external
import logging
logger = logging.getLogger(__name__)

from django.db import models
from django.conf import settings

from lino.api import dd, _
from lino import mixins

from lino.modlib.cal.choicelists import Recurrencies
from lino.modlib.cal.mixins import Reservation
from lino.modlib.contacts.mixins import ContactRelated


class BookingStates(dd.Workflow):
    required_roles = dd.required(dd.SiteStaff)

add = BookingStates.add_item
add('10', _("Draft"), 'draft', editable=True)
add('20', _("Option"), 'option', editable=False)
add('30', _("Registered"), 'registered', editable=False)
add('40', _("Cancelled"), 'cancelled', editable=False)


@dd.receiver(dd.pre_analyze)
def setup_rooms_workflow(sender=None, **kw):

    #~ BookingStates.draft.add_transition(
        #~ states='option registered cancelled',
        #~ icon_name="pencil")
    #~ BookingStates.registered.add_transition(_("Register"),
        #~ states='draft option',
github lino-framework / lino / lino / modlib / cal / models_task.py View on Github external
    @classmethod
    def on_analyze(cls, lino):
        #~ lino.TASK_AUTO_FIELDS = dd.fields_list(cls,
        cls.DISABLED_AUTO_FIELDS = dd.fields_list(
            cls, """start_date start_time summary""")
        super(Task, cls).on_analyze(lino)

    #~ def __unicode__(self):
        # ~ return "#" + str(self.pk)


class Tasks(dd.Table):
    help_text = _("""A calendar task is something you need to do.""")
    model = 'cal.Task'
    required_roles = dd.required(OfficeStaff)
    column_names = 'start_date summary workflow_buttons *'
    order_by = ["start_date", "start_time"]

    detail_layout = """
    start_date due_date id workflow_buttons
    summary
    user project
    #event_type owner created:20 modified:20
    description #notes.NotesByTask
    """

    insert_layout = dd.FormLayout("""
    summary
    user project
    """, window_size=(50, 'auto'))
github lino-framework / lino / lino / modlib / cal / ui.py View on Github external
#~ class MySubscriptions(Subscriptions, ByUser):
    #~ pass

#~ class SubscriptionsByCalendar(Subscriptions):
    #~ master_key = 'calendar'


class SubscriptionsByUser(Subscriptions):
    required_roles = dd.required(OfficeUser)
    master_key = 'user'
    auto_fit_column_widths = True


class SubscriptionsByCalendar(Subscriptions):
    required_roles = dd.required(OfficeUser)
    master_key = 'calendar'
    auto_fit_column_widths = True


def check_subscription(user, calendar):
    "Check whether the given subscription exists. If not, create it."
    Subscription = rt.modules.cal.Subscription
    if calendar is None:
        return
    try:
        Subscription.objects.get(user=user, calendar=calendar)
    except Subscription.DoesNotExist:
        sub = Subscription(user=user, calendar=calendar)
        sub.full_clean()
        sub.save()
github lino-framework / lino / lino / modlib / courses / models.py View on Github external
return self.course

    def get_invoiceable_qty(self):
        return self.places

    def get_body_template(self):
        """Overrides :meth:`lino.core.model.Model.get_body_template`."""
        return self.course.line.body_template

    def get_excerpt_title(self):
        return self.course.line.get_excerpt_title()


class Enrolments(dd.Table):
    #~ debug_permissions=20130531
    required_roles = dd.required(dd.SiteStaff)
    model = 'courses.Enrolment'
    stay_in_grid = True
    parameters = mixins.ObservedPeriod(
        author=dd.ForeignKey(
            settings.SITE.user_model, blank=True, null=True),
        state=EnrolmentStates.field(blank=True, null=True),
        course_state=CourseStates.field(
            _("Course state"), blank=True, null=True),
        participants_only=models.BooleanField(
            _("Participants only"),
            help_text=_(
                "Hide cancelled enrolments. "
                "Ignored if you specify an explicit enrolment state."),
            default=True),
    )
    params_layout = """start_date end_date author state \
github lino-framework / lino / lino / modlib / polls / models.py View on Github external
    @dd.action()
    def select_by_response(self, ar):
        mi = ar.master_instance
        dd.logger.info("20140929 %s", mi)
        if isinstance(mi, Response):
            AnswerChoice(response=mi, choice=self).save()


class Choices(dd.Table):
    model = 'polls.Choice'
    required_roles = dd.required(PollsStaff)


class ChoicesBySet(Choices):
    master_key = 'choiceset'
    required_roles = dd.required()


@dd.python_2_unicode_compatible
class Poll(UserAuthored, mixins.CreatedModified, Referrable):
    """A series of questions."""
    class Meta(object):
        app_label = 'polls'
        abstract = dd.is_abstract_model(__name__, 'Poll')
        verbose_name = _("Poll")
        verbose_name_plural = _("Polls")
        ordering = ['ref']

    title = models.CharField(_("Heading"), max_length=200)

    details = models.TextField(_("Details"), blank=True)
github lino-framework / lino / lino / modlib / reception / models.py View on Github external
kw.update(start_date=today)
        kw.update(end_date=today)
        return kw


if False:
    class ReceivedVisitors(cal.Guests):
        label = _("Received Visitors")
        help_text = _("Shows the visitors being received.")
        filter = Q(waiting_since__isnull=False,
                   busy_since__isnull=False, gone_since__isnull=True)
        column_names = 'since partner event__user event__summary \
        workflow_buttons'
        order_by = ['waiting_since']
        #~ checkout = CheckoutGuest()
        required_roles = dd.required(OfficeUser)
        auto_fit_column_widths = True

        @dd.displayfield(_('Since'))
        def since(self, obj, ar):
            # *received since* == *waiting until*
            return naturaltime(obj.busy_since)


# class ReceptionUser(SiteUser):
#     ored_roles = (OfficeUser(), OfficeOperator())
#     def satisfies(self, required_role):
#         is isinstance(OfficeUser, OfficeOperator

class Visitors(cal.Guests):
    """Common base class for the following tables:
github lino-framework / lino / lino / modlib / cal / models_calendar.py View on Github external
unique_together = ['user', 'calendar']

    manager_roles_required = OfficeStaff
    # manager_level_field = 'office_level'

    calendar = dd.ForeignKey(
        'cal.Calendar', help_text=_("The calendar you want to subscribe to."))

    is_hidden = models.BooleanField(
        _("hidden"), default=False,
        help_text=_("""Whether this subscription should "
        "initially be displayed as a hidden calendar."""))


class Subscriptions(dd.Table):
    required_roles = dd.required(OfficeStaff)
    model = 'cal.Subscription'
    order_by = ['calendar__name']
    #~ insert_layout = """
    #~ label
    #~ event_type
    #~ """
    #~ detail_layout = """
    #~ label user color
    #~ event_type team other_user room
    #~ description
    #~ """

#~ class MySubscriptions(Subscriptions, ByUser):
    #~ pass

#~ class SubscriptionsByCalendar(Subscriptions):
github lino-framework / lino / lino / modlib / clocking / ui.py View on Github external
    @classmethod
    def param_defaults(self, ar, **kw):
        kw = super(MySessionsByDate, self).param_defaults(ar, **kw)
        kw.update(start_date=dd.today())
        kw.update(end_date=dd.today())
        return kw

    @classmethod
    def create_instance(self, ar, **kw):
        kw.update(start_date=ar.param_values.start_date)
        return super(MySessions, self).create_instance(ar, **kw)


class WorkedHours(dd.VentilatingTable):
    required_roles = dd.required()
    label = _("Worked hours")
    hide_zero_rows = True
    parameters = ObservedPeriod(
        user=dd.ForeignKey('users.User', null=True, blank=True))
    params_layout = "start_date end_date user"
    # editable = False
    auto_fit_column_widths = True

    class Row(object):
        def __init__(self, ar, day):
            self.day = day
            self._root2tot = {}
            self._tickets = set()
            grand_tot = Duration()
            pv = dict(start_date=day, end_date=day)
            pv.update(observed_event=dd.PeriodEvents.active)
github lino-framework / lino / lino / modlib / beid / choicelists.py View on Github external
Excerpts from [1]:
    
    - Johan: A document type of 7 is used for bootstrap cards ? What
      is a bootstrap card (maybe some kind of test card?)  Danny: A
      bootstrap card was an eID card that was used in the early start
      of the eID card introduction to bootstrap the computers at the
      administration. This type is no longer issued.
    
    - Johan: A document type of 8 is used for a
      "habilitation/machtigings" card ? Is this for refugees or asylum
      seekers? Danny: A habilitation/machtigings card was aimed at
      civil servants. This type is also no longer used.
    
    """

    required_roles = dd.required(dd.SiteStaff)
    verbose_name = _("eID card type")
    verbose_name_plural = _("eID card types")

add = BeIdCardTypes.add_item
add('1', _("Belgian citizen"), "belgian_citizen")
# ,de=u"Belgischer Staatsbürger",fr=u"Citoyen belge"),
add('6', _("Kids card (< 12 year)"), "kids_card")
#,de=u"Kind unter 12 Jahren"),

#~ add('8', _("Habilitation"))
#,fr=u"Habilitation",nl=u"Machtiging")

add('11', _("Foreigner card A"), "foreigner_a")
        #~ nl=u"Bewijs van inschrijving in het vreemdelingenregister - Tijdelijk verblijf",
        #~ fr=u"Certificat d'inscription au registre des étrangers - Séjour temporaire",
        #~ de=u"Ausländerkarte A Bescheinigung der Eintragung im Ausländerregister - Vorübergehender Aufenthalt",