Ejemplo n.º 1
0
def our_comment(request,
                content_type,
                content_id,
                target_id,
                template_name="plus_comments/reply_form.html",
                **kwargs):

    if request.POST:
        if request.POST.has_key('parent_id'):
            parent_id = request.POST['parent_id']
        else:
            parent_id = None

        try:
            ret = free_comment(request,
                               content_type=content_type,
                               object_id=content_id,
                               parent_id=parent_id,
                               model=ThreadedComment,
                               form_class=ThreadedCommentForm)
        except Exception, e:
            raise e

        from django.contrib.contenttypes.models import ContentType
        ct = ContentType.objects.get(id=content_type)
        obj = ct.get_object_for_this_type(id=content_id)
        from apps.plus_feed.models import FeedItem
        FeedItem.post_COMMENT(request.user, obj)
        return ret
Ejemplo n.º 2
0
def create_group(request, site, template_name="plus_groups/create_group.html", current_app='plus_groups', **kwargs):

    if request.POST :
        form = TgGroupForm(request.POST)

        if not form.is_valid() :
            print form.errors
        else :
            group = form.save(request.user, site)

            from apps.plus_feed.models import FeedItem
            FeedItem.post_CREATE_GROUP(request.user, group.get_inner())

            return HttpResponseRedirect(reverse(current_app + ':group', args=(group.id,)))
    else :
        form = TgGroupForm()
    
    if current_app == 'groups' :
        name_of_created = "Group"
        is_hub = False
    else :
        name_of_created = hub_name()
        is_hub = True

    return render_to_response(template_name, {
            "head_title" : "Create New %s"%name_of_created,
            "name_of_created": name_of_created,
            "head_title_status" : "",
            "group" : form,
            "form" : form,
            "is_hub" : is_hub, 
            }, context_instance=RequestContext(request, current_app=current_app))
Ejemplo n.º 3
0
        def post_leave(self, user_or_group) :
            """ this method, a break out of other stuff which happens when members leave groups,
            can be called as an independent function from syncer"""

            from apps.plus_permissions.types.Profile import ProfileInterfaces
            from apps.plus_permissions.default_agents import get_all_members_group, get_admin_user
            # remove host erpermissions on profile when join/leave Hub
            admin = get_admin_user()
            admin_group = self.get_admin_group()
            if self.group_type == 'hub':
                for prof in ProfileInterfaces:
                    user_or_group.get_security_context().remove_arbitrary_agent(admin_group, 'Profile.%s' % prof, admin)

            from apps.plus_feed.models import FeedItem
            FeedItem.post_LEAVE(user_or_group, self)

            # stop following any group you leave .. not 100% certain this is what we want but our best guess
            from apps.microblogging.models import Following
            Following.objects.unfollow(user_or_group,self)


            # if I was the homehome for this user, change
            if user_or_group.homehub == self :
                user_or_group.homehub = get_all_members_group()
                user_or_group.save()
Ejemplo n.º 4
0
        def post_leave(self, user_or_group):
            """ this method, a break out of other stuff which happens when members leave groups,
            can be called as an independent function from syncer"""

            from apps.plus_permissions.types.Profile import ProfileInterfaces
            from apps.plus_permissions.default_agents import get_all_members_group, get_admin_user
            # remove host erpermissions on profile when join/leave Hub
            admin = get_admin_user()
            admin_group = self.get_admin_group()
            if self.group_type == 'hub':
                for prof in ProfileInterfaces:
                    user_or_group.get_security_context(
                    ).remove_arbitrary_agent(admin_group, 'Profile.%s' % prof,
                                             admin)

            from apps.plus_feed.models import FeedItem
            FeedItem.post_LEAVE(user_or_group, self)

            # stop following any group you leave .. not 100% certain this is what we want but our best guess
            from apps.microblogging.models import Following
            Following.objects.unfollow(user_or_group, self)

            # if I was the homehome for this user, change
            if user_or_group.homehub == self:
                user_or_group.homehub = get_all_members_group()
                user_or_group.save()
Ejemplo n.º 5
0
 def unfollow(self, follower, followed):
     try:
         following = self.get(follower_object_id=follower.id, followed_object_id=followed.id)
         following.delete()
         from apps.plus_feed.models import FeedItem
         FeedItem.post_UNFOLLOW(follower, followed)
     except Following.DoesNotExist:
         pass
Ejemplo n.º 6
0
 def unfollow(self, follower, followed):
     try:
         following = self.get(follower_object_id=follower.id,
                              followed_object_id=followed.id)
         following.delete()
         from apps.plus_feed.models import FeedItem
         FeedItem.post_UNFOLLOW(follower, followed)
     except Following.DoesNotExist:
         pass
Ejemplo n.º 7
0
def join(request, group,  template_name="plus_groups/group.html", current_app='plus_groups', **kwargs):

    group.join(request.user)

    # have to do this here, because models.join is too tied up with group creation 
    # permission infrastructure for group not sufficiently ready to create child FeedItems 
    from apps.plus_feed.models import FeedItem # avoid circularity                                                   
    FeedItem.post_JOIN(request.user, group)

    return HttpResponseRedirect(reverse(current_app + ':group',args=(group.id,)))
Ejemplo n.º 8
0
def add_link(request, target):
    if request.POST :
        form = LinkForm(request.POST)

        if form.is_valid() :
            link = target.create_Link(request.user, target=target, 
                                      text = form.cleaned_data['text'],
                                      url = form.cleaned_data['url'],
                                      service=form.cleaned_data['service'])
            
            from apps.plus_feed.models import FeedItem 
            FeedItem.post_ADD_LINK(request.user, target.get_inner(), form.cleaned_data['url'])

            link_html = get_template('plus_links/one_link.html').render(RequestContext(request, {'text':link.text, 'url':link.url, 'link_id':link.id, 'can_delete':hasattr(link, 'delete') and True or False}))
            data = simplejson.dumps({'new_link':link_html})
            return HttpResponse(data, mimetype='application/json')
        else :
            list_and_form_err = get_template('plus_links/errors.html').render(RequestContext(request, {'form_data':form.data, 'errors':form.errors, 'target_id':target.id, 'target_class':ContentType.objects.get_for_model(target.get_inner()).id}))
            data = simplejson.dumps({'list_and_form':list_and_form_err})
            return HttpResponse(data, mimetype='application/json')
Ejemplo n.º 9
0
def add_link(request, target):
    if request.POST:
        form = LinkForm(request.POST)

        if form.is_valid():
            link = target.create_Link(request.user,
                                      target=target,
                                      text=form.cleaned_data['text'],
                                      url=form.cleaned_data['url'],
                                      service=form.cleaned_data['service'])

            from apps.plus_feed.models import FeedItem
            FeedItem.post_ADD_LINK(request.user, target.get_inner(),
                                   form.cleaned_data['url'])

            link_html = get_template('plus_links/one_link.html').render(
                RequestContext(
                    request, {
                        'text': link.text,
                        'url': link.url,
                        'link_id': link.id,
                        'can_delete': hasattr(link, 'delete') and True or False
                    }))
            data = simplejson.dumps({'new_link': link_html})
            return HttpResponse(data, mimetype='application/json')
        else:
            list_and_form_err = get_template('plus_links/errors.html').render(
                RequestContext(
                    request, {
                        'form_data':
                        form.data,
                        'errors':
                        form.errors,
                        'target_id':
                        target.id,
                        'target_class':
                        ContentType.objects.get_for_model(
                            target.get_inner()).id
                    }))
            data = simplejson.dumps({'list_and_form': list_and_form_err})
            return HttpResponse(data, mimetype='application/json')
Ejemplo n.º 10
0
def create_wiki_page(request,
                     group,
                     page_name,
                     template_name="plus_wiki/create_wiki.html",
                     current_app='plus_groups',
                     **kwargs):
    """creates OR saves WikiPages
    """

    try:
        obj = WikiPage.objects.plus_get(request.user,
                                        name=page_name,
                                        in_agent=group.get_ref())
    except:
        raise Http404
    post_kwargs = request.POST.copy()
    post_kwargs['obj'] = obj
    form = EditWikiForm(post_kwargs)

    if "delete_submit" in post_kwargs:
        if post_kwargs.has_key('delete_check'):
            obj.delete()
            return HttpResponseRedirect(
                reverse(current_app + ':group', args=[group.id]))

    if "move_resource_submit" in post_kwargs:
        form = MoveResourceForm(post_kwargs)
        form.user = request.user  # essential, user is checked inside form validation
        if form.is_valid():
            new_parent_group = form.cleaned_data['new_parent_group']
            obj.move_to_new_group(new_parent_group)
            revision.user = request.user
            return HttpResponseRedirect(
                reverse(current_app + ':group',
                        args=[form.cleaned_data['new_parent_group'].id]))

    if form.is_valid():
        title = form.cleaned_data['title']
        content = form.cleaned_data['content']
        license = form.cleaned_data['license']
        copyright_holder = form.cleaned_data['copyright_holder']
        name = form.cleaned_data['name']
        if request.POST.get('preview', None):
            return render_to_response(template_name, {
                'page':
                TemplateSecureWrapper(obj),
                'data':
                form.data,
                'preview_content':
                content,
                'form_action':
                reverse(current_app + ":create_WikiPage",
                        args=[obj.in_agent.obj.id, obj.name])
            },
                                      context_instance=RequestContext(
                                          request, current_app=current_app))
        else:
            if obj.stub:  # we should change the "created_by" on the genericreference/permissions system to "owner"
                obj.created_by = request.user
                revision.comment = 'Original'
            else:
                revision.comment = form.cleaned_data['what_changed']

            revision.user = request.user
            diff = htmldiffer(
                AttrDict({
                    'title': title,
                    'content': content,
                    'license': license
                }), obj)
            diff = json.dumps(diff)
            #XXX this diff needs to only include things in the proximity of an insertion or deletion
            revision.add_meta(VersionDelta, delta=diff)
            obj.title = title
            obj.set_name(name)
            obj.content = content
            obj.license = license
            obj.copyright_holder = copyright_holder
            obj.stub = False
            obj.save()

            from apps.plus_feed.models import FeedItem
            FeedItem.post_WIKI_PAGE(request.user, obj)

            return HttpResponseRedirect(
                reverse(current_app + ':view_WikiPage',
                        args=[group.id, obj.name]))

    return render_to_response(template_name, {
        'page':
        TemplateSecureWrapper(obj),
        'revision':
        revision,
        'data':
        form.data,
        'errors':
        form.errors,
        'form_action':
        reverse(current_app + ":create_WikiPage",
                args=[obj.in_agent.obj.id, obj.name])
    },
                              context_instance=RequestContext(
                                  request, current_app=current_app))
Ejemplo n.º 11
0
def edit_resource(request,
                  group,
                  resource_name,
                  template_name='plus_resources/upload.html',
                  success_url=None,
                  current_app="plus_groups",
                  **kwargs):

    if not group:
        raise Http404(_('This group does not exist'))

    try:
        secure_upload = Resource.objects.plus_get(request.user,
                                                  name=resource_name,
                                                  in_agent=group.get_ref())
    except Resource.DoesNotExist:
        raise Http404

    if secure_upload.name:
        old_name = secure_upload.name
    else:
        old_name = ''

    try:
        secure_upload.get_all_sliders
        perms_bool = True
    except PlusPermissionsNoAccessException:
        perms_bool = False

    if request.POST:
        post_kwargs = request.POST.copy()
        post_kwargs['obj'] = secure_upload

        if "delete_submit" in post_kwargs:
            if post_kwargs.has_key('delete_check'):
                secure_upload.delete()
                return HttpResponseRedirect(
                    reverse(current_app + ':group', args=[group.id]))

        if "move_resource_submit" in post_kwargs:
            form = MoveResourceForm(post_kwargs)
            form.user = request.user  # essential, user is checked inside form validation
            if form.is_valid():
                new_parent_group = form.cleaned_data['new_parent_group']
                try:
                    secure_upload.move_to_new_group(new_parent_group)
                except Exception, e:
                    print e

                return HttpResponseRedirect(
                    reverse(current_app + ':group',
                            args=[form.cleaned_data['new_parent_group'].id]))

        form = UploadFileForm(post_kwargs, request.FILES, user=request.user)

        if form.is_valid():
            a_file = form.cleaned_data['resource']

            resource = update_attributes(
                secure_upload,
                request.user,
                title=form.cleaned_data['title'],
                name=form.cleaned_data['name'],
                license=form.cleaned_data['license'],
                author=form.cleaned_data['author'],
                description=form.cleaned_data['description'],
                resource=a_file)

            resource.stub = False
            resource.in_agent = group.get_ref()

            # don't allow name to change as this affects the url
            if old_name:
                resource.name = old_name
            resource.save()

            if not success_url:
                success_url = reverse(current_app + ':view_Resource',
                                      args=(group.id, resource.name))

            from apps.plus_feed.models import FeedItem
            FeedItem.post_UPLOAD(request.user, resource)

            return HttpResponseRedirect(success_url)

        else:
            pass
Ejemplo n.º 12
0
 def __set__(self, profile, val):
     from apps.plus_feed.models import FeedItem
     FeedItem.post_STATUS(profile.user, profile.user, val)
Ejemplo n.º 13
0
 def follow(self, follower, followed):
     if follower != followed and not self.is_following(follower, followed):
         Following(follower_content_object=follower, followed_content_object=followed).save()
         from apps.plus_feed.models import FeedItem
         FeedItem.post_FOLLOW(follower, followed)
Ejemplo n.º 14
0
 def follow(self, follower, followed):
     if follower != followed and not self.is_following(follower, followed):
         Following(follower_content_object=follower,
                   followed_content_object=followed).save()
         from apps.plus_feed.models import FeedItem
         FeedItem.post_FOLLOW(follower, followed)
Ejemplo n.º 15
0
def edit_resource(request, group, resource_name,  
                  template_name='plus_resources/upload.html', success_url=None, current_app="plus_groups", **kwargs) :


    if not group :
        raise Http404(_('This group does not exist'))
 
    try:
        secure_upload = Resource.objects.plus_get(request.user, name=resource_name, in_agent=group.get_ref())
    except Resource.DoesNotExist:
        raise Http404

    if secure_upload.name :
        old_name = secure_upload.name
    else :
        old_name = ''

    try:
        secure_upload.get_all_sliders
        perms_bool = True
    except PlusPermissionsNoAccessException:
        perms_bool = False

    if request.POST:
        post_kwargs = request.POST.copy()
        post_kwargs['obj'] = secure_upload

        if "delete_submit" in post_kwargs :
            if post_kwargs.has_key('delete_check') :
                secure_upload.delete()
                return HttpResponseRedirect(reverse(current_app + ':group', args=[group.id]))

        if "move_resource_submit" in post_kwargs :
            form = MoveResourceForm(post_kwargs)
            form.user = request.user # essential, user is checked inside form validation
            if form.is_valid() :
                new_parent_group = form.cleaned_data['new_parent_group']
                try :
                    secure_upload.move_to_new_group(new_parent_group)
                except Exception, e :
                    print e

                return HttpResponseRedirect(reverse(current_app + ':group', args=[form.cleaned_data['new_parent_group'].id]))

        form = UploadFileForm(post_kwargs, request.FILES, user=request.user)

        if form.is_valid():
            a_file = form.cleaned_data['resource']

            resource = update_attributes(secure_upload, request.user,
                                         title = form.cleaned_data['title'],
                                         name  = form.cleaned_data['name'],
                                         license = form.cleaned_data['license'],
                                         author = form.cleaned_data['author'],
                                         description = form.cleaned_data['description'],
                                         resource = a_file)
   
            resource.stub = False
            resource.in_agent = group.get_ref()

            # don't allow name to change as this affects the url
            if old_name :
                resource.name = old_name
            resource.save()
            
            if not success_url :
                success_url = reverse(current_app + ':view_Resource', args=(group.id, resource.name))
           
            from apps.plus_feed.models import FeedItem
            FeedItem.post_UPLOAD(request.user, resource)

            return HttpResponseRedirect(success_url)
                 
        else:
            pass
Ejemplo n.º 16
0
 def save(self):
     if self.cleaned_data['text'] :
         # only bother if there's something in it
         FeedItem.post_STATUS(self.sender,self.cleaned_data['text'])
Ejemplo n.º 17
0
def create_wiki_page(request, group, page_name, template_name="plus_wiki/create_wiki.html", current_app='plus_groups', **kwargs):
    """creates OR saves WikiPages
    """

    try:
        obj = WikiPage.objects.plus_get(request.user, name=page_name, in_agent=group.get_ref())
    except:
        raise Http404
    post_kwargs = request.POST.copy()
    post_kwargs['obj'] = obj
    form = EditWikiForm(post_kwargs)

    if "delete_submit" in post_kwargs :
        if post_kwargs.has_key('delete_check') :
            obj.delete()
            return HttpResponseRedirect(reverse(current_app + ':group', args=[group.id]))

    if "move_resource_submit" in post_kwargs :
        form = MoveResourceForm(post_kwargs)
        form.user = request.user # essential, user is checked inside form validation                                     
        if form.is_valid() :
            new_parent_group = form.cleaned_data['new_parent_group']
            obj.move_to_new_group(new_parent_group)
            revision.user = request.user
            return HttpResponseRedirect(reverse(current_app + ':group', 
                                                args=[form.cleaned_data['new_parent_group'].id]))


    if form.is_valid():
        title = form.cleaned_data['title']
        content = form.cleaned_data['content']
        license = form.cleaned_data['license']
        copyright_holder = form.cleaned_data['copyright_holder']
        name = form.cleaned_data['name']
        if request.POST.get('preview', None):
            return render_to_response(template_name, 
                                      {'page':TemplateSecureWrapper(obj),
                                       'data':form.data,
                                       'preview_content': content,
                                       'form_action':reverse(current_app + ":create_WikiPage", args=[obj.in_agent.obj.id, obj.name])}, 
                                      context_instance=RequestContext(request, current_app=current_app))
        else:
            if obj.stub: # we should change the "created_by" on the genericreference/permissions system to "owner"
                obj.created_by = request.user
                revision.comment = 'Original'
            else:
                revision.comment = form.cleaned_data['what_changed']

            revision.user = request.user
            diff = htmldiffer(AttrDict({'title':title, 'content':content, 'license': license}), obj)
            diff = json.dumps(diff)
            #XXX this diff needs to only include things in the proximity of an insertion or deletion
            revision.add_meta(VersionDelta, delta=diff)
            obj.title = title
            obj.set_name(name)
            obj.content = content
            obj.license = license
            obj.copyright_holder = copyright_holder
            obj.stub = False
            obj.save()

            from apps.plus_feed.models import FeedItem
            FeedItem.post_WIKI_PAGE(request.user, obj)


            return HttpResponseRedirect(reverse(current_app + ':view_WikiPage', args=[group.id, obj.name]))

    return render_to_response(template_name, 
                              {'page':TemplateSecureWrapper(obj),
                               'revision':revision,
                               'data':form.data,
                               'errors': form.errors,
                               'form_action':reverse(current_app + ":create_WikiPage", 
                                                     args=[obj.in_agent.obj.id, obj.name])}, 
                              context_instance=RequestContext(request, current_app=current_app))
Ejemplo n.º 18
0
 def __set__(self,profile,val):
     from apps.plus_feed.models import FeedItem
     FeedItem.post_STATUS(profile.user, profile.user,val)
Ejemplo n.º 19
0
 def save(self):
     if self.cleaned_data['text']:
         # only bother if there's something in it
         FeedItem.post_STATUS(self.sender, self.cleaned_data['text'])