コード例 #1
0
ファイル: share.py プロジェクト: PythonUnited/djinn_forms
    def prepare_value(self, data):

        """ Return shares for this field. If data is empty,
        we simply get the related objects for the given type.
        If data['rm'] has values, filter those out of the result.
        If data['add'] has values, add those to the result
        """

        shares = self.instance.shares.all()

        try:
            shares = list(filter(lambda x: x not in data['rm'], shares))
        except:
            pass

        try:
            shares += data['add']
        except:
            pass

        prepared = []
        for rel in shares:
            if rel.user_id:
                uprofile = rel.user.profile
                prepared.append({'label': str(uprofile),
                                 'value': object_to_urn(uprofile)})
            if rel.usergroup_id:
                gprofile = rel.usergroup.profile
                prepared.append({'label': str(gprofile),
                                 'value': object_to_urn(gprofile)})
        return prepared
コード例 #2
0
ファイル: role.py プロジェクト: PythonUnited/djinn_forms
    def prepare_value(self, data):
        """ Get existing role, if it's there """

        # We have an initial value set...
        #
        if data:
            return {'label': str(data), 'value': object_to_urn(data)}

        value = super(LocalRoleSingleField, self).prepare_value(data)

        if value:
            return value[0]
        else:
            return None
コード例 #3
0
def favorite_action(context,
                    obj=None,
                    urn=None,
                    title=None,
                    label_prefix="",
                    extra_css_classes="",
                    no_icon='false'):
    """ Render favorite action """

    urn = urn or object_to_urn(obj)
    user_profile = context['request'].user.get_profile()
    url = obj and obj.get_absolute_url() or "__NO_URL__"

    try:
        default_folder = user_profile.favoritesfolder_set.all()[0]
    except:
        default_folder = FavoritesFolder.create_defaults_for(user_profile)

    if not title:
        title = obj.title

    try:
        favorite = Favorite.objects.filter(folder__profile=user_profile,
                                           uri__in=[unquote_plus(urn), url])[0]
        is_favorite = True
        label = "Favoriet"
        favorite_id = favorite.id
    except:
        is_favorite = False
        label = "Favoriet maken"
        favorite_id = None

    if label_prefix:
        label = "%s %s" % (label_prefix, label.lower())

    return {
        'is_favorite': is_favorite,
        'favorite_id': favorite_id,
        'folders': user_profile.favoritesfolder_set.all(),
        'default_folder': default_folder,
        'label': label,
        'extra_css_classes': extra_css_classes,
        'label_prefix': label_prefix,
        'urn': urn,
        'title': title,
        'no_icon': no_icon == 'true'
    }
コード例 #4
0
ファイル: relate.py プロジェクト: PythonUnited/djinn_forms
    def get(self, request, term=None):

        term = term or request.GET.get('term', '')

        if not term:
            return HttpResponse(json.dumps([]),
                                content_type='application/json')

        search_field = "%s__contains" % request.GET.get("searchfield", "title")

        ct_parameter = request.GET.get("ct_searchfield", "meta_ct")

        ct_search_field = "%s__in" % ct_parameter

        content_types = request.GET.get('content_type', '').split(",")

        # MJB map
        # content_types = map(map_swappable_ct, content_types)
        content_types = [map_swappable_ct(ctn) for ctn in content_types]

        _filter = {search_field: Raw("*%s*" % term)}

        if content_types:
            _filter[ct_search_field] = content_types

        parentusergroup = request.GET.get("parentusergroup", None)
        if parentusergroup and parentusergroup != '-1':
            _filter['parentusergroup'] = parentusergroup

        sqs = SearchQuerySet().filter(**_filter)

        results = []

        for res in [res for res in sqs if res.object]:
            results.append({
                "label": str(res.object),
                "value": object_to_urn(res.object)
            })

        if len(results) == 0:
            results.append({"label": "Geen resultaat gevonden", "value": ''})

        return HttpResponse(json.dumps(results),
                            content_type='application/json')
コード例 #5
0
ファイル: relate.py プロジェクト: PythonUnited/djinn_forms
    def prepare_value(self, data):

        """Return relations for this field. If data is empty, we simply get
        the related objects for the given type. If data['rm'] has
        values, filter those out of the result. If data['add'] has
        values, add those to the result.
        """

        if data is None:
            data = {}

        relations = self.instance.get_related(self.relation_type)

        relations = [x for x in relations if x not in data.get('rm', [])]

        relations += data.get('add', [])

        return [{'label': rel.title, 'value': object_to_urn(rel)} for rel in
                relations if rel]
コード例 #6
0
ファイル: relate.py プロジェクト: PythonUnited/djinn_forms
    def prepare_value(self, data):
        """Return relations for this field. If data is empty, we simply get
        the related objects for the given type. If data['rm'] has
        values, filter those out of the result. If data['add'] has
        values, add those to the result.
        """

        if data is None:
            data = {}

        relations = self.instance.get_related(self.relation_type)

        relations = [x for x in relations if x not in data.get('rm', [])]

        relations += data.get('add', [])

        return [{
            'label': rel.title,
            'value': object_to_urn(rel)
        } for rel in relations if rel]
コード例 #7
0
ファイル: relate.py プロジェクト: PythonUnited/djinn_forms
    def prepare_value(self, data):
        """ Get existing role, if it's there """

        # value = super(RelateSingleField, self).prepare_value(data)

        # try:
        #     return value[0]
        # except:
        #     return None

        rel = None
        if not data:
            relations = self.instance.get_related(self.relation_type)
            if len(relations) > 0:
                rel = relations[0]
        else:
            rel = data

        if not rel:
            return None

        return {'label': rel.title, 'value': object_to_urn(rel)}
コード例 #8
0
def favorite_action(context, obj=None, urn=None, title=None, label_prefix="",
                    extra_css_classes="", no_icon='false'):

    """ Render favorite action """

    urn = urn or object_to_urn(obj)
    user_profile = context['request'].user.get_profile()
    url = obj and obj.get_absolute_url() or "__NO_URL__"

    try:
        default_folder = user_profile.favoritesfolder_set.all()[0]
    except:
        default_folder = FavoritesFolder.create_defaults_for(user_profile)

    if not title:
        title = obj.title

    try:
        favorite = Favorite.objects.filter(
            folder__profile=user_profile,
            uri__in=[unquote_plus(urn), url])[0]
        is_favorite = True
        label = "Favoriet"
        favorite_id = favorite.id
    except:
        is_favorite = False
        label = "Favoriet maken"
        favorite_id = None        

    if label_prefix:
        label = "%s %s" % (label_prefix, label.lower())

    return {'is_favorite': is_favorite, 'favorite_id': favorite_id,
            'folders': user_profile.favoritesfolder_set.all(),
            'default_folder': default_folder, 'label': label,
            'extra_css_classes': extra_css_classes,
            'label_prefix': label_prefix,
            'urn': urn, 'title': title, 'no_icon': no_icon=='true'}
コード例 #9
0
ファイル: role.py プロジェクト: PythonUnited/djinn_forms
    def prepare_value(self, data):
        """ Get the existing local roles for the given role.  If
        data['rm'] has values, filter those out of the result.  If
        data['add'] has values, add those to the result
        """

        # We have an initial value set...
        #
        if data and not "add" in data.keys():
            return data

        if not data:
            data = {}

        roles = self.instance.get_local_roles(role_filter=[self.role])

        users_or_groups = [lrole.assignee for lrole in roles]

        users_or_groups = [u.profile for u in users_or_groups if u.profile]

        if 'rm' in data:
            try:
                users_or_groups = list(
                    filter(lambda x: x not in data['rm'], users_or_groups))
            except Exception as exc:
                pass

        if 'add' in data:
            try:
                users_or_groups += data['add']
            except Exception as exc:
                pass

        return [{
            'label': str(profile),
            'value': object_to_urn(profile)
        } for profile in users_or_groups]
コード例 #10
0
ファイル: relate.py プロジェクト: PythonUnited/djinn_forms
    def prepare_value(self, data):

        """ Get existing role, if it's there """

        # value = super(RelateSingleField, self).prepare_value(data)

        # try:
        #     return value[0]
        # except:
        #     return None

        rel = None
        if not data:
            relations = self.instance.get_related(self.relation_type)
            if len(relations)>0:
                rel = relations[0]
        else:
            rel = data

        if not rel:
            return None

        return {'label': rel.title,
                'value': object_to_urn(rel)}
コード例 #11
0
    def test_object_to_urn(self):

        "urn:pu.in:%(object_app)s:%(object_ctype)s:%(object_id)s"

        self.assertEquals("urn:pu.in:pgcontent:article:%s" % self.obj.id,
                          object_to_urn(self.obj))
コード例 #12
0
    def test_object_to_urn(self):

        "urn:pu.in:%(object_app)s:%(object_ctype)s:%(object_id)s"

        self.assertEquals("urn:pu.in:pgcontent:article:%s" % self.obj.id,
                          object_to_urn(self.obj))