How to get MS Word templates directory for another user? - templates

I'm using the following code to get the path where Word stores its templates:
WordTemplatePath:=WordApp.Options.DefaultFilePath[$00000002];
The problem is that this returns the path for the actual, logged-in user.
Is there a way to get the path for another user of the same Windows instance?
I need it so my installer program can install the templates used by my program for other users as well.

That approach isn't going to work too well. Typically, users won't have access to other user's profile folders and the "templates" folder for each user is located in they're profile.
Generally, if you need a template installed for all users, it's best to put it in the word STARTUP folder, or possibly in the "WorkGroup Templates" folder.
Alternately, you could require admin rights for the install and then scan, but even then, its possible (though unlikely) that users could have changed the path to their templates folder and so you can hardwire it, you'd have to scan Word's registry settings for each user to do that job right. Not a pretty thing to contemplate.
Are you just updating you're own templates? or are you wanting to scan and modify all the templates that a user has created for themselves? If the latter, you might instead move that logic into your addin and make it a function that is called each time the user loads up (or maybe give them a button to press to force the scan).

Related

Creating a custom Source for Sitecore Template

I am very new to Sitecore, and have to customize a Template for a MultiLine Entry to have different source (List of Items) depending on the Role of the Logged-In Admin. For example the site can have multiple different Admins and each one can add/remove data for a of the page section, so
The content for MultiList of Website-1 (Edited by Admin-1) will be different from Website-2(Edited by Admin-2). So the data for Admin-1 and Admin-2 is at the following locations:
Admin-1: sitecore/content/Data/Features/Admin-1
Admin-2: sitecore/content/Data/Features/Admin-2
Now for the Source part of the Template, I can enter the path for the data: ex-/sitecore/content/Data/Features/ and that will include all of the Items in that folder including both subfolders of "Admin-1" and "Admin-2", but what I really want is when the Admin-1 logs I want the list to be populated only with "Admin-1" content, and vice versa. Is that even possible? I am not sure what to do about that.
Ok, your question was a little ambiguous hence the reason I asked the question.
your data structure is currently a little incorrect in my opinion. I would set it up as follows:
-sitecore
--content
---common (shared between both sites)
---site-1
----home
----settings
----data
---site-2
----home
----settings
----data
Now in your template set the datasource as:
query:./ancestor-or-self::*[##templatename='Site']/data/features/*
This will restrict the options for your multilist to only items in the data folder of the current site. Obviously change ##templatename to whatever yours is.
As for the permissions, you should create 2 roles, Admin-1 and Admin-2. For both roles break the inheritance on /sitecore/content node and then give Admin-1 read/write/create/delete access on /sitecore/content/site-1 and Admin-2 the same on Site-2. Make sure you do this for roles. Then add the necessary users to those roles. If a specific user needs access to both sites then add them to both roles. Use /Security Tools/Security Editor.
I would not call the roles "admin" since that can lead to confusion between the Sitecore Admin setting. Instead, I would call it "Site1ContentEditer" and "Site2ContentEditer". If you introduce workflow this gives you the opportunity to follow the naming convention, e.g. Site1ContentApprover, Site1ContentPublisher etc.
I'm a little rushed right now, but let me know if you need more info.
EDIT: This should give you more info on multisite implementation: Building multisite solutions in Sitecore

Django -- hide links from certain users

Is it possible, on a Django webapp, to hide certain links from those users who do not have the permission to click the link?
I bet there is a per-link way to check if the user has persmission to click the link, and then show the link (or not) based on that test. However, when there are a lot links spread across a whole bunch of web pages, that can be ridiculously tedious. Are there any ways to achieve this across the whole website with a setting or something?
write a template tag similar to spaceless that goes over its contents and removes all links that are not accessible. this would save you from having to touch each link manually.
It might be possible to write a custom template tag that would accept a link url, reverse it, introspect what permissions were required for the target view, and then conditionally display it.
You'd still have to touch every link in every template that you wanted to make fancy like that, and it would probably be an ugly beast. All in all, it's probably easier if you come up with a more centralized way to control access.

django view/template redirection for mobile browsers

Not sure if anyone has had experience with a good solution to rendering templates specifically for mobile devices using django.
I wrote a middleware request processor that uses regex to detect whether it is a mobile browser or not. I am currently setting a boolean attribute on the request so that I can use it further down the pipe. But really my business logic is the same I just want to use a different set of templates.
Is there a way for me to add a new template directory to settings.TEMPLATE_DIRS in the middleware processor, so that a mobile user would get the views I choose to rewrite, but everything else would fall back to the default template directories. But I need to make sure it doesn't persist between requests.
If i added a directory, would settings continue to hold onto it between requests?
..and if so, is this the right solution (checking the browser agent, adding an additional template folder, and then removing it at the end of each request)?
Dynamically modifying the template search path is a great way to handle this. It's not hard to define your own template loader and add it to the TEMPLATE_LOADERS in settings.py. The tricky part of this is handling the fact you may be running in a multi-threaded environment, and you don't have a way to pass your request directly to the template loader.
The way around it is to store the request, a flag, or simply the directories to add to the path in a thread local variable, and reference that thread local variable from a custom template loader. Here's a blog post about creating template loaders, I can vouch for the fact it's pretty easy and works. Here's an even better one about doing exactly what you need.
I guess i didn't specifically point out that you probably do not want to try to change settings.TEMPLATE_DIRS per request, you will get wierd results at best.

Django: what is the most appropriate way to provide administrators with the ability to change small snippets of text

Using Django, what is the most appropriate way to provide administrators with the ability to change small snippets of text, for example in one of my sites there is a small piece of text on the front page I would like the administrator to be able to easily change in the backend, however I do not want to create a whole new app or model because then they would be able to create more than one area of text in this way, but I only want it to show up in one place on the homepage.
Any advice?
This might be a bit more than you're looking for, but django-chunks lets you embed snippets of text into your templates and allow administrators to edit them. Because the only way to put a chunk into a template is by embedding it yourself, you don't have to worry about someone creating additional chunks - they just won't show up anywhere on the site.
Create a new setting in the settings file (or if you're using something like Djblets, in the appropriate model [or if you're using something else, wherever it expects settings to be]) for it, and then use it in the template after passing the appropriate context.

Is there a standard directory browser dialogue in MFC that doesn't involve the user creating directories to specify ones that don't yet exist?

I am working on the bootstrap application of an installer, and I have a dialogue that the user can open to select a different target directory from the given default. Currently, I'm using the CFolderDialog for that, but for the user to select a folder that doesn't yet exist, he has to create the folder first. Once the user has specified the directory, I want to be able to delete it so that, when I launch the installer, it can create the folder itself such that it gets flagged for uninstall. Also, if the user cancels out of my bootstrap application at any time, I don't want any unwanted folders lying around from when the user mucked around in the folder browser. The problem that I'm having is that, if I try to remove the folder that the user created while browsing for a new target folder, I get a sharing violation error. (I compare the directory's creation time with what the system time was at the time the dialogue was launched to make sure that it's OK for me to delete the directory.)
What I need is either a way to get around that sharing violation or another standard dialogue that doesn't involve the user having to create a new directory in order to specify it just because it doesn't yet exist.
Edit: When I originally posted this, I forgot that the folder dialogue that I'm using is actually the XFolder Dialog on the Code Project site. While it does let the user browse for a directory, it's not as intuitive as folder browser dialogues that I've seen in installers in the past. What I'd really want is something where the user can browse to the folder in which their new folder is to go and then simply append the new folder to the path in the dialogue's edit box without having to create the new folder.
Update As the XFolder dialogue is a customization of the standard Open File dialogue which uses a template, it does not work on Vista or newer OSs. Because of this, I must abandon use of this for something else. I'm still looking for a solution here. If someone can show me how to set the initial directory (as opposed to the root directory) when using SHBrowseForFolder(), I'd be willing to use that as my solution.
For your purpose, it would probably make sense to let the user select a base directory, e.g. "C:\Program Files" (creating one in the process if so desired) and install into a subdirectory of that (a name which you append to the selected path and let your installer create). Display the combined path after the user has selected the base. This way, the user doesn't feel like he has taken on responsibility for the directory you're creating, but still has a reasonable level of control over the destination.
I have never seen such a dialog window, neither in MFC nor in any other technology. I agree with Shog9, you should provide the user with a way to separate the selection of a base directory and the creation of directories.
You can use SHBrowseForFolder without specifying neither BIF_BROWSEINCLUDEFILES or BIF_NONEWFOLDERBUTTON.