def theme_preview(request, name=None): if name: resp = HttpResponseRedirect('/') resp.set_cookie(app_settings.CURRENT_THEME_COOKIE, name) request.info(_('Theme "%s" set to preview.')%name) else: resp = HttpResponseRedirect(reverse('themes_home')) resp.delete_cookie(app_settings.CURRENT_THEME_COOKIE) request.info(_('Disabled the theme preview.')) return resp
def clean(self): data = super(ResetPasswordConfirmForm, self).clean() # Validates and loads the user for username or e-mail given queryset = self.queryset or self.user_class.query() email_user = self.get_user_function(self.request, queryset, data) if not email_user or email_user != self.user: raise forms.ValidationError(_("Invalid e-mail for this token.")) if data["new_password"] != data["confirm_password"]: raise forms.ValidationError(_("Invalid password confirmation.")) return data
def import_theme(zipfp, theme=None): """ If a theme is informed, it assumes and theme imported fields are ignored """ # Initializes the working area dir_name = ''.join([random.choice('abcdefghijklmnopqrstuvwxyz') for n in range(20)]) work_dir = os.path.join('/tmp/', dir_name) os.makedirs(work_dir) os.chdir(work_dir) # Opens and extracts the zip file zipf = zipfile.ZipFile(zipfp) zipf.extractall() # Loads driver JSON file json_fp = file('details.json') json = simplejson.loads(json_fp.read()) json_fp.close() # Doesn't allow import existing theme (must delete before) if not theme and Theme.query().filter(name=json['name']).count(): raise ValueError(_('Theme "%s" already exists.')%json['name']) # Creates the new theme if not theme: theme = Theme.query().create(name=json['name'], verbose_name=json['verbose_name']) # Creates the new templates for json_tpl in json['templates']: tpl, new = theme['templates'].get_or_create(name=json_tpl['name']) tpl['content'] = json_tpl['content'] tpl['notes'] = json_tpl['notes'] tpl['engine'] = json_tpl['engine'] tpl.save() # Creates the new static files db_field = ThemeStaticFile._meta.fields['file'] for json_sf in json['static_files']: sf, new = theme['static_files'].get_or_create( name=json_sf['name'], defaults={ 'url': json_sf['url'], 'mime_type': json_sf['mime_type'], }, ) if json_sf['file']: fp = file(json_sf['file']) content = ContentFile(fp.read()) fp.close() upload_name = db_field.generate_filename(sf, json_sf['file']) upload_name = db_field.storage.save(upload_name, content) sf['file'] = FieldFile(sf, db_field, upload_name) sf.save() return theme
def _wrapper(request, name=None, theme=None, **kwargs): if not theme: if name is not None: theme = get_object_or_404(Theme, name=name) elif getattr(request, 'site', None) and request.site['theme']: theme = request.site['theme'] else: request.error(_('No theme to edit.')) return HttpResponseRedirect(request.META.get('HTTP_REFERER','/')) return func(request, theme=theme, **kwargs)
def theme_delete(request, theme): # Templates first theme['templates'].delete() # Delete static files and their phisical files for sf in theme['static_files']: sf['file'].delete() sf.delete() name = theme['name'] # Finally, deletes the theme theme.delete() request.info(_('Theme "%s" deleted.')%unicode(name)) return HttpResponseRedirect(reverse('themes_home'))
def theme_upload(request, theme): if request.method == 'POST': up_file = request.FILES.getlist('dragupload[]')[0] try: import_theme(up_file, theme=theme) # Calls the signal after static files changed theme_static_files_changed.send(sender=request.site, theme=theme, request=request, items=list(theme['static_files'].exclude(file=None))) request.info(_('File imported with success!')) except ValueError as e: request.info(e) return {'theme':theme, 'uploaded':True} else: return {'theme':theme}
def theme_import(request): if request.method == 'POST': try: # Calls the theme importing function to save theme, templates and static files in the right places theme = import_theme(request.FILES['file']) # Calls the signal after static files changed theme_static_files_changed.send(sender=request.site, theme=theme, request=request, items=list(theme['static_files'].exclude(file=None))) # Final message and redirecting request.info(_('File imported with success!')) url_redirect = reverse('themes_theme', kwargs={'name': theme['name']}) except ValueError as e: request.info(e) url_redirect = reverse('themes_home') return HttpResponseRedirect(url_redirect)
def get_text_list(list_, last_word=ugettext_lazy(unicode('or'))): """ >>> get_text_list(['a', 'b', 'c', 'd']) u'a, b, c or d' >>> get_text_list(['a', 'b', 'c'], 'and') u'a, b and c' >>> get_text_list(['a', 'b'], 'and') u'a and b' >>> get_text_list(['a']) u'a' >>> get_text_list([]) u'' """ if len(list_) == 0: return unicode('') if len(list_) == 1: return force_unicode(list_[0]) return unicode('%s %s %s') % ( # Translators: This string is used as a separator between list elements _(', ').join([force_unicode(i) for i in list_][:-1]), force_unicode(last_word), force_unicode(list_[-1]))
def home(request): themes = Theme.query().order_by('verbose_name') previewing = request.COOKIES.get(app_settings.CURRENT_THEME_COOKIE, None) if request.POST.get('name', None): verbose_name = request.POST['name'] name = slugify(request.POST['name']) counter = 0 while Theme.query().filter(name=name).count(): counter += 1 name = '%s-%s'%(slugify(request.POST['name']), counter) theme = Theme.query().create(name=name, verbose_name=verbose_name) request.warning(_('New theme "%s" created.')) return HttpResponseRedirect(reverse('themes_theme', kwargs={'name': theme['name']})) return render_to_response(request, 'themes/home.html', {'themes':themes, 'previewing':previewing}, )
def inactive_site(request): raise Http404(_('Site is inactive. Sorry for this inconvenience and come back soon.'))
""" Copied from Django 1.4 Copyright (c) Django Software Foundation and individual contributors. All rights reserved. Commonly-used date structures """ from london.utils.translation import ugettext_lazy as _, pgettext_lazy WEEKDAYS = { 0:_('Monday'), 1:_('Tuesday'), 2:_('Wednesday'), 3:_('Thursday'), 4:_('Friday'), 5:_('Saturday'), 6:_('Sunday') } WEEKDAYS_ABBR = { 0:_('Mon'), 1:_('Tue'), 2:_('Wed'), 3:_('Thu'), 4:_('Fri'), 5:_('Sat'), 6:_('Sun') } WEEKDAYS_REV = { 'monday':0, 'tuesday':1, 'wednesday':2, 'thursday':3, 'friday':4, 'saturday':5, 'sunday':6 } MONTHS = { 1:_('January'), 2:_('February'), 3:_('March'), 4:_('April'), 5:_('May'), 6:_('June'), 7:_('July'), 8:_('August'), 9:_('September'), 10:_('October'), 11:_('November'), 12:_('December') } MONTHS_3 = { 1:_('jan'), 2:_('feb'), 3:_('mar'), 4:_('apr'), 5:_('may'), 6:_('jun'), 7:_('jul'), 8:_('aug'), 9:_('sep'), 10:_('oct'), 11:_('nov'), 12:_('dec') } MONTHS_3_REV = {
def theme_set_default(request, theme): theme['is_default'] = True theme.save() request.info(_('Theme "%s" set as default.')%theme['name']) return HttpResponseRedirect(reverse('themes_theme', kwargs={'name':theme['name']}))