def process_request(self, request): if not ConfigData.get_configdata('site_installed', default=False): theming.check_themes() if not request.path.startswith('/install') and not request.path.startswith('/loader'): return http.HttpResponseRedirect(reverse('install')) if not request.path.startswith('/install') and not request.path.startswith('/loader'): for app in settings.INSTALLED_APPS: if not ConfigData.is_installed(app): try: Action.register_action(app) except exceptions.ImproperlyConfigured: pass #logging.error(" can not register %s actions" % app) if not ConfigData.is_installed(app): try: _install = util.get_attr_from("%s.config.install" % app) _install() except exceptions.ImproperlyConfigured: pass #logging.error("ImproperlyConfigured -> %s.config.install" % app) areas = util.get_config_value(app, "areas", {}) areas_vals = sorted(areas.values(), key=lambda x: x.get("order", 1000)) ConfigData.set_configdata(app, True, label='installed_app', extra={'adminareas':areas_vals})
def __init__(self, *args, **kwargs): logging.info(">> AdminSiteForm") super(AdminSiteForm, self).__init__(*args, **kwargs) self.fields['site_name'].initial = ConfigData.get_configdata('SITE_NAME') self.fields['meta_description'].initial = ConfigData.get_configdata('SITE_DESCRIPTION') self.fields['meta_keywords'].initial = ConfigData.get_configdata('SITE_KEYWORDS') self.fields['theme'].widget = forms.Select(choices=Theme.get_choices()) self.fields['theme'].initial = Theme.get_active().uuid
def get_global_vars(): params = getattr(settings, 'GLOBALS') params.update({'SITE_NAME':ConfigData.get_configdata('SITE_NAME'), 'SITE_DESCRIPTION':ConfigData.get_configdata('SITE_DESCRIPTION'), 'SITE_KEYWORDS':ConfigData.get_configdata('SITE_KEYWORDS'), 'MEDIA_URL':settings.MEDIA_URL, 'DOMAIN':settings.DOMAIN, 'THEME_MEDIA_URL':settings.THEME_URL + Theme.get_active().directory_name + '/'}) return params
def save(self): super(InstallForm, self).save() params = {"username":self.cleaned_data["username"].lower(), "first_name":self.cleaned_data["first_name"], "last_name":self.cleaned_data["last_name"], "email":self.cleaned_data["email"], "active":True, "superuser":True, "roles":['authenticated', 'administrator']} user = User(**params) user.code = util.generate_uuid() user.set_password(self.cleaned_data["password1"]) user.save() ConfigData.set_configdata('ADMIN_USERNAME', user.username) return user
def mail_welcome(user): params = {'user':user} message = mail.get_mail_message('mail_welcome.txt', **params) html_message = mail.get_mail_message('mail_welcome.html', **params) subject = "Welcome to %s" % ConfigData.get_configdata('SITE_NAME') mail.send_mail(user.email, subject, message, html_message=html_message)
def render(cls, context, name=""): adminareas = [] for app in settings.INSTALLED_APPS: _config = ConfigData.get(name=app, label="installed_app") if _config: adminareas += _config.extra.get("adminareas", []) context.update({"adminareas": adminareas}) return cls.render_block(template_name="block_adminmenu.html", block_title=_(name), context=context)
def mail_confirm(user, mail): _link = "http://%s%s" % (settings.DOMAIN, reverse("users_validate_email", args=[code])) params = {'user':user, "link": _link} message = mail.get_mail_message('mail_validate_email.txt', **params) html_message = mail.get_mail_message('mail_validate_email.html', **params) subject = "Confirm your %s account" % ConfigData.get_configdata('SITE_NAME') mail.send_mail(user.email, subject, message, html_message=html_message)
def dashboard(request): for app in settings.INSTALLED_APPS: adminareas = [] _config = ConfigData.get(name=app, label='installed_app') if _config: adminareas += _config.extra.get('adminareas') c = template.RequestContext(request, locals()) _flag_as_admin(c) return render_to_response("dashboard.html", c)
def install(request): area = 'install' if ConfigData.get_configdata('site_installed', default=False): util.error(request, "Site is already installed") return http.HttpResponseRedirect(reverse('front')) form = InstallForm() if request.method == 'POST': form = InstallForm(request.POST) if form.is_valid(): user = form.save() ConfigData.set_configdata('site_installed', True) auth_login(request, user) util.success(request, "Site has been installed successfully") return http.HttpResponseRedirect(reverse('admin_dashboard')) c = template.RequestContext(request, locals()) _flag_as_admin(c) return render_to_response('install.html', c)
def register(request): form = RegisterForm() if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): user = form.save() mail_welcome(user) authenticate(request, user) util.add_success(request, "Welcome to %s" % ConfigData.get_configdata('SITE_NAME')) return redirect(reverse('admin_dashboard')) c = template.RequestContext(request, locals()) return render_to_response('users_register.html', c)
def new(request): content_dir = {} for app in settings.INSTALLED_APPS: _config = ConfigData.get(name=app, label='installed_app') if _config: _config = "%s.config.get_content" % app get_content = util.get_attr_from_safe(_config) if get_content is not None: content_dir.update({app:get_content()}) handler = NewHandler(request, area='menus', model=MenuItem, model_form=MenuItemForm, tpl='menuitems_new.html', redirect_to=MenuItem.admin_url(), extra_context={"content_dir":content_dir}) return handler.handle()
def save(self): ConfigData.set_configdata('SITE_NAME', self.cleaned_data['site_name']) ConfigData.set_configdata('SITE_DESCRIPTION', self.cleaned_data['meta_description']) ConfigData.set_configdata('SITE_KEYWORDS', self.cleaned_data['meta_keywords']) Theme.check_for_duplicated_active_themes(self.cleaned_data['theme']) return True