Пример #1
0
    def construct_tabs(self, config):
        baseconf = Configuration.config()
        tabs = []

        ## Sort by label, but default (key="") always goes first
        configs = configuration_registry.copy()
        default = [("", configs.pop(""))]

        configs = default + sorted(configs.iteritems(), key=operator.itemgetter(1))
        for (related, (label, model, formclass)) in configs:
            instance = None
            form = None
            selected = False

            if related == config:
                if related:
                    try:
                        instance = getattr(baseconf, related).get()
                    except model.DoesNotExist:
                        pass
                else:
                    instance = baseconf
                form=formclass(instance=instance)
                selected = True
            tabs.append(dict(label=label,
                             related=related,
                             form=form,
                             selected=selected))
        return tabs
Пример #2
0
    def construct_tabs(self, config):
        baseconf = Configuration.config()
        tabs = []

        ## Sort by label, but default (key="") always goes first
        configs = configuration_registry.copy()
        default = configs.pop("")

        for section in [default] + sorted(configs.values(),
                                          key=operator.attrgetter("label")):
            instance = None
            form = None
            selected = False

            if section.id == config:
                if section.id and section.model:
                    try:
                        instance = getattr(baseconf, section.id).get()
                    except section.model.DoesNotExist:
                        pass
                else:
                    instance = baseconf
                if section.form:
                    form=section.form(instance=instance)
                selected = True
            tabs.append(dict(label=section.label,
                             related=section.id,
                             form=form,
                             selected=selected))

        return tabs
def configuration(request):
    """ make sure the 'config' context variable is always
        present since it contains information about the current
        theme """
    def is_logout_url():
        return request.path == reverse("userena_signout")

    return dict(config=Configuration.config(),
                settings=settings,
                root=Node.root(),
                is_logout_url=is_logout_url)
Пример #4
0
    def get_instance(self, config):
        instance = Configuration.config()
        klass = configuration_registry.get(config)

        if klass.model and config:
            try:
                instance = getattr(instance, config).get()
            except klass.model.DoesNotExist:
                instance = klass.model(main=instance)
                instance.save()
        return instance
Пример #5
0
    def test_import(self, client):
        """ test import of main and sub config """
        xml = """<site base="" version="1"><node id="1" tree_path=""><children /></node><config set=""><item name="id">1</item><item name="title">Test Site</item><item name="description">Test Description</item><item name="theme">default</item><item name="analytics" /><item name="head" /><item name="sender" /><item name="sendermail" /><item name="mailto" /></config><config set="testconf"><item name="value">conftest</item></config></site>"""

        root = Node.root()

        importer = Importer(root)
        tree = ElementTree.fromstring(xml)
        res = importer.run(tree)

        c = Configuration.config()
        assert c.title == "Test Site"
        assert c.description == "Test Description"
        assert c.testconf.all()[0].value == "conftest"
Пример #6
0
def contact_handler(handler, request, action):
    handler.context['form'] = ContactForm()
    if handler.post:
        handler.context['form'] = form = ContactForm(request.POST)
        if form.is_valid():
            sender = form.cleaned_data.get('sender', '')
            title = handler.instance.content().title
            message = form.cleaned_data.get('message', '')
            receiver = Configuration.config().mailto
            ip = get_client_ip(request)

            if not receiver:
                try:
                    receiver = settings.ADMINS[0][1]
                except IndexError:
                    error("No suitable receiver for contactform found",
                          data=dict(sender=sender, title=title, message=message))
                    return handler.redirect(handler.instance.path or '/',
                                    error="Unfortunately, something went wrong")


            body = """\
Message from %(sender)s @ %(ip)s

==

%(message)s
""" % dict(sender=sender, ip=ip, message=message)

            try:
                send_mail('Feedback from %s on "%s"' % (sender, title),
                          body,
                          sender,
                          [receiver],
                          fail_silently=False
                          )
            except (SMTPException, Exception):
                exception("failed to send form",
                          data=dict(sender=sender, title=title, message=message))
                return handler.redirect(handler.instance.path or '/',
                                        error="Unfortunately, something went wrong")

            ### Handle smtp issues! fail_silently=False
            return handler.redirect(handler.instance.path or '/',
                                    success="Your feedback has been sent")
    return render_to_response("wheelcms_simplecontact/contact.html",
                              handler.context)
Пример #7
0
    def process(self, config=""):
        instance = Configuration.config()
        (label, model, formclass) = configuration_registry.get(config)

        if config:
            try:
                instance = getattr(instance, config).get()
            except model.DoesNotExist:
                instance = model(main=instance)
                instance.save()

        self.context['form'] = form = \
                 formclass(self.request.POST, instance=instance)
        if form.is_valid():
            form.save()
            ## include hash, open tab
            return self.redirect(reverse('wheel_config'), config=config, success="Changes saved")
        self.context['tabs'] = self.construct_tabs(config)
        return self.template("wheelcms_axle/configuration.html")
Пример #8
0
    def test_export(self, client):
        """ Test export of main and sub config """
        c = Configuration.config()
        c.title = "Test Site"
        c.description = "Test Description"
        c.save()

        t = ConfigurationTest(main=c, value="conftest")
        t.save()

        root = Node.root()
        exporter = Exporter()
        xml, files = exporter.run(root)
        assert xml

        main = find_attribute(xml, "config", "set", "")
        testconf = find_attribute(xml, "config", "set", "testconf")

        assert main
        assert testconf

        assert find_attribute(main, "item", "name", "title").text == "Test Site"
        assert find_attribute(testconf, "item", "name", "value").text == "conftest"
Пример #9
0
def handle_comment_post(handler, request, action):
    """
        Action to create a comment on any Spoke
    """
    form = CommentForm(request.POST)
    if not form.is_valid():
        ## since we're redirecting, use sessions to temporarily store
        ## the comment data
        request.session['comment_post'] = request.POST
        return handler.redirect(handler.instance.get_absolute_url(),
                                error=ugettext("Please fix your errors"),
                                hash="commentform")

    name = request.POST.get('name')
    body = request.POST.get('body')
    captcha = request.POST.get('body')

    ## if someone tries really really hard...
    id = "%s-%s" % (timezone.now().strftime("%Y%m%d%H%M%S"),
                    random.randint(0,1000))
    title = _("Comment by %(owner)s on %(date)s") % \
              dict(owner=name, date=timezone.now())

    n = handler.instance.add(id)
    lang = get_active_language()

    c = Comment(title=title, name=name, body=body, node=n,
                state="pending", language=lang).save()

    if 'posted_comments' not in request.session:
        request.session['posted_comments'] = []
    request.session['posted_comments'].append(c.node.path)
    request.session.modified = True


    baseconf = BaseConfiguration.config()
    try:
        notify = baseconf.comments.get().notify_address.strip()
    except Configuration.DoesNotExist:
        notify = ""

    sender = baseconf.sendermail.strip()

    if notify and sender:
        content = handler.instance.content()
        domain = Site.objects.get_current().domain
        content_url = "http://%s%s" % (domain, content.get_absolute_url())
        comment_url = "http://%s%s" % (domain, n.get_absolute_url())

        send_mail('New comment on "%s"' % content.title,
        """A new comment has been posted on "%(title)s" %(content_url)s

Name: %(name)s
Content:
%(body)s

View/edit/delete comment: %(comment_url)sedit#collapseadvanced""" % dict(title=content.title,
                  content_url=content_url,
                  comment_url=comment_url,
                  name=name, body=body),

                  sender,
                  [notify],
                  fail_silently=True)

    ## log details (ip, etc) in description, or add extra fields
    ## send notification, if enabled
    ## optionally 'recognize' the user and show the comment only to him/her
    ## allow approval/rejection of comment through view?

    return handler.redirect(handler.instance.get_absolute_url(),
                            info="Your comment is being processed")
Пример #10
0
    def theme_css(self):
        theme = Configuration.config().themeinfo()

        return ",".join(theme.css_resources())