コード例 #1
0
ファイル: views.py プロジェクト: zouf/AllSortz
def get_default():
    cfilter = Community.objects.filter(name="Princeton")
    if cfilter.count() == 0:
        logger.debug("Creating a default community of Princeton")
        c = Community(name="Princeton", descr="Default Community of Princeton", city="Princeton",state="NJ")
        c.save()
        return c
    else:
        return cfilter[0]
コード例 #2
0
 def test_priority_of_community_depends_on_followers_num(self):
     other_attrs = dict(deactivated=False, ctype=Community.TYPE_PUBLIC_PAGE)
     communities = [
         Community(vkid=1, followers=0, **other_attrs),
         Community(vkid=2, followers=20, **other_attrs),
         Community(vkid=3, followers=10, **other_attrs),
     ]
     self.assertEqual(
         [c.vkid for c in sorted(communities, key=WallUpdater._priority_of_community)],
         [1, 3, 2]
     )
コード例 #3
0
 def get(self, request, *args, **kwargs):
     self.c = Community.objects.get(pk=self.kwargs["pk"])
     self.a, self.m, self.e, self.ad, self.template_name = Community.get_administrators(
         self.c.pk), Community.get_moderators(
             self.c.pk), Community.get_editors(
                 self.c.pk), Community.get_advertisers(
                     self.c.pk), get_community_manage_template(
                         "communities/manage/members.html", request.user,
                         self.c.pk, request.META['HTTP_USER_AGENT'])
     return super(CommunityMemberManageView,
                  self).get(request, *args, **kwargs)
コード例 #4
0
 def test_new_communities_have_highest_priority(self):
     other_attrs = dict(deactivated=False, ctype=Community.TYPE_PUBLIC_PAGE, followers=0)
     dt = timezone.now()
     communities = [
         Community(vkid=1, wall_checked_at=dt, **other_attrs),
         Community(vkid=2, **other_attrs),
         Community(vkid=3, wall_checked_at=dt, **other_attrs),
     ]
     self.assertEqual(
         sorted(communities, key=WallUpdater._priority_of_community)[-1].vkid,
         2
     )
コード例 #5
0
 def test_update_time_is_more_important_than_followers_num(self):
     other_attrs = dict(deactivated=False, ctype=Community.TYPE_PUBLIC_PAGE)
     dt = timezone.now()
     communities = [
         Community(vkid=1, followers=0, wall_checked_at=dt + TimeDelta(hours=1), **other_attrs),
         Community(vkid=2, followers=20, wall_checked_at=dt, **other_attrs),
         Community(vkid=3, followers=10, wall_checked_at=dt + TimeDelta(hours=2), **other_attrs),
     ]
     self.assertEqual(
         [c.vkid for c in sorted(communities, key=WallUpdater._priority_of_community)],
         [3, 1, 2]
     )
コード例 #6
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_get_posts_for_community_with_name(user, community_name):
    check_is_not_banned_from_community_with_name(user=user, community_name=community_name)
    if Community.is_community_with_name_private(
            community_name=community_name) and not user.is_member_of_community_with_name(
        community_name=community_name):
        raise ValidationError(
            'Сообщество является приватным. Вы должны стать участником, чтобы видеть его записи.',
        )
    if Community.is_community_with_name_closed(
            community_name=community_name) and not user.is_member_of_community_with_name(
        community_name=community_name):
        raise ValidationError(
            'Сообщество является закрытым. Вы должны стать участником, чтобы видеть его записи.',
        )
コード例 #7
0
 def post(self,request,format):
     try:
         json_raw = request.body.decode(encoding='UTF-8')
         obj = json.loads(json_raw)
         try:
             u = User.objects.get(username=obj["comm_leader"])
             entity = Community( comm_leader = u, comm_name = obj["comm_name"],comm_description = obj["comm_description"])
             entity.save()
         except ObjectDoesNotExist:
             return HttpResponse(json.dumps({"msg" : "The Leader doesn't exist"}), content_type='application/json')
         
         return HttpResponse(json.dumps({"msg" : "The community was added successfully"}), content_type='application/json')
     except Exception, e:
         return HttpResponse( json.dumps({"e" : str(e)}) )
コード例 #8
0
    def post(self, request, *args, **kwargs):
        from common.templates import render_for_platform
        from communities.forms import CommunityForm

        self.form = CommunityForm(request.POST)
        if self.form.is_valid() and request.is_ajax():
            new_community, membersheeps = self.form.save(commit=False), [
                request.user,
            ]
            community = Community.create_community(
                name=new_community.name,
                category=new_community.category,
                type=new_community.type,
                creator=request.user)
            data = {
                'is_stat_open': True,
                'is_settings_open': True,
                'is_message_open': True,
                'is_photo_open': True,
                'is_post_open': True,
                'is_member_open': True,
                'is_doc_open': True,
                'is_video_open': True,
                'is_music_open': True,
                'is_good_open': True,
                'community': community,
                'post_list_pk': community.get_post_list().pk,
                'membersheeps': membersheeps,
            }
            return render_for_platform(
                request, 'communities/detail/public_community.html', data)
        else:
            from django.http import HttpResponseBadRequest
            return HttpResponseBadRequest()
コード例 #9
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_get_community_with_name_members(user, community_name):
    check_is_not_banned_from_community_with_name(user=user, community_name=community_name)

    if Community.is_community_with_name_private(community_name=community_name):
        if not user.is_member_of_community_with_name(community_name=community_name):
            raise ValidationError(
                'Нельзя видеть подписчиков частного сообщества.',
            )
コード例 #10
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_add_administrator_with_username_to_community_with_name(user, username, community_name):
    if not user.is_creator_of_community_with_name(community_name=community_name):
        raise ValidationError(
            'Только создатель сообщества может добавить администраторов.',
        )

    if Community.is_user_with_username_administrator_of_community_with_name(username=username,
                                                                            community_name=community_name):
        raise ValidationError(
            'Пользователь уже является администратором',
        )

    if not Community.is_user_with_username_member_of_community_with_name(username=username,
                                                                        community_name=community_name):
        raise ValidationError(
            'Нельзя сделать администратором пользователя, который не подписан на сообщество',
        )
コード例 #11
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_ban_user_with_username_from_community_with_name(user, username, community_name):
    if not user.is_administrator_of_community_with_name(
            community_name=community_name) and not user.is_moderator_of_community_with_name(
        community_name=community_name):
        raise ValidationError(
            'Только администраторы и модераторы сообщества могут блокировать участников сообщества.',
        )

    if Community.is_user_with_username_banned_from_community_with_name(username=username,
                                                                       community_name=community_name):
        raise ValidationError(
            'Пользователь уже забанен',
        )

    if Community.is_user_with_username_moderator_of_community_with_name(username=username,
                                                                        community_name=community_name) or Community.is_user_with_username_administrator_of_community_with_name(
        username=username, community_name=community_name):
        raise ValidationError(
            'Вы не можете заблокировать модератора или администратора сообщества',
        )
コード例 #12
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_remove_moderator_with_username_to_community_with_name(user, username, community_name):
    if not user.is_administrator_of_community_with_name(community_name=community_name):
        raise ValidationError(
            'Удалять модераторов могут только администраторы сообщества',
        )

    if not Community.is_user_with_username_moderator_of_community_with_name(username=username,
                                                                            community_name=community_name):
        raise ValidationError(
            'Пользователь не является модератором',
        )
コード例 #13
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_remove_administrator_with_username_to_community_with_name(user, username, community_name):
    if not user.is_creator_of_community_with_name(community_name=community_name):
        raise ValidationError(
            'Только создатель сообщества может удалить администраторов.',
        )

    if not Community.is_user_with_username_administrator_of_community_with_name(username=username,
                                                                                community_name=community_name):
        raise ValidationError(
            'Пользователь не является администратором',
        )
コード例 #14
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_unban_user_with_username_from_community_with_name(user, username, community_name):
    if not user.is_administrator_of_community_with_name(
            community_name=community_name) and not user.is_moderator_of_community_with_name(
        community_name=community_name):
        raise ValidationError(
            'Только администраторы и модераторы сообщества могут блокировать участников сообщества',
        )
    if not Community.is_user_with_username_banned_from_community_with_name(username=username,
                                                                           community_name=community_name):
        raise ValidationError(
            'Нельзя разбанить не заблокированного пользователя',
        )
コード例 #15
0
 def get_community(self, request):
     if not self.community:
         try:
             community_id = request.session['community_id']
             self.community = Community.objects.get(pk=community_id)
         except:
             self.community = Community.get_default(request)
             request.session['community_id'] = self.community.pk
     else:
         return self.community
     return self.community
     """
コード例 #16
0
 def test_sleep_until_check_begins(self):
     now = timezone.now()
     cu = CommunitiesUpdater(None)
     cu._communities_buffer = [
         Community(vkid=1,
                   deactivated=False,
                   ctype=Community.TYPE_PUBLIC_PAGE,
                   checked_at=now - COMMUNITY_UPDATE_PERIOD +
                   TimeDelta(seconds=42))
     ]
     with patch('django.utils.timezone.now', return_value=now),\
             patch.object(cu, '_sleep') as _sleep:
         cu._sleep_until_check_begins()
         self.assertEqual(_sleep.call_args, [(42, )])
コード例 #17
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_join_community_with_name(user, community_name):
    if user.is_banned_from_community_with_name(community_name):
        raise ValidationError('Вы не можете присоединиться к сообществу, в котором вы были заблокированы.')

    if user.is_member_of_community_with_name(community_name):
        raise ValidationError(
            'Вы уже являетесь подписчиков сообщества',
        )

    if Community.is_community_with_name_private(community_name=community_name):
        if not user.is_invited_to_community_with_name(community_name=community_name):
            raise ValidationError(
                'Вы не приглашены в это сообщество',
            )
コード例 #18
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_add_moderator_with_username_to_community_with_name(user, username, community_name):
    if not user.is_administrator_of_community_with_name(community_name=community_name):
        raise ValidationError(
            'Только администраторы сообщества могут добавлять модераторов',
        )

    if Community.is_user_with_username_administrator_of_community_with_name(username=username,
                                                                            community_name=community_name):
        raise ValidationError(
            'Пользователь является администратором',
        )

    if Community.is_user_with_username_moderator_of_community_with_name(username=username,
                                                                        community_name=community_name):
        raise ValidationError(
            'Пользователь уже является модератором',
        )

    if not Community.is_user_with_username_member_of_community_with_name(username=username,
                                                                         community_name=community_name):
        raise ValidationError(
            'Нельзя сделать модератором пользователя, который не является подписчиком сообщества',
        )
コード例 #19
0
ファイル: checkers.py プロジェクト: Interesnij/cry
def check_can_invite_user_with_username_to_community_with_name(user, username, community_name):
    if not user.is_member_of_community_with_name(community_name=community_name):
        raise ValidationError(
            'Вы можете приглашать людей только в сообщество, членом которого являетесь.',
        )

    if user.has_invited_user_with_username_to_community_with_name(username=username, community_name=community_name):
        raise ValidationError(
            'Вы уже пригласили этого пользователя присоединиться к сообществу.',
        )

    if Community.is_user_with_username_member_of_community_with_name(username=username,
                                                                     community_name=community_name):
        raise ValidationError(
            'Пользователь уже является подписчиком сообщества',
        )

    if not Community.is_community_with_name_invites_enabled(community_name=community_name) and not (
            user.is_administrator_of_community_with_name(
                community_name=community_name) or user.is_moderator_of_community_with_name(
        community_name=community_name)):
        raise ValidationError(
            'Приглашения для этого сообщества не включены. Приглашать могут только администраторы и модераторы.',
        )
コード例 #20
0
ファイル: load.py プロジェクト: Interesnij/rus
	def get_queryset(self):
		if self.target == "user":
			return self.request.user.get_all_friends()
		elif self.community_pk:
			from communities.models import Community
			return Community.get_members(self.community_pk)
コード例 #21
0
 def __create_notice_C(cls, community: Community, notice: Notice) -> None:
     for member in community.members.all():
         user_status = community.get_member_status(member)
         if user_status['valid']:
             cls.__notice_box_manager.create(user=member, notice=notice)
コード例 #22
0
ファイル: list.py プロジェクト: Interesnij/rus
	def get_queryset(self):
		return Community.get_trending_communities()
コード例 #23
0
 def get_community(self, request):
     if not self.community:
         self.community = Community.get_default(request)
         #add as a member
         self.save()
     return self.community