Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#~ f.write(jscompress(unicode(tpl)+'\n'))
f.write(jscompress(tpl.render(**context) + '\n'))
env = settings.SITE.plugins.jinja.renderer.jinja_env
for p in settings.SITE.installed_plugins:
if isinstance(p, Plugin):
for tplname in p.site_js_snippets:
tpl = env.get_template(tplname)
f.write(jscompress('\n// from %s:%s\n' % (p, tplname)))
f.write(jscompress('\n' + tpl.render(**context) + '\n'))
menu = settings.SITE.get_site_menu(self, profile)
menu.add_item(
'home', _("Home"), javascript="Lino.handle_home_button()")
f.write("Lino.main_menu = %s;\n" % py2js(menu))
"""Call Ext.namespace for *all* actors because
e.g. outbox.Mails.FormPanel is defined in ns outbox.Mails
which is not directly used by non-expert users.
"""
for a in self.actors_list:
f.write("Ext.namespace('Lino.%s')\n" % a)
# actors with their own `get_handle_name` don't have a js
# implementation
actors_list = [
a for a in self.actors_list if a.get_handle_name is None]
# generate only actors whose default_action is visible
actors_list = [
def fn():
yield "// lino.js --- generated %s by %s for %s." % (
time.ctime(), escape(settings.SITE.site_version()),
get_user_profile())
# lino.__version__)
#~ // $site.title ($lino.welcome_text())
if self.extjs_version == 3:
yield "Ext.BLANK_IMAGE_URL = '%s';" % extjs.build_lib_url(
'resources/images/default/s.gif')
yield "LANGUAGE_CHOICES = %s;" % py2js(
list(settings.SITE.LANGUAGE_CHOICES))
yield "MEDIA_URL = %s;" % py2js(settings.SITE.build_media_url())
yield "GEN_TIMESTAMP = %s;" % py2js(rt.settings.SITE.kernel.code_mtime)
def fn():
yield "// lino.js --- generated %s by %s for %s." % (
time.ctime(), escape(settings.SITE.site_version()),
get_user_profile())
# lino.__version__)
#~ // $site.title ($lino.welcome_text())
if self.extjs_version == 3:
yield "Ext.BLANK_IMAGE_URL = '%s';" % extjs.build_lib_url(
'resources/images/default/s.gif')
yield "LANGUAGE_CHOICES = %s;" % py2js(
list(settings.SITE.LANGUAGE_CHOICES))
yield "MEDIA_URL = %s;" % py2js(settings.SITE.build_media_url())
yield "GEN_TIMESTAMP = %s;" % py2js(rt.settings.SITE.kernel.code_mtime)
def js_render_GridPanel_class(self, rh):
yield ""
yield "// js_render_GridPanel_class %s" % rh.actor
yield "Lino.%s.GridPanel = Ext.extend(Lino.GridPanel,{" % rh.actor
kw = dict()
#~ kw.update(empty_title=%s,rh.actor.get_button_label()
if getattr(rh.actor,'use_detail_params_value',None):
kw.update(use_detail_params_value=True)
kw.update(ls_url=rh.actor.actor_url())
if not hasattr(rh, 'store'):
raise AttributeError("20200128 {} has no store".format(rh))
kw.update(ls_store_fields=[js_code(f.as_js(f.name))
for f in rh.store.list_fields])
if rh.store.pk is not None:
kw.update(ls_id_property=rh.store.pk.name)
kw.update(pk_index=rh.store.pk_index)
if settings.SITE.is_installed('contenttypes'):
m = getattr(rh.store.pk, 'model', None)
# e.g. pk may be the VALUE_FIELD of a choicelist which
# has no model
if m is not None:
ct = ContentType.objects.get_for_model(m).pk
kw.update(content_type=ct)
kw.update(cell_edit=rh.actor.cell_edit)
kw.update(focus_on_quick_search=rh.actor.focus_on_quick_search)
kw.update(ls_bbar_actions=self.toolbar(
rh.actor.get_toolbar_actions(rh.actor.default_action.action)))
def js_render_GridPanel_class(self, rh):
yield ""
yield "// js_render_GridPanel_class %s" % rh.actor
yield "Lino.%s.GridPanel = Ext.extend(Lino.GridPanel,{" % rh.actor
kw = dict()
#~ kw.update(empty_title=%s,rh.actor.get_button_label()
kw.update(ls_url=rh.actor.actor_url())
kw.update(ls_store_fields=[js_code(f.as_js(f.name))
for f in rh.store.list_fields])
if rh.store.pk is not None:
kw.update(ls_id_property=rh.store.pk.name)
kw.update(pk_index=rh.store.pk_index)
if settings.SITE.is_installed('contenttypes'):
m = getattr(rh.store.pk, 'model', None)
# e.g. pk may be the VALUE_FIELD of a choicelist which
# has no model
if m is not None:
ct = ContentType.objects.get_for_model(m).pk
kw.update(content_type=ct)
kw.update(cell_edit=rh.actor.cell_edit)
kw.update(ls_bbar_actions=self.toolbar(
rh.actor.get_toolbar_actions(rh.actor.default_action.action)))
kw.update(ls_grid_configs=[gc.data for gc in rh.actor.grid_configs])
def objects():
aType = Instantiator('attestations.AttestationType', "name").build
yield aType(_("Default"), build_method='appyodt', template='Default.odt')
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,
def unused_js_main(self):
for ln in MasterWrapper.js_main(self):
yield ln
yield "this.refresh = function() { console.log('DetailMasterWrapper.refresh() is not implemented') };"
yield "this.get_current_record = function() { return this.current_record;};"
yield "this.get_selected = function() {"
yield " return this.current_record.id;"
yield "}"
yield "this.load_record = function(record) {"
yield " this.current_record = record;"
yield " if (record) this.main_panel.form.loadRecord(record)"
yield " else this.main_panel.form.reset();"
yield "};"
#~ yield "this.load_record(%s);" % py2js(ext_store.Record(self.datalink.store,object))
yield "var fn = Ext.data.Record.create(%s)" % \
py2js([js_code(f.as_js()) for f in self.rh.store.fields])
d = self.rh.store.row2dict(self.rh.row)
yield "this.load_record(fn(%s));" % py2js(d)
def objects():
Project = rt.modules.tickets.Project
Milestone = rt.modules.tickets.Milestone
Ticket = rt.modules.tickets.Ticket
User = rt.modules.users.User
TicketStates = rt.modules.tickets.TicketStates
states = set()
for n, row in enumerate(codecs.open(fn, encoding="utf-8").readlines()):
if n == 0:
continue # headers
if not row:
continue
cells = row.split('\t')
if len(cells) != len(COLUMNS):
msg = "Oops, line {0} has {1} cells".format(n, len(cells))
raise Exception(msg)