Exemple #1
0
def create_initial_user_widgets(sender, profile, **kwargs):
    """ Function responsible for creating the initial widgets of the UserDashboard
    upon user creation. Will create widgets that are defined in:
        ``settings.COSINNUS_INITIAL_USER_WIDGETS``
    """
    for app_name, widget_name, options in settings.COSINNUS_INITIAL_USER_WIDGETS:
        widget_class = widget_registry.get(app_name, widget_name, None)
        if widget_class:
            widget = widget_class.create(None, group=None, user=profile.user)
            widget.save_config(options)
Exemple #2
0
def ensure_user_widget(user, app_name, widget_name, config={}):
    """ Makes sure if a widget exists for the given user, and if not, creates it """
    from cosinnus.models.widget import WidgetConfig
    wqs = WidgetConfig.objects.filter(user_id=user.pk,
                                      app_name=app_name,
                                      widget_name=widget_name)
    if wqs.count() <= 0:
        widget_class = widget_registry.get(app_name, widget_name)
        widget = widget_class.create(None, group=None, user=user)
        widget.save_config(config)
Exemple #3
0
def ensure_group_widget(group, app_name, widget_name, widget_type, options):
    """ Checks if a widget exists, and if not, creates it """
    widget_check = WidgetConfig.objects.filter(
        group_id=group.pk,
        app_name=app_name,
        widget_name__in=[widget_name,
                         widget_name.replace('_', ' ')],
        type=widget_type)
    if widget_check.count() <= 0:
        widget_class = widget_registry.get(app_name, widget_name, None)
        if widget_class:
            widget = widget_class.create(None,
                                         group=group,
                                         user=None,
                                         widget_type=widget_type)
            widget.save_config(options)