Example #1
0
    def clean(self):
        self.mode = {}
        self.obfuscation = {}
#        for type in self.allowed_types:
#            setattr(self.local, type, [])
        self.local = []
            
        #apply global config
        self.mode['css'] = get_settings("COMPRESSOR_CSS_MODE", COMPRESSOR_MODE_ONE_FILE)
        self.mode['js'] = get_settings("COMPRESSOR_JS_MODE", COMPRESSOR_MODE_ONE_FILE)

        self.obfuscation['css'] = get_settings("COMPRESSOR_CSS_OBFUSCATION", True)
        self.obfuscation['js'] = get_settings("COMPRESSOR_JS_OBFUSCATION", True)
Example #2
0
from apps.tools.shortcuts import get_settings
from django.conf import settings
import os


PROCESSOR_LIST = get_settings(
    "COMPRESSOR_PROCESSORS",
    [
        "apps.compressor.coffee_script.CoffeeCompiler",
        "apps.compressor.processors.OneFile",
        "apps.compressor.processors.Inline",
        "apps.compressor.processors.Links",
    ],
)


COMPRESSOR_MODE_ONE_FILE = 1
COMPRESSOR_MODE_LINKS = 2
COMPRESSOR_MODE_INLINE = 3


COMPRESSOR_MARKER = {"css": "<!--[*CSS*]-->", "js": "<!--[*JS*]-->"}


COMPRESSOR_CACHE_PREFIX = "cache"

COMPRESSOR_CACHE_ROOT = get_settings(
    "COMPRESSOR_CACHE_ROOT", os.path.join(settings.MEDIA_ROOT, COMPRESSOR_CACHE_PREFIX)
)
COMPRESSOR_CACHE_URL = get_settings("COMPRESSOR_CACHE_URL", settings.MEDIA_URL + COMPRESSOR_CACHE_PREFIX + "/")
COMPRESSOR_ONE_FILE_IGNORE = get_settings("COMPRESSOR_ONE_FILE_IGNORE", [])
Example #3
0
# -*- coding: utf-8 -*-
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.db import models
from django.utils.translation import ugettext_lazy as _
from apps.tools.shortcuts import get_settings
from apps.tools.text_parser import add_noindex_to_a
from pytils import translit


__all__ = ("Block",)

STATIC_BLOCKS_USE_CACHE = get_settings("STATIC_BLOCKS_USE_CACHE", True)
STATIC_BLOCKS_CACHE_KEY = get_settings("STATIC_BLOCKS_CACHE_KEY", "sb_%s_%s")
STATIC_BLOCKS_CACHE_TIMEOUT = get_settings("STATIC_BLOCKS_CACHE_TIMEOUT", 86400)  # 1 day


# Create your models here.
class Block(models.Model):
    site = models.ForeignKey(Site, default=settings.SITE_ID)
    address = models.SlugField(_("address"), blank=True, db_index=True)  # unique=True, - exclude for Language

    title = models.CharField(_("title"), blank=True, max_length=200)
    content = models.TextField(_("content"), blank=True)
    use_title = models.BooleanField(_("use title"), default=True)

    __unicode__ = lambda self: u"%s" % self.title

    def save(self, *args, **kwargs):
Example #4
0
import os
from django.conf import settings
from apps.tools.class_loader import app_path_by_name
import re
from apps.tools.shortcuts import get_settings
from django.core.cache import cache
from apps.compressor.base import compressor



COMPRESSOR_USE_CACHE_FOR_SEARCH_MEDIA = get_settings("COMPRESSOR_USE_CACHE_FOR_SEARCH_MEDIA", False)
COMPRESSOR_CHACE_PREFIX = "compr_"

def search_media(value):
    #check full path
    if os.path.exists(value):
        return value

    if COMPRESSOR_USE_CACHE_FOR_SEARCH_MEDIA:
        ret = cache.get("%s|%s" % (COMPRESSOR_CHACE_PREFIX, value), -1)
        if ret!=-1:
            return ret
        
    path_name = os.path.join(settings.MEDIA_ROOT, value)
    if os.path.exists(path_name):
        if COMPRESSOR_USE_CACHE_FOR_SEARCH_MEDIA:
            cache.set("%s|%s" % (COMPRESSOR_CHACE_PREFIX, value), path_name)        
        return path_name
    
    for apps in settings.INSTALLED_APPS:
        path_name = os.path.join(app_path_by_name(apps), 'media', value)
Example #5
0
from apps.simple_feedback.forms import FeedbackForm
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.encoding import force_unicode
from django.conf import settings
from apps.tools.shortcuts import get_settings
from django.template.loader import render_to_string
from apps.tools.mail import send_mail
from django.utils.translation import ugettext
from apps.tools.decorators import render_to

FEEDBACK_EMAILS = get_settings("FEEDBACK_EMAILS", [])


@render_to
def form(req):
    out={}
    form_kwargs = {'initial': dict(map(lambda key: (key, force_unicode(req.GET[key])), req.GET))}
    if req.POST:
        out['form'] = form = FeedbackForm(req.POST, **form_kwargs)
        if form.is_valid():
            feedback = form.save()
            
            if FEEDBACK_EMAILS:
                
                send_mail(
                    ugettext('%(project_name)s: feedback') % {"project_name": settings.SITE_NAME},
                    render_to_string("simple_feedback/email.html", {
                        'site_name': settings.SITE_NAME,
                        'feedback':feedback, 
                        'url': '%s/admin/simple_feedback/feedback/%s/' % (settings.SITE_URL, feedback.id),
Example #6
0
from apps.tools.shortcuts import get_settings
from django.conf import settings
import os
import subprocess
import time

COMPRESS_STATIC_CLOSURE_BIN = get_settings('COMPRESSOR_YUICOMPRESSOR_BIN', "java -jar " + os.path.join(os.path.dirname(__file__), "..", "bin", "yuicompressor-2.4.6.jar"))


def obfuscator(content, type):
    if settings.DEBUG:
        begin = time.time()
        print "YuiCompressor: run obfuscator..."
        
    p = subprocess.Popen(COMPRESS_STATIC_CLOSURE_BIN+" --type %s" % type, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
    p.stdin.write(content.encode('utf-8'))
    p.stdin.close()
    
    new_content = p.stdout.read()
    p.stdout.close()
    
    errors = p.stderr.read()
    p.stderr.close()
#    
    if settings.DEBUG:
        old_len = len(content)
        new_len = len(new_content)
        delta = old_len - new_len
        
        print "YuiCompressor: source content size:", old_len
        print "YuiCompressor: new content size:", new_len        
Example #7
0
from apps.compressor.consts import FILE_MARKER
from apps.tools.shortcuts import get_settings
from django.conf import settings
import os
import subprocess
import time
import re

COMPRESS_STATIC_CLOSURE_BIN = get_settings('COMPRESSOR_GOOGLE_CLOSURE_BIN', "java -jar " + os.path.join(os.path.dirname(__file__), "..", "bin", "compiler.jar"))

class ObfuscatorError(Exception):
    
    def __init__(self, errors, content):
        self.errors = errors
        self.content = content.split("\n")
        
        
    def __unicode__(self):
        parsed = []
        unparsed = []
        
        for err_line in self.errors.split("stdin:"):
            if not err_line:
                continue            
            err = err_line.split(":")
            
            if len(err)<2:
                unparsed.append(err_line)
                continue
            line_num = int(err[0])
            #getfile name
Example #8
0
"""
author:Kovalenko Pavel ([email protected])  
"""
from xml.dom import minidom, Node
import os
from django.core.urlresolvers import reverse, get_urlconf
import re
from django.conf import settings
from apps.tools.class_loader import get_class_by_string
from apps.xml_menu.patch_urlresolvers import resolve2
from apps.tools.shortcuts import get_settings



DEFAULT_MENU = os.path.join(settings.PROJECT_ROOT,get_settings("XML_MENU_FILE", os.path.join("settings","menu.xml")))
root_item=None

def get_attr(node, attr_name):
    for attr in node.attributes.items():
        if attr[0]==attr_name:
            return attr[1]
    raise Exception('Unknown attribute "%s" in "%s"' % (attr_name, node.tagName))


def safe_get_attr(node, attr_name):
    for attr in node.attributes.items():
        if attr[0]==attr_name:
            return attr[1]
    return None