app/soc/views/models/mentor.py
changeset 1726 711c8dcab67e
parent 1659 ed1a0f139a21
child 1763 6bd59cad39a5
equal deleted inserted replaced
1725:52d90bbc98dc 1726:711c8dcab67e
    29 from soc.logic import dicts
    29 from soc.logic import dicts
    30 from soc.logic.models import organization as org_logic
    30 from soc.logic.models import organization as org_logic
    31 from soc.views.helper import access
    31 from soc.views.helper import access
    32 from soc.views.helper import decorators
    32 from soc.views.helper import decorators
    33 from soc.views.helper import dynaform
    33 from soc.views.helper import dynaform
       
    34 from soc.views.helper import redirects
    34 from soc.views.helper import params as params_helper
    35 from soc.views.helper import params as params_helper
    35 from soc.views.helper import widgets
    36 from soc.views.helper import widgets
    36 from soc.views.models import organization as org_view
    37 from soc.views.models import organization as org_view
    37 from soc.views.models import role
    38 from soc.views.models import role
    38 
    39 
   190     form = context['form']
   191     form = context['form']
   191 
   192 
   192     if 'scope_path' in form.initial:
   193     if 'scope_path' in form.initial:
   193       scope_path = form.initial['scope_path']
   194       scope_path = form.initial['scope_path']
   194     elif 'scope_path' in request.POST:
   195     elif 'scope_path' in request.POST:
   195       # TODO: do this nicely
       
   196       scope_path = request.POST['scope_path']
   196       scope_path = request.POST['scope_path']
   197     else:
   197     else:
   198       # TODO: is this always sufficient?
       
   199       form.fields['mentor_agreement'] = None
   198       form.fields['mentor_agreement'] = None
   200       return
   199       return
   201 
   200 
   202     entity = org_logic.logic.getFromKeyName(scope_path)
   201     entity = org_logic.logic.getFromKeyName(scope_path)
   203 
   202 
   204     if not (entity and entity.scope and entity.scope.mentor_agreement):
   203     if not (entity and entity.scope and entity.scope.mentor_agreement):
   205       return
   204       return
   206 
   205 
   207     content = entity.scope.mentor_agreement.content
   206     agreement = entity.scope.mentor_agreement
   208 
   207 
   209     form.fields['mentor_agreement'].widget.text = content
   208     if not (entity and agreement):
       
   209       return
       
   210 
       
   211     content = agreement.content
       
   212     params = {'url_name': 'document'}
       
   213 
       
   214     widget = form.fields['mentor_agreement'].widget
       
   215     widget.text = content
       
   216     widget.url = redirects.getPublicRedirect(agreement, params)
       
   217 
   210 
   218 
   211 view = View()
   219 view = View()
   212 
   220 
   213 accept_invite = decorators.view(view.acceptInvite)
   221 accept_invite = decorators.view(view.acceptInvite)
   214 admin = decorators.view(view.admin)
   222 admin = decorators.view(view.admin)