Exemplo n.º 1
0
    def ready(self):
        """ Add user info to ExtensibleNodeSerializer """
        from nodeshot.core.nodes.base import ExtensibleNodeSerializer
        from .serializers import ProfileRelationSerializer

        ExtensibleNodeSerializer.add_relationship(
            name='user',
            serializer=ProfileRelationSerializer,
            queryset=lambda obj, request: obj.user)
Exemplo n.º 2
0
    def ready(self):
        """ Add relationship to ExtensibleNodeSerializer """
        from nodeshot.core.nodes.base import ExtensibleNodeSerializer

        ExtensibleNodeSerializer.add_relationship(**{
            'name': 'devices',
            'view_name': 'api_node_devices',
            'lookup_field': 'slug'
        })
Exemplo n.º 3
0
    def ready(self):
        """ Add relationship to ExtensibleNodeSerializer """
        from nodeshot.core.nodes.base import ExtensibleNodeSerializer

        ExtensibleNodeSerializer.add_relationship(**{
            'name': 'links',
            'view_name': 'api_node_links',
            'lookup_field': 'slug'
        })
Exemplo n.º 4
0
    def ready(self):
        """ Add user info to ExtensibleNodeSerializer """
        from nodeshot.core.nodes.base import ExtensibleNodeSerializer
        from .serializers import ProfileRelationSerializer

        ExtensibleNodeSerializer.add_relationship(
            name='user',
            serializer=ProfileRelationSerializer,
            queryset=lambda obj, request: obj.user
        )
Exemplo n.º 5
0
from interfaces.ethernet import Ethernet
from interfaces.wireless import Wireless
from interfaces.bridge import Bridge
from interfaces.tunnel import Tunnel
from interfaces.vlan import Vlan
from interfaces.vap import Vap


__all__ = [
    'RoutingProtocol',
    'Device',
    'Interface',
    'Ip',
    'Ethernet',
    'Wireless',
    'Bridge',
    'Tunnel',
    'Vlan',
    'Vap'
]


# ------ Add relationship to ExtensibleNodeSerializer ------ #

from nodeshot.core.nodes.base import ExtensibleNodeSerializer

ExtensibleNodeSerializer.add_relationship(**{
    'name': 'devices',
    'view_name': 'api_node_devices',
    'lookup_field': 'slug'
})
Exemplo n.º 6
0

class ProfileRelationSerializer(ProfileSerializer):
    """ Profile Serializer used for linking """
    class Meta:
        model = User
        fields = ('id', 'username', 'full_name', 'city', 'country', 'avatar', 'details')


# ------ Add user info to ExtensibleNodeSerializer ------ #

from nodeshot.core.nodes.base import ExtensibleNodeSerializer

ExtensibleNodeSerializer.add_relationship(
    name='user',
    serializer=ProfileRelationSerializer,
    queryset='obj.user'
)


class AccountSerializer(serializers.ModelSerializer):
    """ Account serializer """
    profile = serializers.HyperlinkedIdentityField(
        lookup_field='username',
        view_name='api_profile_detail'
    )
    social_links = serializers.HyperlinkedIdentityField(
        lookup_field='username',
        view_name='api_user_social_links_list'
    )
    change_password = HyperlinkedField(
Exemplo n.º 7
0

class ProfileRelationSerializer(ProfileSerializer):
    """ Profile Serializer used for linking """
    class Meta:
        model = User
        fields = ('id', 'username', 'full_name', 'city', 'country', 'avatar', 'details')


# ------ Add user info to ExtensibleNodeSerializer ------ #

from nodeshot.core.nodes.base import ExtensibleNodeSerializer

ExtensibleNodeSerializer.add_relationship(
    name='user',
    serializer=ProfileRelationSerializer,
    queryset=lambda obj, request: obj.user
)


class AccountSerializer(serializers.ModelSerializer):
    """ Account serializer """
    profile = serializers.HyperlinkedIdentityField(
        lookup_field='username',
        view_name='api_profile_detail'
    )
    social_links = serializers.HyperlinkedIdentityField(
        lookup_field='username',
        view_name='api_user_social_links_list'
    )
    change_password = HyperlinkedField(
Exemplo n.º 8
0
    check_dependencies(dependencies="emailconfirmation", module="nodeshot.community.profiles")


from .profile import Profile
from .social_link import SocialLink
from .password_reset import PasswordReset

__all__ = ["Profile", "SocialLink", "PasswordReset"]


# ------ Add relationship to ExtensibleNodeSerializer ------ #

from nodeshot.core.nodes.base import ExtensibleNodeSerializer

ExtensibleNodeSerializer.add_relationship(
    **{"name": "user", "view_name": "api_profile_detail", "lookup_field": "user.username"}
)


# ------ SIGNALS ------ #

# perform certain actions when some other parts of the application changes
# eg: update user statistics when a new device is added

from django.contrib.auth.models import Group
from django.dispatch import receiver
from django.db.models.signals import post_save


@receiver(post_save, sender=Profile)
def new_user(sender, **kwargs):
Exemplo n.º 9
0
    def ready(self):
        """ Add user info to ExtensibleNodeSerializer """
        from nodeshot.core.nodes.base import ExtensibleNodeSerializer
        from .models import Vote
        from .serializers import (CommentRelationSerializer,
                                  ParticipationSerializer)

        ExtensibleNodeSerializer.add_relationship(
            'comments',
            serializer=CommentRelationSerializer,
            many=True,
            queryset=lambda obj, request: obj.comment_set.all())

        ExtensibleNodeSerializer.add_relationship(
            'counts',
            serializer=ParticipationSerializer,
            queryset=lambda obj, request: obj.noderatingcount)

        ExtensibleNodeSerializer.add_relationship('votes_url',
                                                  view_name='api_node_votes',
                                                  lookup_field='slug')

        ExtensibleNodeSerializer.add_relationship('ratings_url',
                                                  view_name='api_node_ratings',
                                                  lookup_field='slug')

        ExtensibleNodeSerializer.add_relationship(
            'comments_url', view_name='api_node_comments', lookup_field='slug')

        def voted(obj, request):
            """
            Determines if current logged-in user has already voted on a node
            returns 1 if user has already liked
            returns -1 if user has already disliked
            returns False if user hasn't voted or if not authenticated
            """
            if request.user.is_authenticated():
                v = Vote.objects.filter(node_id=obj.id,
                                        user_id=request.user.id)
                if len(v) > 0:
                    return v[0].vote
            # hasn't voted yet or not authenticated
            return False

        ExtensibleNodeSerializer.add_relationship('voted', function=voted)

        ExtensibleNodeSerializer.add_relationship(
            'voting_allowed', function=lambda obj, request: obj.voting_allowed)

        ExtensibleNodeSerializer.add_relationship(
            'rating_allowed', function=lambda obj, request: obj.rating_allowed)

        ExtensibleNodeSerializer.add_relationship(
            'comments_allowed',
            function=lambda obj, request: obj.comments_allowed)
Exemplo n.º 10
0

class ProfileRelationSerializer(ProfileSerializer):
    """ Profile Serializer used for linking """
    class Meta:
        model = User
        fields = ('id', 'username', 'full_name', 'city', 'country', 'avatar',
                  'details')


# ------ Add user info to ExtensibleNodeSerializer ------ #

from nodeshot.core.nodes.base import ExtensibleNodeSerializer

ExtensibleNodeSerializer.add_relationship(
    name='user',
    serializer=ProfileRelationSerializer,
    queryset=lambda obj, request: obj.user)


class AccountSerializer(serializers.ModelSerializer):
    """ Account serializer """
    profile = serializers.HyperlinkedIdentityField(
        lookup_field='username', view_name='api_profile_detail')
    social_links = serializers.HyperlinkedIdentityField(
        lookup_field='username', view_name='api_user_social_links_list')
    change_password = HyperlinkedField(view_name='api_account_password_change')
    logout = HyperlinkedField(view_name='api_account_logout')

    if EMAIL_CONFIRMATION:
        email_addresses = HyperlinkedField(view_name='api_account_email_list')
Exemplo n.º 11
0
    def ready(self):
        """ Add user info to ExtensibleNodeSerializer """
        from nodeshot.core.nodes.base import ExtensibleNodeSerializer
        from .models import Vote
        from .serializers import (CommentRelationSerializer,
                                  ParticipationSerializer)

        ExtensibleNodeSerializer.add_relationship(
            'comments',
            serializer=CommentRelationSerializer,
            many=True,
            queryset=lambda obj, request: obj.comment_set.all()
        )

        ExtensibleNodeSerializer.add_relationship(
            'counts',
            serializer=ParticipationSerializer,
            queryset=lambda obj, request: obj.noderatingcount
        )

        ExtensibleNodeSerializer.add_relationship(
            'votes_url',
            view_name='api_node_votes',
            lookup_field='slug'
        )

        ExtensibleNodeSerializer.add_relationship(
            'ratings_url',
            view_name='api_node_ratings',
            lookup_field='slug'
        )

        ExtensibleNodeSerializer.add_relationship(
            'comments_url',
            view_name='api_node_comments',
            lookup_field='slug'
        )

        def voted(obj, request):
            """
            Determines if current logged-in user has already voted on a node
            returns 1 if user has already liked
            returns -1 if user has already disliked
            returns False if user hasn't voted or if not authenticated
            """
            if request.user.is_authenticated():
                v = Vote.objects.filter(node_id=obj.id, user_id=request.user.id)
                if len(v) > 0:
                    return v[0].vote
            # hasn't voted yet or not authenticated
            return False

        ExtensibleNodeSerializer.add_relationship(
            'voted',
            function=voted
        )

        ExtensibleNodeSerializer.add_relationship(
            'voting_allowed',
            function=lambda obj, request: obj.voting_allowed
        )

        ExtensibleNodeSerializer.add_relationship(
            'rating_allowed',
            function=lambda obj, request: obj.rating_allowed
        )

        ExtensibleNodeSerializer.add_relationship(
            'comments_allowed',
            function=lambda obj, request: obj.comments_allowed
        )
Exemplo n.º 12
0
    check_dependencies(dependencies='emailconfirmation',
                       module='nodeshot.community.profiles')

from .profile import Profile
from .social_link import SocialLink
from .password_reset import PasswordReset

__all__ = ['Profile', 'SocialLink', 'PasswordReset']

# ------ Add relationship to ExtensibleNodeSerializer ------ #

from nodeshot.core.nodes.base import ExtensibleNodeSerializer

ExtensibleNodeSerializer.add_relationship(
    **{
        'name': 'user',
        'view_name': 'api_profile_detail',
        'lookup_field': 'user.username'
    })

# ------ SIGNALS ------ #

# perform certain actions when some other parts of the application changes
# eg: update user statistics when a new device is added

from django.contrib.auth.models import Group
from django.dispatch import receiver
from django.db.models.signals import post_save


@receiver(post_save, sender=Profile)
def new_user(sender, **kwargs):