def is_homepage(self): SiteskinModel = get_custom_model_class(ss_defaults.SITESKIN_SETTINGS_MODEL) siteskin = SiteskinModel.objects.filter(site=Site.objects.get_current()).filter(home_page__id = self.id) if siteskin: return True else: return False
def is_homepage(self): SiteskinModel = get_custom_model_class( ss_defaults.SITESKIN_SETTINGS_MODEL) siteskin = SiteskinModel.objects.filter( site=Site.objects.get_current()).filter(home_page__id=self.id) if siteskin: return True else: return False
def handle(self, *args, **options): from spicy.utils.models import get_custom_model_class from spicy.feedback import defaults Feedback = get_custom_model_class(defaults.CUSTOM_FEEDBACK_MODEL) from spicy.utils.printing import print_error, print_info, print_warning now = datetime.datetime.utcnow().replace(tzinfo=utc) feedback_timeout = Feedback.objects.filter( pattern__isnull=False, email_has_been_sent=False, ).distinct('email').order_by('email', '-submit_date').values_list( 'id', 'pattern__auto_response_timeout') feedbacks = [] for id, timeout in feedback_timeout: feedbacks.append( Feedback.objects.filter(pk=id, submit_date__lte=now - timedelta(minutes=timeout))) if not feedbacks: print_info('Has no new auto feedbacks') else: totalCount = len(feedbacks) sentCount = 0 print_info('Sending\r\n') for feedback in feedbacks[:defaults.MESSAGES_PER_MINUTE]: try: print_info('%s\r\n' % feedback.email) feedback.send_using_pattern() sentCount += 1 except Exception as e: print_error('Error sending to %s: "%s"\r\n' % (feedback.email, str(e))) print_info('Total to send: %i\r\nSuccessfully sent: %i\r\n' % (totalCount, sentCount))
import os import tempfile from django.contrib.auth import views from spicy.core.profile.decorators import is_staff from spicy.core.service import api from spicy.core.siteskin.decorators import render_to, ajax_request from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext_lazy as _ from django.http import HttpResponse from spicy.mediacenter import defaults as mc_defaults from django.core.files.base import ContentFile from spicy.utils.models import get_custom_model_class from . import defaults from redmine import Redmine SettingsModel = get_custom_model_class(defaults.ADMIN_SETTINGS_MODEL) Library = get_custom_model_class(mc_defaults.CUSTOM_LIBRARY_MODEL) Media = get_custom_model_class(mc_defaults.CUSTOM_MEDIA_MODEL) File = get_custom_model_class(mc_defaults.CUSTOM_FILE_MODEL) def login(request): return views.login(request, template_name='spicy.core.admin/admin/login.html', extra_context={'redirect': request.GET.get('next')}) def logout(request): return views.logout(request, template_name='spicy.core.admin/admin/logout.html')
from spicy.utils.models import get_custom_model_class from . import defaults Profile = get_custom_model_class(defaults.CUSTOM_USER_MODEL)
import json from captcha.fields import CaptchaField from captcha.helpers import captcha_image_url from captcha.models import CaptchaStore from django import forms from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ from django.views.generic.edit import CreateView from spicy.utils.models import get_custom_model_class from . import defaults, models Feedback = get_custom_model_class(defaults.CUSTOM_FEEDBACK_MODEL) class FeedbackForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(FeedbackForm, self).__init__(*args, **kwargs) if self.instance.pattern.use_captcha: self.fields['captcha'] = CaptchaField(label=_('Captcha')) class Meta: model = Feedback fields = ('name', 'email', 'phone', 'message', 'url', 'company_name', 'var1', 'var2', 'var3') class AjaxExampleForm(CreateView): template_name = '' form_class = FeedbackForm def form_invalid(self, form):
# -*- coding: utf-8 -*- from . import defaults from django import forms from django.contrib.sites.models import Site from django.forms.models import inlineformset_factory from django.utils.translation import ugettext_lazy as _ from spicy.core.service import forms as service_forms from spicy.core.siteskin.fields import SanitizingCharField from spicy.core.siteskin.widgets import AutoCompleteChooser from spicy.utils.models import get_custom_model_class from ckeditor.widgets import CKEditorWidget Document = get_custom_model_class(defaults.CUSTOM_DOCUMENT_MODEL) DocumentProviderModel = get_custom_model_class( defaults.CUSTOM_DOCUMENT_PROVIDER_MODEL) DocumentProviderRelatedDoc = get_custom_model_class( defaults.CUSTOM_DOCUMENT_PROVIDER_RELATED_DOC_MODEL) class DocumentForm(forms.ModelForm): #title = forms.CharField(label=_('Title'), max_length=255, required=True) #body = SanitizingCharField(label=_('Document body')) class Meta: model = Document fields = ('title', 'pub_date', 'body', 'draft', 'is_public', 'enable_comments', 'is_sitemap', 'registration_required', 'preview', 'preview2') widgets = { 'body': CKEditorWidget(), #forms.Textarea(attrs=dict(rows=20)), 'pub_date': forms.DateTimeInput(format='%Y-%m-%d %H:%i')
def get_admin_settings(): # TODO make cache wrapper SettingsModel = get_custom_model_class(defaults.ADMIN_SETTINGS_MODEL) instance, _ = SettingsModel.objects.get_or_create(site_id=settings.SITE_ID) return instance
import os from django.conf import settings from django.core.cache import cache from django.http import Http404 from django.shortcuts import render_to_response from django.template import RequestContext from spicy.core.service import api from spicy.core.siteskin import defaults as sk_defaults from spicy.utils import make_cache_key from spicy.utils.models import get_custom_model_class from spicy.core.siteskin.decorators import render_to from . import defaults DocumentModel = get_custom_model_class(defaults.CUSTOM_DOCUMENT_MODEL) def doc_list_rss(request): return dict() @render_to('spicy.document/document.html', use_siteskin=True) def document(request, doc_id): doc = None try: doc = DocumentModel.objects.get(pk=doc_id) except DocumentModel.DoesNotExist: raise Http404
from django import forms from spicy.utils.models import get_custom_model_class from django.utils.encoding import smart_unicode from django.utils.safestring import SafeUnicode from django.utils.translation import ugettext_lazy as _ from . import defaults, utils SiteskinModel = get_custom_model_class(defaults.SITESKIN_SETTINGS_MODEL) class ValueAndHiddenInput(forms.HiddenInput): def render(self, name, value, attrs=None): original = super(ValueAndHiddenInput, self).render(name, value, attrs) if value is not None: return SafeUnicode(original + smart_unicode(value)) else: return original class ThemeForm(forms.ModelForm): theme = forms.CharField( label=_('Theme'), widget=forms.Select( attrs={'class': 'uniform'}, choices=utils.get_siteskin_themes()), required=True) class Meta: model = SiteskinModel exclude = ('site', )
from django import forms from spicy.utils.models import get_custom_model_class from django.utils.encoding import smart_unicode from django.utils.safestring import SafeUnicode from django.utils.translation import ugettext_lazy as _ from . import defaults, utils SiteskinModel = get_custom_model_class(defaults.SITESKIN_SETTINGS_MODEL) class ValueAndHiddenInput(forms.HiddenInput): def render(self, name, value, attrs=None): original = super(ValueAndHiddenInput, self).render(name, value, attrs) if value is not None: return SafeUnicode(original + smart_unicode(value)) else: return original class ThemeForm(forms.ModelForm): theme = forms.CharField(label=_('Theme'), widget=forms.Select( attrs={'class': 'uniform'}, choices=utils.get_siteskin_themes()), required=True) class Meta: model = SiteskinModel exclude = ('site', )
from django.contrib.sites.models import Site from django.utils.translation import ugettext as _ from spicy.core.profile.decorators import is_staff from spicy.core.service import api from spicy.core.siteskin.decorators import render_to from spicy.utils.models import get_custom_model_class from . import conf, defaults, forms, utils SettingsModel = get_custom_model_class(defaults.ADMIN_SETTINGS_MODEL) class AdminApp(conf.AdminAppBase): name = 'spicyadmin' label = _('Admin') order_number = 10 menu_items = ( conf.AdminLink( 'spicyadmin:admin:settings', _('Metrics, meta & Extra JS'), icon_class='icon-cogs', perms='admin.change_settings'), conf.AdminLink( 'spicyadmin:admin:robots', _('Setup robots.txt'), icon_class='icon-asterisk', perms='admin.change_settings'), conf.AdminLink( 'spicyadmin:admin:sitemap', _('Sitemap.xml'), icon_class='icon-sitemap', perms='admin.change_settings'), conf.AdminLink( 'spicyadmin:admin:managers', _('Manager\'s emails'), icon_class='icon-envelope', perms='admin.change_manager_settings'),
from django import forms from django.contrib.sites.models import Site from spicy.utils.models import get_custom_model_class from . import defaults SettingsModel = get_custom_model_class(defaults.ADMIN_SETTINGS_MODEL) class SettingsForm(forms.ModelForm): class Meta: model = SettingsModel fields = 'admins_emails', 'managers_emails' class MetricsForm(forms.ModelForm): class Meta: model = SettingsModel fields = 'ga_key', class DeveloperForm(forms.ModelForm): class Meta: model = SettingsModel fields = ( 'sentry_key', 'redmine_key', 'redmine_tracker_url', 'redmine_username', 'redmine_password', 'redmine_project', 'enable_debug_toolbar', 'debug_mode') class ApplicationForm(forms.ModelForm): class Meta:
from datetime import datetime as dt from django.template import RequestContext from spicy.core.simplepages.views import render_simplepage from spicy.utils.printing import print_error from . import defaults from spicy.core.simplepages import defaults as sp_defaults from spicy.utils.models import get_custom_model_class from django.contrib.sites.models import Site from django.shortcuts import get_object_or_404 from django import http SimplePage = get_custom_model_class(sp_defaults.SIMPLE_PAGE_MODEL) SiteskinModel = get_custom_model_class(defaults.SITESKIN_SETTINGS_MODEL) def page_not_found(request): """ Default 404 handler. """ if defaults.DEBUG_ERROR_PAGES: print_error( 'handler404: %s %s %s %s\n' % (dt.now(), request.GET, request.POST, request.get_full_path())) response = render_simplepage(request, '/errors/404/') response.status_code = 404 return response def forbidden(request): """
import os import tempfile from django.contrib.auth import views from spicy.core.profile.decorators import is_staff from spicy.core.service import api from spicy.core.siteskin.decorators import render_to, ajax_request from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext_lazy as _ from django.http import HttpResponse from spicy.mediacenter import defaults as mc_defaults from django.core.files.base import ContentFile from spicy.utils.models import get_custom_model_class from . import defaults from redmine import Redmine SettingsModel = get_custom_model_class(defaults.ADMIN_SETTINGS_MODEL) Library = get_custom_model_class(mc_defaults.CUSTOM_LIBRARY_MODEL) Media = get_custom_model_class(mc_defaults.CUSTOM_MEDIA_MODEL) File = get_custom_model_class(mc_defaults.CUSTOM_FILE_MODEL) def login(request): return views.login( request, template_name='spicy.core.admin/admin/login.html', extra_context={'redirect': request.GET.get('next')}) def logout(request): return views.logout(request, template_name='spicy.core.admin/admin/logout.html')
from django.contrib.auth.management.commands.changepassword import Command from django.core.management.base import CommandError from spicy.utils.models import get_custom_model_class from spicy.core.profile import defaults Profile = get_custom_model_class(defaults.CUSTOM_USER_MODEL) import getpass class Command(Command): def handle(self, *args, **options): if len(args) > 1: raise CommandError("need exactly one or zero arguments for email") if args: email, = args else: email = getpass.getuser() try: profile = Profile.objects.get(email=email) except Profile.DoesNotExist: raise CommandError("profile '%s' does not exist" % email) print "Changing password for profile '%s'" % profile.email MAX_TRIES = 3 count = 0 p1, p2 = 1, 2 # To make them initially mismatch.
from datetime import datetime as dt from django.template import RequestContext from spicy.core.simplepages.views import render_simplepage from spicy.utils.printing import print_error from . import defaults from spicy.core.simplepages import defaults as sp_defaults from spicy.utils.models import get_custom_model_class from django.contrib.sites.models import Site from django.shortcuts import get_object_or_404 from django import http SimplePage = get_custom_model_class(sp_defaults.SIMPLE_PAGE_MODEL) SiteskinModel = get_custom_model_class(defaults.SITESKIN_SETTINGS_MODEL) def page_not_found(request): """ Default 404 handler. """ if defaults.DEBUG_ERROR_PAGES: print_error('handler404: %s %s %s %s\n' % ( dt.now(), request.GET, request.POST, request.get_full_path())) response = render_simplepage(request, '/errors/404/') response.status_code = 404 return response def forbidden(request): """ Default 403 handler.