Esempio n. 1
0
def install_theme():
    """
    Copy theme in a new twistranet instance.
    Change settings of this instance
    """

    # Copy theme-defined static files into the static directory.
    # We start by importing the theme app
    theme_app = import_module(settings.TWISTRANET_THEME_APP)
    theme_app_dir = os.path.split(theme_app.__file__)[0]
    dest_root = os.path.abspath(os.path.join(settings.HERE, 'www', 'static'))
    source_root = os.path.abspath(os.path.join(theme_app_dir, 'static'))
    if not os.path.isdir(dest_root):
        os.makedirs(dest_root)
    for root, dirs, files in os.walk(source_root):
        relative_root = root[len(source_root) + 1:]
        for d in dirs:
            dest_dir = os.path.join(dest_root, relative_root, d)
            if not os.path.isdir(dest_dir):
                os.mkdir(dest_dir)
        for fname in files:
            dest_file = os.path.join(dest_root, relative_root, fname)
            shutil.copy(
                os.path.join(source_root, root, fname),
                dest_file,
            )
    
    log.info("The twistranet theme has been installed in your project.")
Esempio n. 2
0
def install_theme():
    """
    Copy theme in a new twistranet instance.
    Change settings of this instance
    """

    # Copy theme-defined static files into the static directory.
    # We start by importing the theme app
    theme_app = import_module(settings.TWISTRANET_THEME_APP)
    theme_app_dir = os.path.split(theme_app.__file__)[0]
    dest_root = os.path.abspath(os.path.join(settings.HERE, 'www', 'static'))
    source_root = os.path.abspath(os.path.join(theme_app_dir, 'static'))
    if not os.path.isdir(dest_root):
        os.makedirs(dest_root)
    for root, dirs, files in os.walk(source_root):
        relative_root = root[len(source_root) + 1:]
        for d in dirs:
            dest_dir = os.path.join(dest_root, relative_root, d)
            if not os.path.isdir(dest_dir):
                os.mkdir(dest_dir)
        for fname in files:
            dest_file = os.path.join(dest_root, relative_root, fname)
            shutil.copy(
                os.path.join(source_root, root, fname),
                dest_file,
            )

    log.info("The twistranet theme has been installed in your project.")
Esempio n. 3
0
def create_profile(sender, instance, created, *args, **kw):
    """
    Create an empty profile for a new user.
    XXX TODO: Handle particular LDAP attributes? 
    See http://packages.python.org/django-auth-ldap/#user-objects for more info
    """
    if created:
        # Here we check if AdminCommunity exists.
        # If it doesn't, that probably means we're inside the bootstrap process,
        # and in such case we don't want to create a profile now.
        import community
        if not community.AdminCommunity.objects.__booster__.exists():
            log.debug("Admin community doesn't exist (yet)")
            return
            
        # We consider we're the SystemAccount now.
        __account__ = SystemAccount.get()
        
        # Actually create profile
        log.info("Automatic creation of a UserAccount for %s" % instance)
        profile = UserAccount(
            user = instance,
            slug = slugify.slugify(instance.username),
        )
        profile.save()
Esempio n. 4
0
def create_profile(sender, instance, created, *args, **kw):
    """
    Create an empty profile for a new user.
    XXX TODO: Handle particular LDAP attributes? 
    See http://packages.python.org/django-auth-ldap/#user-objects for more info
    """
    if created:
        # Here we check if AdminCommunity exists.
        # If it doesn't, that probably means we're inside the bootstrap process,
        # and in such case we don't want to create a profile now.
        import community
        if not community.AdminCommunity.objects.__booster__.exists():
            log.debug("Admin community doesn't exist (yet)")
            return

        # We consider we're the SystemAccount now.
        __account__ = SystemAccount.get()

        # Actually create profile
        log.info("Automatic creation of a UserAccount for %s" % instance)
        profile = UserAccount(
            user=instance,
            slug=slugify.slugify(instance.username),
        )
        profile.save()
Esempio n. 5
0
    def prepare_view(self):
        """
        Render the import form
        or do the import (from csv file posted).
        """

        if self.request.method == "POST" and \
           self.request.FILES.get("csv_file", None):
            csv_file = self.request.FILES.get("csv_file")
            reader = csv.reader(csv_file, dialect=CSVDialect)
            for line in reader:
                if not line:
                    continue
                # firstname;lastname;email
                firstname = line[0].decode('utf8')
                lastname = line[1].decode('utf8')
                email = line[2]
                username = email.split('@')[0]
                username = slugify(username).replace('_','-')
                if User.objects.filter(username = username).exists():
                    u = User.objects.get(username = username)
                    useraccount = UserAccount.objects.get(user = u)
                    log.info( "User account '%s' already exixts" %useraccount.title )
                else:
                    # create user
                    try:
                        __account__ = SystemAccount.get()
                        u = User.objects.create(
                            username = username,
                            first_name = firstname,
                            last_name = lastname,
                            email = email,
                            is_superuser = False,
                            is_active = True,
                        )
                        chars = string.ascii_letters + string.digits
                        random.seed = (os.urandom(1024))
                        password = ''.join(random.choice(chars) for i in range(6))
                        u.set_password(password)
                        u.save()
                        useraccount = UserAccount.objects.get(user = u)
                        useraccount.title = u"%s %s" % (firstname, lastname)
                        useraccount.save()
                        log.info( "User account '%s' for %s %s (%s) created !" %(username, firstname, lastname,  email))

                        # notify imported user (a mail is sent to prevent user)
                        h = "%s%s%s%s" % (settings.SECRET_KEY, email, password, time.strftime("%Y%m%d"))
                        h = hashlib.md5(h).hexdigest()
                        reset_link = reverse(ResetPassword.name, args = (h, urllib.quote_plus(email)))

                        user_imported.send(
                            sender = self.__class__,
                            target = useraccount,
                            reset_password_url = reset_link,
                        )
                        del __account__
                    except:
                        log.warning( "Impossible to create account '%s' for %s %s (%s)" %(username, firstname, lastname,  email))
                        continue

                community_title = line[3].decode('utf8')
                cid = slugify(community_title)
                if  Community.objects.filter(slug = cid).exists():
                    log.info( "Community %s already exists !" %community )
                else:
                    c  = Community.objects.create(
                        slug = cid,
                        title = community_title,
                        permissions = "workgroup"
                    )
                    c.save()

                com = Community.objects.get(slug= cid)
                com.join(account=useraccount)
                log.info( "user %s join the community %s !" %(useraccount.title, community_title) )

            messages.info( self.request, u"import finished",)