class MapBlock(Block): name = 'map' default_place = 'rightsidebar' help_text = _('Block that renders a google maps placed in a location') verbose_name = _('Maps Block') config_params = BaseBlock.config_params + [ params.Float( name="latitude", label=_("map latitude"), default=37.390925, ), params.Float( name="longitude", label=_("map longitude"), default=-5.994844, ), params.Integer( name="width", label=_("Map width"), default=200, ), params.Integer( name="height", label=_("Map height"), default=200, ), params.Integer( name="zoom", label=_("Map zoom"), default=4, ), params.Bool( name="render_ui", label=_("Render UI"), default=True, ), ] def render(self, request, place, context, *args, **kwargs): context = { 'zoom': self.get_config().get('zoom').get_value(), 'latitude': self.get_config().get('latitude').get_value(), 'longitude': self.get_config().get('longitude').get_value(), 'width': self.get_config().get('width').get_value(), 'height': self.get_config().get('height').get_value(), 'render_ui': self.get_config().get('render_ui').get_value(), 'MEDIA_URL': context.get('MEDIA_URL', settings.MEDIA_URL), 'GOOGLE_MAPS_API_KEY': context.get('GOOGLE_MAPS_API_KEY', ''), 'LANGUAGE_CODE': get_language(), 'reg_block': self.reg_item, 'request': context.get('request', None)} return self.render_block( request, template_name='maps/block_map.html', block_title=_('Map'), context=context, )
class BaseMenuBlock(object): config_params = BaseBlock.config_params + [ params.Integer(name='max_num_level', label=_('maximum number of levels to show'), default=-1) ] default_caching_params = { 'enabled': False, 'only_anonymous': True, 'vary_on_user': False, 'timeout': 3600, 'vary_on_url': True, 'vary_on_language': True, } @classmethod def get_models_refresh_cache(self): return [Menu] def get_max_level(self): max_value = self.get_config().get('max_num_level', None) if max_value: return max_value.get_value() return -1
class BaseSingleMenuBlock(BaseMenuBlock): config_params = BaseMenuBlock.config_params + [ params.Integer( name='max_num_items', label=_('maximum number of items without js collapsible'), default=-1) ] def get_max_num_items(self): max_num_items = self.get_config().get('max_num_items', None) if max_num_items: return max_num_items.get_value() return -1
class StandingOutSlideShowBlock(Block): name = 'standingout-slideshow' default_place = 'homepage' help_text = ugettext_lazy('Block with a jquery slideshow of standingouts') verbose_name = ugettext_lazy('Standing out Slide Show block') config_params = BaseBlock.config_params + [ params.Integer(name='limit', label=_('limit for standingouts in block'), default='5'), ] default_caching_params = { 'enabled': False, 'timeout': 3600, 'only_anonymous': True, 'vary_on_user': False, 'vary_on_url': True, 'vary_on_language': True, } @classmethod def get_models_refresh_cache(self): return [StandingOut, StandingOutCategory] def render(self, request, place, context, block_content_relation=None, *args, **kwargs): (category, created) = StandingOutCategory.objects.get_or_create(slug='slideshow') name_field = get_fallback_fieldname('name') if (created): setattr(category, name_field, 'slideshow') category.save() standingouts = StandingOut.objects.filter( standing_out_category=category) limit = self.get_config().get('limit', None) if limit: standingouts = standingouts[:limit.get_value()] return self.render_block(request, template_name='block_slideshow.html', block_title=_('Slideshow'), context={'standingouts': standingouts})
class PluginConfig(Plugin): name = 'Feedback' description = 'Feedback plugin' version = '0.0.1' url_prefixes = (('feedback', 'plugins.feedback.urls'), ) config_params = [ params.Integer(name='number_of_comments', label=_('Number of comment for each content'), default=-1), params.Bool(name='show_children', label=_('Show children'), default=True), params.Bool(name='show_links', label=_('Show options bar'), default=True), ] def get_blocks(self): return [FeedbackBlock]
class StandingOutBlock(Block): name = 'standingout' default_place = 'rightsidebar' help_text = ugettext_lazy('Block with standing out by categories') verbose_name = ugettext_lazy('Standing out block') config_params = BaseBlock.config_params + [ params.Integer(name='limit', label=_('limit for standingouts in block'), default='5'), ] default_caching_params = { 'enabled': False, 'timeout': 3600, 'only_anonymous': True, 'vary_on_user': False, 'vary_on_url': True, 'vary_on_language': True, } @classmethod def get_models_refresh_cache(self): return [StandingOut, StandingOutCategory] def render(self, request, place, context, block_content_relation=None, *args, **kwargs): section = None content = None standingout_categories = StandingOutCategory.objects.all() standingouts = None for standingout_category in standingout_categories: variable_value = context.get(standingout_category.context_variable, None) if variable_value: variable_real_instance = getattr(variable_value, 'get_real_instance', None) if variable_real_instance: variable_value = variable_real_instance() if standingout_category.context_variable == 'section': standingouts = get_section_standingouts( StandingOut.objects.all(), variable_value) section = standingouts and variable_value else: filter_ctypes = get_filter_ct(variable_value) standingouts = StandingOut.objects.filter( related_id=variable_value.pk).filter(filter_ctypes) content = standingouts and variable_value if content: sections = content.sections.all() if sections.count(): section = sections[0] if standingouts: break standingouts = standingouts or StandingOut.objects.filter( related_content_type__isnull=True, related_id__isnull=True) limit = self.get_config().get('limit', None) if limit: standingouts = standingouts[:limit.get_value()] return self.render_block(request, template_name='block_standingout.html', block_title=_('Search'), context={ 'standingouts': standingouts, 'section': section, 'content': content })
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Merengue. If not, see <http://www.gnu.org/licenses/>. """ Tests for merengue.registry application """ from merengue.registry import params from merengue.registry.items import RegistrableItem config_params = [ params.Bool(name='is_human', default=True), params.Integer(name='age'), params.List(name='friends', choices=('Juan', 'Luis', 'Pepe')) ] class PersonItem(RegistrableItem): config_params = config_params class SingletonItem(RegistrableItem): singleton = True config_params = config_params __test__ = { "doctest":