We needed to be able to grab the user's email address so that we could send
it to an external API, so we changed the file:
edx-platform
<https://github.com/appsembler/edx-platform/tree/367b4e69d151d9e4fa6bfee55dc6cbb08e955f60>
/common
<https://github.com/appsembler/edx-platform/tree/367b4e69d151d9e4fa6bfee55dc6cbb08e955f60/common>
/lib
<https://github.com/appsembler/edx-platform/tree/367b4e69d151d9e4fa6bfee55dc6cbb08e955f60/common/lib>
/xmodule
<https://github.com/appsembler/edx-platform/tree/367b4e69d151d9e4fa6bfee55dc6cbb08e955f60/common/lib/xmodule>
/xmodule
<https://github.com/appsembler/edx-platform/tree/367b4e69d151d9e4fa6bfee55dc6cbb08e955f60/common/lib/xmodule/xmodule>
/html_module.py
in the class HtmlModuleMixin(HtmlBlock, XModule) (lines added are in green)
def get_html(self):
data = self.data
if self.system.user_is_staff:
from django.contrib.auth.models import User
user = User.objects.get(id=self.system.user_id)
data = data.replace("%%USER_EMAIL%%", user.email)
elif self.system.anonymous_student_id:
data = data.replace("%%USER_ID%%",
self.system.anonymous_student_id)
if getattr(self.system, 'get_real_user', None):
user =
self.system.get_real_user(self.system.anonymous_student_id)
if user and user.is_authenticated():
data = data.replace("%%USER_EMAIL%%", user.email)
return data
On Wednesday, February 10, 2016 at 10:15:58 AM UTC-8, Robert R wrote:
>
> Sorry for the delay Robi.
>
> It looks like you are looking for something like the Keyword functionality
> <http://edx.readthedocs.org/projects/edx-partner-course-staff/en/latest/manage_live_course/bulk_email.html>
>
> supported in bulk emails, but that doesn't exist for the HTML Component.
>
> I did find the following code
> <https://github.com/edx/edx-platform/blob/master/common/lib/xmodule/xmodule/html_module.py#L78-L86>
>
> which seems to explain how %%USER_ID%% is getting replaced. I was trying
> to better understand the comment in that code, to see if that helps
> indicate a direction for you, but I haven't yet gotten an answer and didn't
> want to leave you with no response.
>
> Robert
>
> On Fri, Feb 5, 2016 at 2:56 PM, Roberto Renz <[email protected]
> <javascript:>> wrote:
>
>> Hi Robert,
>>
>> I'm trying to use the %%USER_ID%% just on a unit html content. it works
>> but It changed to student instead of the actual user ID.
>> so I tried playing with the templates for lms and cms and I can add stuff
>> to the footer or whatever other html file, but the variables are like ${
>> user.id} or ${user.username} and they work fine, I do get the value
>> of the variables..
>> what I would like to do is use those variables but on a normal html unit
>> so I can use them in an iframe however it doesn't convert the variables, I
>> just get the same string.
>>
>> Now I'm guessing, this is probably where I have to create an xblock and
>> use that in advanced blocks. but that is where I'm stuck, unless somebody
>> has any other ideas.
>>
>> Best Regards...
>>
>> Roberto Renz
>>
>>
>> On 2/5/2016 8:41 AM, Robert Raposa wrote:
>>
>> Hi Robi.
>>
>> What template are you in? Are you in a context with other variables that
>> are being properly replaced with this same syntax? Or are you using Django
>> Templates rather than Mako Templates?
>>
>> Thanks.
>>
>> Robert
>>
>> On Mon, Feb 1, 2016 at 12:59 AM, Robi Renz <[email protected]
>> <javascript:>> wrote:
>>
>>> Hi Campi
>>>
>>> I'm interested in doing this exact same thing..
>>>
>>> I'm trying to send data off to and external web address as parameters.
>>>
>>> but when I add the variable names and look at the course html I only
>>> visually see the ${user.username} on screen..
>>> the only one I can get to translate automatically is the %%USER_ID%%,
>>> and that one only puts student instead of the actual ID.
>>> any hints on how to tackle this would be greatly appreciated..
>>>
>>> Best Regards...
>>>
>>> Roberto Renz
>>>
>>> On Wednesday, January 27, 2016 at 9:11:28 AM UTC-7, campi wrote:
>>>>
>>>> Hi,
>>>>
>>>> I have noted that in the HTML templates of EDX LMS (e.g.
>>>> Navigation.html, courseware/courses.html, etc.) I can access a Python
>>>> variable called user.
>>>>
>>>> This is an example code portion of navigation.html
>>>>
>>>> <li class="primary">
>>>> <a href="${reverse('dashboard')}" class="user-link">
>>>> <i class="icon fa fa-home" aria-hidden="true"></i>
>>>> <span class="sr">${_("Dashboard for:")}</span>
>>>> <div>
>>>> *${user.username}*
>>>> </div>
>>>> </a>
>>>> </li>
>>>> <li class="primary">
>>>>
>>>> This *${user.username} *sentence prints the username of the user
>>>> currently logged. It is also possible to print the current user's email by
>>>> using
>>>>
>>>> *${user.email} *However, when I try to print the user's country (I
>>>> have set the country registration field as required) in this way
>>>> *${user.country}
>>>> *an error arises as the attribute 'country' does not exist in the
>>>> variable user.
>>>>
>>>> *AttributeError: 'User' object has no attribute 'country'*
>>>>
>>>> Where is this 'User' object defined in the code? Can I modify it adding
>>>> a country attribute in order to obtain the user's country in the LMS code?
>>>>
>>>> Thanks in advance for your help.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "General Open edX discussion" group.
>>> To view this discussion on the web visit
>>> <https://groups.google.com/d/msgid/edx-code/bdb36fc5-3b53-4438-8da2-7b0e01955090%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> https://groups.google.com/d/msgid/edx-code/bdb36fc5-3b53-4438-8da2-7b0e01955090%40googlegroups.com
>>> .
>>>
>>
>>
>>
>> --
>>
>> *Robert Raposa*
>>
>> edX | Software Architect | [email protected] <javascript:>
>>
>> 141 Portland Street, 9th floor
>>
>> Cambridge, MA 02139
>> <http://www.edxonline.org/>http://www.edx.org
>>
>> [image:
>> http://www.e-learn.nl/media/blogs/e-learn/edX_Logo_Col_RGB_FINAL.jpg?mtime=1336074566]
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "General Open edX discussion" group.
>> To view this discussion on the web visit
>> <https://groups.google.com/d/msgid/edx-code/CAKZ_z5mvGkem38ORCwUbNZOTPEiA4ggGP9ARj8n3Uaz0gCz9Hg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> https://groups.google.com/d/msgid/edx-code/CAKZ_z5mvGkem38ORCwUbNZOTPEiA4ggGP9ARj8n3Uaz0gCz9Hg%40mail.gmail.com
>> .
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "General Open edX discussion" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/edx-code/56B4FE84.2080603%40gmail.com
>> <https://groups.google.com/d/msgid/edx-code/56B4FE84.2080603%40gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
>
> --
>
> *Robert Raposa*
>
> edX | Software Architect | [email protected] <javascript:>
>
> 141 Portland Street, 9th floor
>
> Cambridge, MA 02139
> http://www.edx.org <http://www.edxonline.org/>
>
> [image:
> http://www.e-learn.nl/media/blogs/e-learn/edX_Logo_Col_RGB_FINAL.jpg?mtime=1336074566]
>
--
You received this message because you are subscribed to the Google Groups
"General Open edX discussion" group.
To view this discussion on the web visit
https://groups.google.com/d/msgid/edx-code/f1e63074-cd4f-43ff-b436-20e457abe7f1%40googlegroups.com.