Esempio n. 1
0
    def create_survey(cls, title, list, image, creator, is_anonymous,
                      is_multiple, is_no_edited, time_end, answers, community):
        list.count += 1
        list.save(update_fields=["count"])
        survey = cls.objects.create(title=title,
                                    order=list.count,
                                    list=list,
                                    image=image,
                                    creator=creator,
                                    is_anonymous=is_anonymous,
                                    is_multiple=is_multiple,
                                    is_no_edited=is_no_edited,
                                    time_end=time_end)
        answer_order = 0
        for answer in answers:
            answer_order += 1
            Answer.objects.create(survey=survey,
                                  text=answer,
                                  order=answer_order)
        if community:
            from common.notify.progs import community_send_notify, community_send_wall
            from notify.models import Notify, Wall

            Wall.objects.create(creator_id=creator.pk,
                                community_id=community.pk,
                                type="SUR",
                                object_id=survey.pk,
                                verb="ITE")
            community_send_wall(doc.pk, creator.pk, community.pk, None,
                                "create_c_survey_wall")
            for user_id in community.get_member_for_notify_ids():
                Notify.objects.create(creator_id=creator.pk,
                                      community_id=community.pk,
                                      recipient_id=user_id,
                                      type="SUR",
                                      object_id=survey.pk,
                                      verb="ITE")
                community_send_notify(doc.pk, creator.pk, user_id,
                                      community.pk, None,
                                      "create_c_survey_notify")
        else:
            from common.notify.progs import user_send_notify, user_send_wall
            from notify.models import Notify, Wall

            Wall.objects.create(creator_id=creator.pk,
                                type="SUR",
                                object_id=survey.pk,
                                verb="ITE")
            user_send_wall(survey.pk, None, "create_u_survey_wall")
            for user_id in creator.get_user_main_news_ids():
                Notify.objects.create(creator_id=creator.pk,
                                      recipient_id=user_id,
                                      type="SUR",
                                      object_id=survey.pk,
                                      verb="ITE")
                user_send_notify(survey.pk, creator.pk, user_id, None,
                                 "create_u_survey_notify")
        return survey
Esempio n. 2
0
    def create_list(cls, creator, name, description, community):
        from notify.models import Notify, Wall
        from common.processing.survey import get_survey_list_processing

        list = cls.objects.create(creator=creator,
                                  name=name,
                                  description=description,
                                  community=community)
        is_public = True
        if community:
            from communities.model.list import CommunitySurveyListPosition
            CommunitySurveyListPosition.objects.create(
                community=community.pk,
                list=list.pk,
                position=SurveyList.get_community_lists_count(community.pk))
            if is_public:
                from common.notify.progs import community_send_notify, community_send_wall
                Wall.objects.create(creator_id=creator.pk,
                                    community_id=community.pk,
                                    type="SUL",
                                    object_id=list.pk,
                                    verb="ITE")
                community_send_wall(list.pk, creator.pk, community.pk, None,
                                    "create_c_survey_list_wall")
                for user_id in community.get_member_for_notify_ids():
                    Notify.objects.create(creator_id=creator.pk,
                                          community_id=community.pk,
                                          recipient_id=user_id,
                                          type="SUL",
                                          object_id=list.pk,
                                          verb="ITE")
                    community_send_notify(list.pk, creator.pk, user_id,
                                          community.pk, None,
                                          "create_c_survey_list_notify")
        else:
            from users.model.list import UserSurveyListPosition
            UserSurveyListPosition.objects.create(
                user=creator.pk,
                list=list.pk,
                position=SurveyList.get_user_lists_count(creator.pk))
            if is_public:
                from common.notify.progs import user_send_notify, user_send_wall
                Wall.objects.create(creator_id=creator.pk,
                                    type="SUL",
                                    object_id=list.pk,
                                    verb="ITE")
                user_send_wall(list.pk, None, "create_u_survey_list_wall")
                for user_id in creator.get_user_main_news_ids():
                    Notify.objects.create(creator_id=creator.pk,
                                          recipient_id=user_id,
                                          type="SUL",
                                          object_id=list.pk,
                                          verb="ITE")
                    user_send_notify(list.pk, creator.pk, user_id, None,
                                     "create_u_survey_list_notify")
        get_survey_list_processing(list, SurveyList.LIST)
        return list
Esempio n. 3
0
    def post(self, request, *args, **kwargs):
        form_post, list, attach = PostForm(
            request.POST), PostsList.objects.get(
                pk=self.kwargs["pk"]), request.POST.getlist('attach_items')

        if request.is_ajax() and form_post.is_valid(
        ) and list.is_user_can_create_el(request.user.pk):
            post = form_post.save(commit=False)
            creator = request.user
            if post.text or attach:
                from common.templates import render_for_platform
                new_post = post.create_post(
                    creator=creator,
                    text=post.text,
                    category=post.category,
                    list=list,
                    attach=attach,
                    parent=None,
                    comments_enabled=post.comments_enabled,
                    is_signature=post.is_signature,
                    votes_on=post.votes_on,
                    community=None)

                from common.notify.progs import user_send_notify, user_send_wall
                from notify.models import Notify, Wall

                Wall.objects.create(creator_id=creator.pk,
                                    type="POS",
                                    object_id=new_post.pk,
                                    verb="ITE")
                user_send_wall(new_post.pk, None, "create_u_post_wall")
                for user_id in creator.get_user_main_notify_ids():
                    Notify.objects.create(creator_id=creator.pk,
                                          recipient_id=user_id,
                                          type="POS",
                                          object_id=new_post.pk,
                                          verb="ITE")
                    user_send_notify(new_post.pk, creator.pk, user_id, None,
                                     "create_u_post_notify")
                creator.plus_posts(1)

                return render_for_platform(request,
                                           'posts/post_user/my_post.html',
                                           {'object': new_post})
            else:
                return HttpResponseBadRequest()
        else:
            return HttpResponseBadRequest()
Esempio n. 4
0
    def create_manager_community(cls, name, s_avatar, description, category, creator, type):
        from logs.model.manage_community import CommunityManageLog
        from notify.models import Wall
        from common.notify.progs import user_send_wall
        from common.processing import get_community_processing

        community = cls.objects.create(name=name, description=description, creator=creator, category=category)
        if s_avatar:
            community.create_s_avatar(s_avatar)
        CommunityMembership.create_membership(user=creator, is_administrator=True, community=community)
        community.save()
        creator.create_or_plus_populate_community(community.pk)
        community.add_news_subscriber(creator.pk)
        community.add_notify_subscriber(creator.pk)
        CommunityManageLog.objects.create(item=self.pk, manager=manager_id, action_type=CommunityManageLog.CREATE)
        Wall.objects.create(creator_id=creator.pk, type="COM", object_id=self.pk, verb="ITE")
        user_send_wall(self.pk, None, "community_wall")
        return community
Esempio n. 5
0
    def publish_community(self, name, s_avatar, category, description, manager_id):
        from logs.model.manage_community import CommunityManageLog
        from notify.models import Wall, Notify
        from common.notify.progs import user_send_wall, user_send_notify
        from common.processing import get_community_processing

        get_community_processing(name, description)
        CommunityMembership.create_membership(user=self.creator, is_administrator=True, community=self)
        self.name = name
        self.category = category
        self.description = description
        self.save()
        self.add_news_subscriber(creator.pk)
        self.add_notify_subscriber(creator.pk)
        if s_avatar:
            self.create_s_avatar(s_avatar)
        CommunityManageLog.objects.create(item=self.pk, manager=manager_id, action_type=CommunityManageLog.PUBLISH)
        Wall.objects.create(creator_id=creator.pk, type="COM", object_id=self.pk, verb="ITE")
        user_send_wall(self.pk, None, "community_wall")
        Notify.objects.create(creator_id=creator.pk, recipient_id=self.creator.pk, type="COM", object_id=self.pk, verb="ITE")
        user_send_notify(self.pk, self.creator.pk, self.creator.pk, None, "community_notify")
        return self