Example #1
0
class DanglingTags(TestCase):
    """
    Regression tests for
    https://office.ewb.ca/fastrac/myewb2/ticket/395
    """

    def setUp(self):
        # if we decide to truncate over 600 chars, increase this test string!!
        self.topic = GroupTopic(body="<div>this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends...  </div>")

    def test_dangling_tags(self):
        self.assertEquals(self.topic.intro()[-9:], "</div>...")
        
Example #2
0
class DanglingTags(TestCase):
    """
    Regression tests for
    https://office.ewb.ca/fastrac/myewb2/ticket/395
    """
    def setUp(self):
        # if we decide to truncate over 600 chars, increase this test string!!
        self.topic = GroupTopic(
            body=
            "<div>this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends...  </div>"
        )

    def test_dangling_tags(self):
        self.assertEquals(self.topic.intro()[-9:], "</div>...")
Example #3
0
 def setUp(self):
     # if we decide to truncate over 600 chars, increase this test string!!
     self.topic = GroupTopic(body="<div>this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends...  </div>")
Example #4
0
def new_topic(request, group_slug=None, bridge=None):
    is_member = False
    group = None
    if group_slug is None:
        group_slug = "ewb"

    group = get_object_or_404(BaseGroup, slug=group_slug)
    is_member = group.user_is_member(request.user, admin_override=True)

    if not group.is_visible(request.user):
        return HttpResponseForbidden()

    attach_count = 0
    if request.method == "POST":
        if not request.user.is_authenticated():
            return HttpResponseForbidden()
        try:
            attach_count = int(request.POST.get("attach_count", 0))
        except ValueError:
            attach_count = 0

        if group.slug == "ewb" or is_member:
            # has been previewed.  mark it as good to go!
            if request.POST.get("previewed", None) and request.POST.get(
                    "postid", None):
                topic = GroupTopic.objects.get(id=request.POST['postid'],
                                               creator=request.user)
                if topic.pending:
                    topic.pending = False
                    topic.save()

                    # extra security check that sender isn't forged.
                    # can't hurt...
                    sender_valid = False
                    if group.user_is_admin(request.user) and request.POST.get(
                            'sender', None):
                        if request.POST['sender'] == group.from_email:
                            sender_valid = True
                            sender = '"%s" <%s>' % (group.from_name,
                                                    group.from_email)

                        elif get_object_or_none(
                                EmailAddress, email=request.POST['sender']
                        ) in request.user.get_profile().email_addresses():
                            sender_valid = True
                            sender = '"%s %s" <%s>' % (
                                request.user.get_profile().first_name,
                                request.user.get_profile().last_name,
                                request.POST['sender'])

                        elif request.user.is_staff and request.POST[
                                'sender'] == "*****@*****.**":
                            sender_valid = True
                            sender = '"EWB-ISF Canada" <*****@*****.**>'

                    if topic.send_as_email:
                        if sender_valid:
                            request.user.message_set.create(
                                message=escape("Sent as %s" % sender))
                            topic.send_email(sender=sender)
                        else:
                            request.user.message_set.create(
                                message="Unable to send email.")

                    # redirect out.
                    request.user.message_set.create(
                        message=_("You have started the topic %(topic_title)s")
                        % {"topic_title": topic.title})

                else:
                    # probably double-clicked the submit button and this is the dupe request...
                    pass

                return HttpResponseRedirect(topic.get_absolute_url())

            # confirmation was cancelled, so delete the temp post and bump back to edit screen
            topic = None
            if request.POST.get("goback", None) and request.POST.get(
                    "postid", None):
                topic = get_object_or_none(GroupTopic,
                                           id=request.POST['postid'],
                                           pending=True,
                                           creator=request.user)

            if topic:
                topic_form = GroupTopicForm(instance=topic,
                                            user=request.user,
                                            group=group)
                attach_forms = []
                topic.delete()

            # validate form and show preview...
            else:
                topic_form = GroupTopicForm(request.POST,
                                            user=request.user,
                                            group=group)
                attach_forms = [
                    AttachmentForm(request.POST,
                                   request.FILES,
                                   prefix=str(x),
                                   instance=Attachment())
                    for x in range(0, attach_count)
                ]

                # do not take blank attachment forms into account
                for af in attach_forms:
                    if not af.is_valid() and not af['attachment_file'].data:
                        attach_forms.remove(af)
                        attach_count = attach_count - 1

                # all good.  save it!
                if topic_form.is_valid() and all([
                        af.is_valid() for af in attach_forms
                ]) and not request.POST.get("goback", None):
                    # save the post but mark it as "pending".... and display a confirmation.
                    topic = topic_form.save(commit=False)
                    if group:
                        group.associate(topic, commit=False)
                    topic.creator = request.user
                    topic.pending = True
                    topic.save()

                    # save the attachments.
                    # We need the "Topic" object in order to retrieve attachments properly
                    # since other functions only get the Topic object
                    base_topic = GroupTopic.objects.get(id=topic.id)
                    attachments = []
                    for af in attach_forms:
                        attachment = af.save(request, base_topic)
                        attachments.append(
                            af.cleaned_data['attachment_file'].name)

                    sender = None
                    if topic_form.cleaned_data.get('send_as_email', None):
                        sender = topic_form.cleaned_data.get('sender', None)

                    is_large_group = False
                    if group.members.count() > 50:
                        is_large_group = True

                    return render_to_response(
                        "topics/preview.html", {
                            "group": group,
                            "topic": topic,
                            "is_member": is_member,
                            "sender": sender,
                            "attachments": attachments,
                            "is_large_group": is_large_group,
                        },
                        context_instance=RequestContext(request))
        else:
            # if they can't start a topic, why are we still loading up a form?
            request.user.message_set.create(message=_(
                "You are not a member and so cannot start a new topic"))
            topic_form = GroupTopicForm(instance=GroupTopic())
            attach_forms = [
                AttachmentForm(prefix=str(x), instance=Attachment())
                for x in range(0, attach_count)
            ]

    else:
        topic_form = GroupTopicForm(instance=GroupTopic(),
                                    user=request.user,
                                    group=group)
        attach_forms = []

    return render_to_response("topics/new_topic.html", {
        "group": group,
        "topic_form": topic_form,
        "attach_forms": attach_forms,
        "attach_count": attach_count,
        "is_member": is_member,
    },
                              context_instance=RequestContext(request))
Example #5
0
def topics(request,
           group_slug=None,
           form_class=GroupTopicForm,
           attach_form_class=AttachmentForm,
           template_name="topics/topics.html",
           bridge=None,
           mode=None):

    if request.is_ajax() or request.GET.get('ajax', None):
        template_name = "topics/topics_ajax.html"

    # kinda hack-ish.  but the easiest way; doesn't feel worth adding an AJAX param for this.
    if group_slug == 'featured':
        mode = 'featured'
        group_slug = None

    is_member = False
    group = None
    if group_slug is not None:
        group = get_object_or_404(BaseGroup, slug=group_slug)
        is_member = group.user_is_member(request.user, admin_override=True)

    if group and not group.is_visible(request.user):
        return HttpResponseForbidden()

    attach_count = 0
    if request.method == "POST" and group:
        return new_topic(request, group_slug)
    else:
        topic_form = form_class(instance=GroupTopic(),
                                user=request.user,
                                group=group)

        attach_forms = []

    # if it's a listing by group, check group visibility
    if group:
        topics = GroupTopic.objects.get_for_group(group)

    # otherwise throw up a generic listing of visible posts
    else:
        # generic topic listing: show posts from groups you're in
        # also shows posts from public groups...
        # for guests, show posts from public groups only
        topics = GroupTopic.objects.visible(user=request.user)

    if mode == 'featured':
        topics = GroupTopic.objects.featured(topics)
    elif mode == 'newposts' and request.user.is_authenticated():
        topics = GroupTopic.objects.since(
            request.user.get_profile().previous_login, qs=topics)
    elif mode == 'newreplies' and request.user.is_authenticated():
        topics = GroupTopic.objects.replies_since(
            request.user.get_profile().previous_login, qs=topics)

    if request.user.is_authenticated():
        can_adminovision = user_can_adminovision(request.user)
        can_execovision = user_can_execovision(request.user)
        adminovision = request.user.get_profile().adminovision

        if not request.user.get_profile().show_emails:
            topics = GroupTopic.objects.exclude_emails(topics)

    else:
        can_adminovision = False
        can_execovision = False
        adminovision = False

    # also kinda hackish
    if group and group.slug == "ewb":
        group = None
        mode = "frontpage"
    elif not group and not mode:
        mode = "latest"

    return render_to_response(
        template_name,
        {
            "group": group,
            "topic_form": topic_form,
            "attach_forms": attach_forms,
            "attach_count": attach_count,
            "is_member": is_member,
            "topics": topics,
            "can_adminovision": can_adminovision,
            "can_execovision": can_execovision,
            "adminovision": adminovision,
            "login_form": EmailLoginForm(),  # for front-page toolbar
            "mode": mode
        },
        context_instance=RequestContext(request))
Example #6
0
 def setUp(self):
     # if we decide to truncate over 600 chars, increase this test string!!
     self.topic = GroupTopic(
         body=
         "<div>this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends... this is the div that never ends... yes it goes on and on my friends...  </div>"
     )