Exemplo n.º 1
0
    def filter_images(self, request, *args, **kwargs):
        query = request.GET.get('q')
        if query:
            if self.search_fields is None:
                self.search_fields = ('keywords', )
            lookups = ["%s__icontains" % field for field in self.search_fields]
            bits = query.split()

            site = None
            if request.session[CURRENT_SITE_FILTER] != '':
                site = Site.query().get(
                    pk=request.session[CURRENT_SITE_FILTER])

            queryset = Image.query()
            for bit in bits:
                if site and WIDGET_SITE_SPECIFIC_IMAGES:
                    queryset = queryset.filter(pk__in=[
                        str(pk)
                        for pk in site['images'].values_list('pk', flat=True)
                    ])
                queryset = queryset.filter_if_any(*[{
                    lookup: bit
                } for lookup in lookups])
            return JsonResponse(queryset.values('name'))
        return JsonResponse()
Exemplo n.º 2
0
    def process_request(self, request):
        request.site = None

        # Try using site detecting function
        if app_settings.DETECTING_FUNCTION:
            try:
                func = import_anything(app_settings.DETECTING_FUNCTION)
                site_or_mirror = func(request)

                if isinstance(site_or_mirror, SiteMirror):
                    request.site = site_or_mirror['site']
                    if app_settings.MIRROR_PERMANENT_REDIRECT:
                        scheme = 'https' if (request.is_secure() or site_or_mirror['https_is_default']) else 'http'
                        new_hostname = site_or_mirror['site']['hostname']
                        if request.META.get('SERVER_PORT', 80) != 80:
                            new_hostname += ':%s'%request.META['SERVER_PORT']
                        return HttpResponsePermanentRedirect('%s://%s/'%(scheme, new_hostname))
                else:
                    request.site = site_or_mirror
            except ImportError:
                pass

        # Treats the inactive site
        if ((not request.site or not request.site['is_active']) and
            not app_settings.ACCEPT_INACTIVE_SITE and
            app_settings.INACTIVE_SITE_VIEW):
            view = import_anything(INACTIVE_SITE_VIEW)
            return view(request)

        # Creates a new site if there is no site existing
        if Site.query().count() == 0 and app_settings.CREATE_SITE_IF_EMPTY:
            request.site = Site(_save=True, name='localhost', hostname='localhost', default=True, active=True)
Exemplo n.º 3
0
    def get_initial(self, initial=None):
        initial = initial or super(PageForm, self).get_initial(initial)

        # Filter author users if user hasn't permissions to view them all
        if not self.request.user.has_perm('auth.edit_user', self.request.site):
            self.fields['author'].queryset = self.fields['author'].queryset(
                self).filter(pk=self.request.user['pk'])

        page_query = Page.query()
        if self.request.session[CURRENT_SITE_FILTER] != '':
            site = Site.query().get(
                pk=self.request.session[CURRENT_SITE_FILTER])
            page_query = page_query.filter(site=site)

        if self.instance['pk']:
            #exclude self page from the list of similar ones
            page_query = page_query.exclude(
                pk=self.instance['pk']).order_by('name')
        else:
            # setting initial author for new page
            initial['author'] = str(self.request.user['pk'])

        self.fields['parent_page'].queryset = page_query
        signals.page_form_initialize.send(sender=self,
                                          initial=initial,
                                          publish_field_name='is_published')
        return initial
Exemplo n.º 4
0
    def set_site(self, request, pk, **kwargs):
        """Select the current site to filter in Admin for this session."""
        del request.session[CURRENT_SITE_FILTER]

        # If no site exists for the given PK, let it empty
        if pk == '-unselect-':
            request.session[CURRENT_SITE_FILTER] = ''
        elif Site.query().filter(pk=pk).count() > 0:
            request.session[CURRENT_SITE_FILTER] = pk

        return JsonResponse('{"status":"ok", "redirect":"%s"}' % request.GET['goto'] if 'goto' in request.GET else '')
Exemplo n.º 5
0
def list(request, template='post_list', site=None, queryset_function=None):
    if isinstance(site, basestring):
        site = Site.query().get(name=site)

    if not site:
        site = request.site

    if callable(queryset_function):
        posts = queryset_function(request)
    else:
        posts = site['posts']

    return render_to_response(request, template, {'posts': posts})
def basic(request):
    ret = {'admin_site': admin.site}

    if getattr(request, 'session', None):
        # If there is a selected site
        if request.session.get(CURRENT_SITE_FILTER, None) is not None:
            ret['admin_selected_site'] = request.session[CURRENT_SITE_FILTER]
        else:
            if getattr(request, 'site', None):
                ret['admin_selected_site'] = str(request.site['pk'])
                request.session[CURRENT_SITE_FILTER] = str(request.site['pk'])
            else:
                sites = Site.query().active().filter(is_default = True)
    
                if sites.count() > 0:
                    ret['admin_selected_site'] = str(sites[0]['pk'])
                elif Site.query().active().count():
                    ret['admin_selected_site'] = str(Site.query().active()[0]['pk'])
                else:
                    ret['admin_selected_site'] = None

    return ret
Exemplo n.º 7
0
def list(request, template='post_list', site=None, queryset_function=None):
    if isinstance(site, basestring):
        site = Site.query().get(name=site)

    if not site:
        site = request.site

    if callable(queryset_function):
        posts = queryset_function(request)
    else:
        posts = site['posts']

    return render_to_response(request, template, {'posts':posts})
Exemplo n.º 8
0
def add_collection_items_to_sender_form(sender, initial):
    form = sender
    
    items_choices_from_app_settings = []
    for path in app_settings.APPS_FOR_COLLECTION_APP:
        model = get_model(path)
        queryset = model.query()
        if 'site' in model._meta.fields and form.request.session[CURRENT_SITE_FILTER] != '':
            site = Site.query().get(pk = form.request.session[CURRENT_SITE_FILTER])
            queryset = queryset.filter(site=site)
        for item in queryset:
            items_choices_from_app_settings.append((str(item['pk']), "%s: %s: %s" % (item._meta.app_label, item._meta.model_label, item.__unicode__() )))
    
    form.fields['items'] = london.forms.ChoiceField(name='items', widget=london.forms.SelectMultiple, choices=tuple(items_choices_from_app_settings),  required=False, help_text='app: model: item')
Exemplo n.º 9
0
def view(request, slug, template="post_view", site=None, queryset_function=None):
    if isinstance(site, basestring):
        site = Site.query().get(name=site)

    if not site:
        site = request.site

    if callable(queryset_function):
        posts = queryset_function(request)
    else:
        posts = site['posts']

    post = get_object_or_404(posts, slug=slug)
    return render_to_response(request, template, {'post': post, 
                            'categories': post.get_categories()})
Exemplo n.º 10
0
 def filter_images(self, request, *args, **kwargs):
     query = request.GET.get('q')
     if query:
         if self.search_fields is None:
             self.search_fields = ('keywords',)
         lookups = ["%s__icontains" % field for field in self.search_fields]
         bits = query.split()
         
         site = None
         if request.session[CURRENT_SITE_FILTER] != '':
             site = Site.query().get(pk = request.session[CURRENT_SITE_FILTER])
         
         queryset = Image.query()
         for bit in bits:
             if site and WIDGET_SITE_SPECIFIC_IMAGES:
                 queryset = queryset.filter(pk__in = [str(pk) for pk in site['images'].values_list('pk', flat=True)])
             queryset = queryset.filter_if_any(*[{lookup: bit} for lookup in lookups])
         return JsonResponse(queryset.values('name'))
     return JsonResponse()
Exemplo n.º 11
0
 def filter_objects(queryset):
     # filter by current selected site
     try:
         if 'site' in queryset.model._meta.fields and request.session[CURRENT_SITE_FILTER] != '':
             site = Site.query().get(pk = request.session[CURRENT_SITE_FILTER])
             queryset = queryset.filter(site=site)
     except:
         pass
     
     if request.GET:
         params = [(key, str(val)) for key, val in request.GET.items() if key not in ('q',) and not key.startswith('_')]
         queryset = queryset.filter(**dict(params))
     search_terms = request.GET.get('q', None)
     if self.search_fields is not None and search_terms:
         lookups = ["%s__icontains" % field for field in self.search_fields]
         search_filters = []
         bits = search_terms.split()
         for bit in bits:
             queryset = queryset.filter_if_any(*[{lookup: bit} for lookup in lookups])
     return queryset
Exemplo n.º 12
0
def view(request,
         slug,
         template="post_view",
         site=None,
         queryset_function=None):
    if isinstance(site, basestring):
        site = Site.query().get(name=site)

    if not site:
        site = request.site

    if callable(queryset_function):
        posts = queryset_function(request)
    else:
        posts = site['posts']

    post = get_object_or_404(posts, slug=slug)
    return render_to_response(request, template, {
        'post': post,
        'categories': post.get_categories()
    })
Exemplo n.º 13
0
 def get_initial(self, initial=None):
     initial = initial or super(PageForm, self).get_initial(initial)
     
     # Filter author users if user hasn't permissions to view them all
     if not self.request.user.has_perm('auth.edit_user', self.request.site):
         self.fields['author'].queryset = self.fields['author'].queryset(self).filter(pk = self.request.user['pk'])
     
     page_query = Page.query()
     if self.request.session[CURRENT_SITE_FILTER] != '':
         site = Site.query().get(pk = self.request.session[CURRENT_SITE_FILTER])
         page_query = page_query.filter(site=site)
     
     if self.instance['pk']:
         #exclude self page from the list of similar ones
         page_query = page_query.exclude(pk = self.instance['pk']).order_by('name')
     else:
         # setting initial author for new page
         initial['author'] = str(self.request.user['pk'])
     
     self.fields['parent_page'].queryset = page_query    
     signals.page_form_initialize.send(sender=self, initial=initial, publish_field_name='is_published')
     return initial
Exemplo n.º 14
0
from london.utils.safestring import mark_safe
from london.urls import reverse
from london.apps.collections.models import Collection

from datetime import datetime

try:
    from images.render import ImagesRender
    image_compiler = ImagesRender()
except:
    image_compiler = None

import markdown2

try:
    SITES = [(slugify(site['name']), site['name']) for site in Site.query()]
except:
    SITES = []


class Category(models.Model):
    class Meta:
        ordering = ('name', )

    name = models.CharField(max_length=50)


class PostQuerySet(models.QuerySet):
    def published(self):
        return self.filter(is_draft=False)
Exemplo n.º 15
0
def add_image_field_to_sender_form(sender):
    form = sender
    site = None
    if form.request.session[CURRENT_SITE_FILTER] != '':
        site = Site.query().get(pk = form.request.session[CURRENT_SITE_FILTER])
    form.fields['images'] = london.forms.Field(name='images', widget=ImagesWidget({'site':site}), required=False)
Exemplo n.º 16
0
 def all_sites(self):
     return Site.query()  
Exemplo n.º 17
0
 def all_sites(self):
     return Site.query()
Exemplo n.º 18
0
from london.urls import reverse
from london.apps.collections.models import Collection

from datetime import datetime

try:
    from images.render import ImagesRender

    image_compiler = ImagesRender()
except:
    image_compiler = None

import markdown2

try:
    SITES = [(slugify(site["name"]), site["name"]) for site in Site.query()]
except:
    SITES = []


class Category(models.Model):
    class Meta:
        ordering = ("name",)

    name = models.CharField(max_length=50)


class PostQuerySet(models.QuerySet):
    def published(self):
        return self.filter(is_draft=False)
Exemplo n.º 19
0
def basic(request):
    return {
        'writer': is_writer(request.user),
        'sites': Site.query().filter(is_active=True)
    }
Exemplo n.º 20
0
def basic(request):
    return {"writer": is_writer(request.user), "sites": Site.query().filter(is_active=True)}
Exemplo n.º 21
0
 def get_sites(self):
     return [{'pk':unicode(site['pk']), 'name':site['name']} for site in Site.query()]