Beispiel #1
0
    def create_survey(cls, title, image, lists, creator, order, is_anonymous, is_multiple, is_no_edited, time_end, answers, community):
        from common.processing import get_survey_processing

        if not lists:
            from rest_framework.exceptions import ValidationError
            raise ValidationError("Не выбран список для нового документа")

        survey = cls.objects.create(title=title,image=image,creator=creator,order=order,is_anonymous=is_anonymous,is_multiple=is_multiple,is_no_edited=is_no_edited,time_end=time_end)
        for answer in answers:
            Answer.objects.create(survey=survey, text=answer)
        for list_id in lists:
            list = SurveyList.objects.get(pk=list_id)
            list.survey_list.add(survey)
        get_survey_processing(survey, Survey.PUBLISHED)
        if community:
            from common.notify.progs import community_send_notify, community_send_wall
            from notify.models import Notify, Wall

            community.plus_surveys(1)
            #Wall.objects.create(creator_id=creator.pk, community_id=community.pk, recipient_id=user_id, 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

            creator.plus_surveys(1)
            #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_news_notify_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
Beispiel #2
0
 def create_list(cls, creator, name, description, order, community, is_public):
     from notify.models import Notify, Wall
     from common.processing import get_survey_list_processing
     if not SurveyList.is_user_can_added_list(creator.pk):
         pass
     if not order:
         order = 1
     if community:
         list = cls.objects.create(creator=creator,name=name,description=description, order=order, community=community)
         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:
         list = cls.objects.create(creator=creator,name=name,description=description, order=order)
         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_news_notify_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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
    def create_doc(cls, creator, title, file, lists, is_public, community):
        from common.processing import get_doc_processing

        if not lists:
            from rest_framework.exceptions import ValidationError
            raise ValidationError("Не выбран список для нового документа")
        private = 0
        doc = cls.objects.create(creator=creator,
                                 title=title,
                                 file=file,
                                 community=community)
        if community:
            community.plus_docs(1)
        else:
            creator.plus_docs(1)
        for list_id in lists:
            doc_list = DocList.objects.get(pk=list_id)
            doc_list.doc_list.add(doc)
            if doc_list.is_private():
                private = 1
        if not private and is_public:
            get_doc_processing(doc, Doc.PUBLISHED)
            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, recipient_id=user_id, type="DOC", object_id=doc.pk, verb="ITE")
                #community_send_wall(doc.pk, creator.pk, community.pk, None, "create_c_doc_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="DOC",
                                          object_id=doc.pk,
                                          verb="ITE")
                    community_send_notify(doc.pk, creator.pk, user_id,
                                          community.pk, None,
                                          "create_c_doc_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="DOC", object_id=doc.pk, verb="ITE")
                #user_send_wall(doc.pk, None, "create_u_doc_wall")
                for user_id in creator.get_user_news_notify_ids():
                    Notify.objects.create(creator_id=creator.pk,
                                          recipient_id=user_id,
                                          type="DOC",
                                          object_id=doc.pk,
                                          verb="ITE")
                    user_send_notify(doc.pk, creator.pk, user_id, None,
                                     "create_u_doc_notify")
        else:
            get_doc_processing(doc, Doc.PRIVATE)
        return doc
Beispiel #6
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()
Beispiel #7
0
    def create_video(cls, creator, title, file, image, uri, lists, is_public, community):
        from common.processing import get_video_processing

        if not lists:
            from rest_framework.exceptions import ValidationError
            raise ValidationError("Не выбран список для нового документа")
        elif not file and not uri:
            from rest_framework.exceptions import ValidationError
            raise ValidationError("Не выбран файл для ссылка")
        if uri:
            current_uri = uri.replace("watch?v=", "embed/")
        else:
            current_uri = ""
        private = 0
        video = cls.objects.create(creator=creator,title=title,image=image,file=file,uri=current_uri,community=community)
        if community:
            community.plus_videos(1)
        else:
            creator.plus_videos(1)
        for list_id in lists:
            video_list = VideoList.objects.get(pk=list_id)
            video_list.video_list.add(video)
            if video_list.is_private():
                private = 1
        if not private and is_public:
            get_video_processing(video, Video.PUBLISHED)
            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, recipient_id=user_id, type="VID", object_id=video.pk, verb="ITE")
                #community_send_wall(video.pk, creator.pk, community.pk, None, "create_c_video_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="VID", object_id=video.pk, verb="ITE")
                    community_send_notify(video.pk, creator.pk, user_id, community.pk, None, "create_c_video_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="VID", object_id=video.pk, verb="ITE")
                #user_send_wall(video.pk, None, "create_u_video_wall")
                for user_id in creator.get_user_news_notify_ids():
                    Notify.objects.create(creator_id=creator.pk, recipient_id=user_id, type="VID", object_id=video.pk, verb="ITE")
                    user_send_notify(video.pk, creator.pk, user_id, None, "create_u_video_notify")
        else:
            get_video_processing(video, Video.PRIVATE)
        return video
Beispiel #8
0
    def create_photo(cls, creator, image, list):
        from common.processing import get_photo_processing

        photo = cls.objects.create(creator=creator, preview=image, file=image)
        list.photo_list.add(photo)
        if list.community:
            list.community.plus_photos(1)
        else:
            creator.plus_photos(1)
        if not list.is_private():
            get_photo_processing(photo, Photo.PUBLISHED)
            if list.community:
                from common.notify.progs import community_send_notify, community_send_wall
                from notify.models import Notify, Wall
                community_id = community.pk
                #Wall.objects.create(creator_id=creator.pk, community_id=community_id, recipient_id=user_id, type='PHO', object_id=photo.pk, verb="ITE")
                #community_send_wall(photo.pk, creator.pk, community_id, None, "create_c_photo_wall")
                for user_id in list.community.get_member_for_notify_ids():
                    Notify.objects.create(creator_id=creator.pk,
                                          community_id=community_id,
                                          recipient_id=user_id,
                                          type='PHO',
                                          object_id=photo.pk,
                                          verb="ITE")
                    community_send_notify(photo.pk, creator.pk, user_id,
                                          community_id, None,
                                          "create_c_photo_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='PHO', object_id=photo.pk, verb="ITE")
                #user_send_wall(photo.pk, None, "create_u_photo_wall")
                for user_id in creator.get_user_news_notify_ids():
                    Notify.objects.create(creator_id=creator.pk,
                                          recipient_id=user_id,
                                          type='PHO',
                                          object_id=photo.pk,
                                          verb="ITE")
                    user_send_notify(photo.pk, creator.pk, user_id, None,
                                     "create_u_photo_notify")
        else:
            get_photo_processing(photo, Photo.PRIVATE)
        return photo
Beispiel #9
0
    def create_track(cls, creator, title, file, lists, is_public, community):
        from common.processing import get_music_processing

        if not lists:
            from rest_framework.exceptions import ValidationError
            raise ValidationError("Не выбран список для нового документа")
        private = 0
        track = cls.objects.create(creator=creator,title=title,file=file)
        if community:
            community.plus_tracks(1)
        else:
            creator.plus_tracks(1)
        for list_id in lists:
            track_list = SoundList.objects.get(pk=list_id)
            track_list.playlist.add(track)
            if track_list.is_private():
                private = 1
        if not private and is_public:
            get_music_processing(track, Music.PUBLISHED)
            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, recipient_id=user_id, type="MUS", object_id=track.pk, verb="ITE")
                #community_send_wall(track.pk, creator.pk, community.pk, None, "create_c_track_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="MUS", object_id=track.pk, verb="ITE")
                    community_send_notify(track.pk, creator.pk, user_id, community.pk, None, "create_c_track_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="MUS", object_id=track.pk, verb="ITE")
                #user_send_wall(track.pk, None, "create_u_track_wall")
                for user_id in creator.get_user_news_notify_ids():
                    Notify.objects.create(creator_id=creator.pk, recipient_id=user_id, type="MUS", object_id=track.pk, verb="ITE")
                    user_send_notify(track.pk, creator.pk, user_id, None, "create_u_track_notify")
        else:
            get_music_processing(track, Music.PRIVATE)
        return track
Beispiel #10
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