예제 #1
0
  def _editPost(self, request, entity, fields):
    """See base.View._editPost().
    """

    if not entity:
      # fill in the account field with the current User
      account = users.User()
      fields['account'] = account
      fields['user_id'] = account.user_id()
    else:
      fields['account'] = entity.account
      fields['user_id'] = entity.user_id

    # special actions if there is no ToS present
    site_tos = site_logic.getToS(site_logic.getSingleton())
    if not site_tos:
      # there is no Terms of Service set
      if not entity:
        # we are a new user so set the agrees_to_tos field to None
        fields['agreed_to_tos'] = None
      else:
        # editing an existing user so no value changes allowed
        fields['agreed_to_tos'] = entity.agreed_to_tos
    else:
      if not entity or not entity.agreed_to_tos:
        # set the time of agreement
        fields['agreed_to_tos_on'] = datetime.datetime.now()

    super(View, self)._editPost(request, entity, fields)
예제 #2
0
 def context(self):
   site = site_logic.getSingleton()
   return {
       'app_version': os.environ.get('CURRENT_VERSION_ID', '').split('.')[0],
       'page_name': 'Search GSoC',
       'cse_key':  site.cse_key
   }
예제 #3
0
  def agreesToSiteToS(self, entity):
    """Returns indication of User's answer to the site-wide Terms of Service.

    Args:
      entity: User entity to check for agreement to site-wide ToS

    Returns:
      True: no site-wide ToS is currently in effect on the site
      True: site-wide ToS is in effect *and* User agrees to it
        (User explicitly answered "Yes")
      False: site-wide ToS is in effect but User did not agree to it yet
    """
    if not site_logic.getToS(site_logic.getSingleton()):
      # no site-wide ToS in effect, so let the User slide for now
      return True

    try:
      agreed_on = entity.agreed_to_tos_on
    except db.Error:
      # return False indicating that answer is missing
      return False

    # user has not agreed yet
    if not agreed_on:
      return False

    return True
예제 #4
0
    def roles(self,
              request,
              access_type,
              page_name=None,
              params=None,
              **kwargs):
        """Displays the valid roles for this user.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: not used
    """

        if request.GET.get('fmt') == 'json':
            return self.getRolesListData(request)

        contents = []

        site = site_logic.getSingleton()
        site_name = site.site_name

        params = params.copy()
        params['no_lists_msg'] = self.DEF_NO_ROLES_MSG_FMT % site_name

        i = 0
        for _, loop_view in sorted(role_view.ROLE_VIEWS.iteritems()):
            list_params = loop_view.getParams().copy()
            list = helper.lists.getListGenerator(request, list_params, idx=i)
            contents.append(list)
            i += 1

        return self._list(request, params, contents, page_name)
예제 #5
0
파일: access.py 프로젝트: jamslevy/gsoc
  def checkIsUser(self, django_args=None):
    """Raises an alternate HTTP response if Google Account has no User entity.

    Args:
      django_args: a dictionary with django's arguments, not used

    Raises:
      AccessViolationResponse:
      * if no User exists for the logged-in Google Account, or
      * if no Google Account is logged in at all
      * if User has not agreed to the site-wide ToS, if one exists
    """

    self.checkIsLoggedIn()

    if not self.user:
      raise out_of_band.LoginRequest(message_fmt=DEF_NO_USER_LOGIN_MSG)

    if user_logic.agreesToSiteToS(self.user):
      return

    # Would not reach this point of site-wide ToS did not exist, since
    # agreesToSiteToS() call above always returns True if no ToS is in effect.
    login_msg_fmt = DEF_AGREE_TO_TOS_MSG_FMT % {
        'tos_link': redirects.getToSRedirect(site_logic.getSingleton())}

    raise out_of_band.LoginRequest(message_fmt=login_msg_fmt)
예제 #6
0
  def transitFromInvalid(self, entity):
    """The task was invalidated manually. So post a comment about it
    and unset the deadline.

    Args:
      entity: The GCITask entity
    """

    # do not unset the user and student properties since if student
    # challenges the manual invalidation of the task we should still
    # be able to retrieve the task. So just unset the deadline.
    properties = {
        'deadline': None,
        }

    changes = [ugettext('User-MelangeAutomatic'),
               ugettext('Action-None'),
               ugettext('Status-Invalid')]

    content = self.DEF_INVALID_MSG % {
        'site_name': site_logic.getSingleton().site_name,
        }

    update_dict = {
        'properties': properties,
        'changes': changes,
        'content': content,
        }

    return update_dict
예제 #7
0
파일: user.py 프로젝트: jamslevy/gsoc
    def agreesToSiteToS(self, entity):
        """Returns indication of User's answer to the site-wide Terms of Service.

    Args:
      entity: User entity to check for agreement to site-wide ToS

    Returns:
      True: no site-wide ToS is currently in effect on the site
      True: site-wide ToS is in effect *and* User agrees to it
        (User explicitly answered "Yes")
      False: site-wide ToS is in effect but User did not agree to it yet
    """
        if not site_logic.getToS(site_logic.getSingleton()):
            # no site-wide ToS in effect, so let the User slide for now
            return True

        try:
            agreed_on = entity.agreed_to_tos_on
        except db.Error:
            # return False indicating that answer is missing
            return False

        # user has not agreed yet
        if not agreed_on:
            return False

        return True
예제 #8
0
def sendRequestTaskNotification(org_admins, message):
  """Sends notifications to org admins that there is a student who requested
  more tasks from them.

  Args:
    org_admins: a list of org admins who the notification should be sent to
    message: a short message that will be included to the notification
  """

  from soc.logic.models.site import logic as site_logic

  # get the default mail sender
  default_sender = mail_dispatcher.getDefaultMailSender()

  if not default_sender:
    # no valid sender found, abort
    return
  else:
    (sender_name, sender) = default_sender

  # get site name
  site_entity = site_logic.getSingleton()
  template = DEF_TASK_REQUEST_TEMPLATE

  properties = {
      'message': message,
      'sender_name': sender_name,
      }

  for org_admin in org_admins:
    to = org_admin.user
    properties['to'] = to
    properties['to_name'] = to.name

    notifications.sendNotification(to, None, properties, subject, template)
예제 #9
0
  def search(self, request, access_type,
             page_name=None, params=None, **kwargs):
    """Displays the search page for the entity specified by **kwargs.

    Params usage:
      rights: The rights dictionary is used to check if the user has
        the required rights to view the admin page for this entity.
        See checkAccess for more details on how the rights dictionary
        is used to check access rights.
      name: The name value is used to set the entity_type in the
        context so that the template can refer to it.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: the Key Fields for the specified entity
    """

    # create default template context for use with any templates
    context = helper.responses.getUniversalContext(request)
    helper.responses.useJavaScript(context, params['js_uses_all'])

    context['page_name'] = page_name
    settings = site_logic.getSingleton()
    context['cse_key'] = settings.cse_key
    template = params['search_template']

    return helper.responses.respond(request, template, context)
예제 #10
0
  def getSidebarMenus(self, id, user, params=None):
    """See base.View.getSidebarMenus.

    Returns a custom sidebar entry for the 'site' singleton.
    """

    entity = site_logic.getSingleton()

    submenus = document_view.view.getMenusForScope(entity, self._params)

    try:
      rights = self._params['rights']
      rights.setCurrentUser(id, user)
      rights.checkIsHost()
      is_host = True
    except out_of_band.Error:
      is_host = False

    if is_host:
      submenus += [(redirects.getCreateDocumentRedirect(entity, 'site'),
          "Create a New Document", 'any_access')]

      submenus += [(redirects.getListDocumentsRedirect(entity, 'site'),
          "List Documents", 'any_access')]

    if entity.cse_key:
      # only add the search entry if a key is defined
      submenus += [('/site/search', 'Search', 'any_access')]

    new_params = {}
    new_params['sidebar_additional'] = submenus

    params = dicts.merge(params, new_params)
    return super(View, self).getSidebarMenus(id, user, params=params)
예제 #11
0
 def context(self):
     site = site_logic.getSingleton()
     return {
         'app_version': os.environ.get('CURRENT_VERSION_ID',
                                       '').split('.')[0],
         'page_name': 'Search GSoC',
         'cse_key': site.cse_key
     }
예제 #12
0
  def roles(self, request, access_type,
               page_name=None, params=None, **kwargs):
    """Displays the valid roles for this user.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: not used
    """

    lists_params = []

    for _, loop_view in sorted(role_view.ROLE_VIEWS.iteritems()):
      list_params = loop_view.getParams()

      if not list_params['show_in_roles_overview']:
        # filler for easy indexing
        lists_params.append(None)
        continue

      list_params = list_params.copy()
      list_params['public_field_keys'] = list_params['public_field_keys'] + ['status']
      list_params['public_field_names'] = list_params['public_field_names'] + ['Status']
      list_params['list_description'] = self.DEF_ROLE_LIST_MSG_FMT % list_params
      field_props = list_params.setdefault('public_field_props', {})
      field_props['status'] = {
          'searchoptions': {'defaultValue': 'Active'},
          'stype': 'select',
          'editoptions': {'value': ':All;^active$:Active;^inactive$:Inactive'},
      }

      lists_params.append(list_params)

    if lists.isDataRequest(request):
      return self.getRolesListData(request, lists_params)

    contents = []

    for i, list_params in enumerate(lists_params):
      if list_params is None:
        continue

      if not self.getRolesListData(lists.IsNonEmptyRequest(i), lists_params):
        continue

      list = lists.getListGenerator(request, list_params, idx=i)
      contents.append(list)

    params = params.copy()

    if not contents:
      site_name = site_logic.getSingleton().site_name
      params['list_msg'] = self.DEF_NO_ROLES_MSG_FMT % site_name

    return self._list(request, params, contents, page_name)
예제 #13
0
  def editPost(self, request, entity, context, params=None):
    """Overwrite so we can add the contents of the ToS.
    For params see base.View.editPost().
    """

    site_tos = site_logic.getToS(site_logic.getSingleton())
    if site_tos:
      context['tos_contents'] = site_tos.content

    return super(View, self).editPost(request, entity, context, params=params)
예제 #14
0
  def _getToSExampleText(self):
    """Returns example_text linking to site-wide ToS, or a warning message.
    """
    tos_link = redirects.getToSRedirect(site_logic.getSingleton())

    if not tos_link:
      return ('<div class="notice">&nbsp;<i>No site-wide</i> Terms of'
              ' Service <i>are currently set!</i>&nbsp;</div>')

    return ('<i>current site-wide <b><a href=%s>Terms of Service</a></b></i>'
            % tos_link)
예제 #15
0
    def __init__(self, params=None):
        """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

    Params:
      params: a dict with params for this View
    """

        rights = access.Checker(params)
        rights['unspecified'] = ['deny']
        rights['edit'] = ['deny']
        rights['show'] = [('checkIsMyEntity',
                           [notification_logic, 'scope_path'])]
        rights['delete'] = [('checkIsMyEntity',
                             [notification_logic, 'scope_path'])]
        rights['list'] = ['checkIsUser']
        # create is developer only for the time being to test functionality
        rights['create'] = ['checkIsDeveloper']

        new_params = {}
        new_params['logic'] = notification_logic
        new_params['rights'] = rights

        new_params['name'] = "Notification"

        new_params['no_create_with_key_fields'] = True
        new_params['create_form'] = CreateForm

        new_params['edit_redirect'] = '/%(url_name)s/list'

        new_params['list_template'] = 'soc/notification/list/notification.html'

        site_name = site_logic.getSingleton().site_name

        new_params['public_configuration'] = {"multiselect": True}
        new_params['public_field_extra'] = lambda entity: {
            "from": entity.from_user.name if entity.from_user else site_name,
        }
        new_params['public_field_keys'] = [
            "unread",
            "from",
            "subject",
            "created_on",
        ]
        new_params['public_field_names'] = [
            "Unread", "From", "Subject", "Received on"
        ]

        params = dicts.merge(params, new_params)

        super(View, self).__init__(params=params)
예제 #16
0
def sendNewNotificationMessage(notification_entity):
  """Sends an email to a user about a new notification.

    Args:
      notification_entity: Notification about which the message should be sent
  """

  from soc.logic.models.site import logic as site_logic
  from soc.views.models.notification import view as notification_view

  # create the url to show this notification
  notification_url = 'http://%(host)s%(index)s' % {
      'host' : system.getHostname(),
      'index': redirects.getPublicRedirect(notification_entity,
          notification_view.getParams())}

  sender = mail_dispatcher.getDefaultMailSender()
  site_entity = site_logic.getSingleton()
  site_name = site_entity.site_name

  # get the default mail sender
  default_sender = mail_dispatcher.getDefaultMailSender()

  if not default_sender:
    # no valid sender found, abort
    logging.error('No default sender')
    return
  else:
    (sender_name, sender) = default_sender

  to = accounts.denormalizeAccount(notification_entity.scope.account).email()
  subject = DEF_NEW_NOTIFICATION_MSG_SUBJECT_FMT % notification_entity.subject

  # create the message contents
  messageProperties = {
      'to_name': notification_entity.scope.name,
      'sender_name': sender_name,
      'to': to,
      'sender': sender,
      'site_name': site_name,
      'subject': force_unicode(subject),
      'notification' : notification_entity,
      'notification_url' : notification_url
      }

  # send out the message using the default new notification template
  mail_dispatcher.sendMailFromTemplate('soc/mail/new_notification.html',
                                       messageProperties)
예제 #17
0
파일: decorators.py 프로젝트: jamslevy/gsoc
    def view_wrapper(request, *args, **kwds):
        """View decorator wrapper method.
    """

        try:
            site = site_logic.getSingleton()

            # don't redirect admins, or if we're at /maintenance already
            no_redirect = user_logic.isDeveloper() or request.path == "/maintenance"

            if (not no_redirect) and timeline.isActivePeriod(site, "maintenance"):
                return http.HttpResponseRedirect("/maintenance")

            return func(request, *args, **kwds)
        except DeadlineExceededError, exception:
            logging.exception(exception)
            return http.HttpResponseRedirect("/soc/content/deadline_exceeded.html")
예제 #18
0
  def roles(self, request, access_type,
               page_name=None, params=None, **kwargs):
    """Displays the valid roles for this user.

    Args:
      request: the standard Django HTTP request object
      access_type : the name of the access type which should be checked
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      kwargs: not used
    """

    user = user_logic.getForCurrentAccount()

    # only select the roles for the current user
    # pylint: disable-msg=E1103
    filter = {
        'link_id': user.link_id,
        'status': ['active', 'inactive']
        }

    contents = []

    i = 0

    for _, loop_view in sorted(role_view.ROLE_VIEWS.iteritems()):
      list_params = loop_view.getParams().copy()
      list_params['list_action'] = (redirects.getEditRedirect, list_params)
      list_params['list_description'] = self.DEF_ROLE_LIST_MSG_FMT % list_params

      list = helper.lists.getListContent(request, list_params, filter,
                                         idx=i, need_content=True)

      if list:
        contents.append(list)
        i += 1

    site = site_logic.getSingleton()
    site_name = site.site_name

    params = params.copy()
    params['no_lists_msg'] = self.DEF_NO_ROLES_MSG_FMT % site_name

    return self._list(request, params, contents, page_name)
예제 #19
0
def sendTaskUpdateMail(subscriber, subject, message_properties=None):
  """Sends an email to a user about an update to a Task.

    Args:
      subscriber: The user entity to whom the message must be sent
      subject: Subject of the mail
      message_properties: The mail message properties
      template: Optional django template that is used to build the message body
  """

  from soc.logic.models.site import logic as site_logic

  site_entity = site_logic.getSingleton()
  site_name = site_entity.site_name

  # get the default mail sender
  default_sender = mail_dispatcher.getDefaultMailSender()

  if not default_sender:
    # no valid sender found, abort
    return
  else:
    (sender_name, sender) = default_sender

  to = accounts.denormalizeAccount(subscriber.account).email()

  # create the message contents
  new_message_properties = {
      'to_name': subscriber.name,
      'sender_name': sender_name,
      'to': to,
      'sender': sender,
      'site_name': site_name,
      'subject': force_unicode(subject),
      }

  messageProperties = dicts.merge(message_properties, new_message_properties)

  template = 'modules/ghop/task/update_notification'

  # send out the message using the default new notification template
  mail_dispatcher.sendMailFromTemplate(template, messageProperties)
예제 #20
0
def sendNotification(to_user, from_user, message_properties, subject, template):
  """Sends out a notification to the specified user.

  Args:
    to_user : user to which the notification will be send
    from_user: user from who sends the notifications (None iff sent by site)
    message_properties : message properties
    subject : subject of notification email
    template : template used for generating notification
  """

  from soc.logic.models.notification import logic as notification_logic
  from soc.logic.models.site import logic as site_logic

  if from_user:
    sender_name = from_user.name
  else:
    site_entity = site_logic.getSingleton()
    sender_name = 'The %s Team' % (site_entity.site_name)

  new_message_properties = {
      'sender_name': sender_name,
      'to_name': to_user.name,
      }

  message_properties = dicts.merge(message_properties, new_message_properties)

  message = loader.render_to_string(template, dictionary=message_properties)

  fields = {
      'from_user': from_user,
      'subject': subject,
      'message': message,
      'scope': to_user,
      'link_id': 't%i' % (int(time.time()*100)),
      'scope_path': to_user.link_id
  }

  key_name = notification_logic.getKeyNameFromFields(fields)

  # create and put a new notification in the datastore
  notification_logic.updateOrCreateFromKeyName(fields, key_name)
예제 #21
0
def sendWelcomeMessage(user_entity):
  """Sends out a welcome message to a user.

    Args:
      user_entity: User entity which the message should be send to
  """

  from soc.logic.models.site import logic as site_logic

  # get site name
  site_entity = site_logic.getSingleton()
  site_name = site_entity.site_name

  # get the default mail sender
  default_sender = mail_dispatcher.getDefaultMailSender()

  if not default_sender:
    # no valid sender found, should not happen but abort anyway
    logging.error('No default sender')
    return
  else:
    sender_name, sender = default_sender

  to = accounts.denormalizeAccount(user_entity.account).email()

  # create the message contents
  messageProperties = {
      'to_name': user_entity.name,
      'sender_name': sender_name,
      'to': to,
      'sender': sender,
      'subject': DEF_WELCOME_MSG_FMT % {
          'site_name': site_name,
          'name': user_entity.name
          },
      'site_name': site_name,
      'site_location': 'http://%s' % system.getHostname(),
      }

  # send out the message using the default welcome template
  mail_dispatcher.sendMailFromTemplate('soc/mail/welcome.html',
                                       messageProperties)
예제 #22
0
def sendNotification(to_user, from_user, message_properties, subject, template):
  """Sends out a notification to the specified user.

  Args:
    to_user : user to which the notification will be send
    from_user: user from who sends the notifications (None iff sent by site)
    message_properties : message properties
    subject : subject of notification email
    template : template used for generating notification
  """

  from soc.logic.models.notification import logic as notification_logic
  from soc.logic.models.site import logic as site_logic

  if from_user:
    sender_name = from_user.name
  else:
    site_entity = site_logic.getSingleton()
    sender_name = 'The %s Team' % (site_entity.site_name)

  new_message_properties = {
      'sender_name': sender_name,
      'to_name': to_user.name,
      }

  message_properties = dicts.merge(message_properties, new_message_properties)

  message = loader.render_to_string(template, dictionary=message_properties)

  fields = {
      'from_user': from_user,
      'subject': subject,
      'message': message,
      'scope': to_user,
      'link_id': 't%i' % (int(time.time()*100)),
      'scope_path': to_user.link_id
  }

  key_name = notification_logic.getKeyNameFromFields(fields)

  # create and put a new notification in the datastore
  notification_logic.updateOrCreateFromKeyName(fields, key_name)
예제 #23
0
 def testCleanAgreesToTos(self):
     """Tests that the agrees_to_tos field can be cleaned.
 """
     field_name = 'agrees_to_tos'
     clean_field = cleaning.clean_agrees_to_tos(field_name)
     # Test that the value of the field will be returned
     # if there is no tos document
     field_value = 'Any value'
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), field_value)
     site = site_logic.getSingleton()
     document_properties = {
         'link_id': 'a_tos',
         'scope_path': site.link_id,
         'scope': site,
         'prefix': 'site',
         'author': self.user,
         'title': 'Home Page',
         'short_name': 'Home',
         'content': 'This is the Home Page',
         'modified_by': self.user,
     }
     document = document_logic.updateOrCreateFromFields(document_properties)
     site.tos = document
     site.put()
     # Test that True will be returned if there is a tos document and
     # the value of the field is not empty
     field_value = 'Any value'
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), True)
     # Test that None will be returned instead of ValidationError if there is
     # a tos document and the value of the field is empty
     field_value = ''
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), None)
     #self.assertRaises(forms.ValidationError, clean_field, self.form)
     # Test that None will be returned instead of ValidationError if there is
     # a tos document and the value of the field is False
     field_value = False
     self.form.cleaned_data = {field_name: field_value}
     self.assertEqual(clean_field(self.form), None)
예제 #24
0
 def testCleanAgreesToTos(self):
   """Tests that the agrees_to_tos field can be cleaned.
   """
   field_name = 'agrees_to_tos'
   clean_field = cleaning.clean_agrees_to_tos(field_name)
   # Test that the value of the field will be returned
   # if there is no tos document
   field_value = 'Any value'
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), field_value)
   site = site_logic.getSingleton()
   document_properties = {
       'link_id': 'a_tos',
       'scope_path': site.link_id,
       'scope': site,
       'prefix': 'site',
       'author': self.user,
       'title': 'Home Page',
       'short_name': 'Home',
       'content': 'This is the Home Page',
       'modified_by': self.user,
       }
   document = document_logic.updateOrCreateFromFields(document_properties)
   site.tos = document
   site.put()
   # Test that True will be returned if there is a tos document and
   # the value of the field is not empty
   field_value = 'Any value'
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), True)
   # Test that None will be returned instead of ValidationError if there is
   # a tos document and the value of the field is empty
   field_value = ''
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), None)
   #self.assertRaises(forms.ValidationError, clean_field, self.form)
   # Test that None will be returned instead of ValidationError if there is
   # a tos document and the value of the field is False
   field_value = False
   self.form.cleaned_data = {field_name: field_value}
   self.assertEqual(clean_field(self.form), None)
예제 #25
0
def sendMail(to_user, subject, message_properties, template):
  """Sends an email with the specified properties and mail content

  Args:
    to_user: user entity to whom the mail should be sent
    subject: subject of the mail
    message_properties: contains those properties that need to be
                        customized
    template: template that holds the content of the mail
  """

  from soc.logic.models.site import logic as site_logic

  site_entity = site_logic.getSingleton()
  site_name = site_entity.site_name

  # get the default mail sender
  default_sender = mail_dispatcher.getDefaultMailSender()

  if not default_sender:
    # no valid sender found, abort
    return
  else:
    (sender_name, sender) = default_sender

  to = accounts.denormalizeAccount(to_user.account).email()

  # create the message contents
  new_message_properties = {
      'to_name': to_user.name,
      'sender_name': sender_name,
      'to': to,
      'sender': sender,
      'site_name': site_name,
      'subject': force_unicode(subject)
      }

  messageProperties = dicts.merge(message_properties, new_message_properties)

  # send out the message using the default new notification template
  mail_dispatcher.sendMailFromTemplate(template, messageProperties)
예제 #26
0
    def populate(self, redirect, request, args, kwargs):
        """Populates the fields in the RequestData object.

    Args:
      request: Django HTTPRequest object.
      args & kwargs: The args and kwargs django sends along.
    """
        self.redirect = redirect
        self.request = request
        self.args = args
        self.kwargs = kwargs
        self.GET = request.GET
        self.POST = request.POST
        self.path = request.path.encode('utf-8')
        self.full_path = request.get_full_path().encode('utf-8')
        self.site = site_logic.getSingleton()
        self.user = user_logic.getCurrentUser()
        if users.is_current_user_admin():
            self.is_developer = True
        if self.user and self.user.is_developer:
            self.is_developer = True
        self.gae_user = users.get_current_user()
예제 #27
0
  def populate(self, redirect, request, args, kwargs):
    """Populates the fields in the RequestData object.

    Args:
      request: Django HTTPRequest object.
      args & kwargs: The args and kwargs django sends along.
    """
    self.redirect = redirect
    self.request = request
    self.args = args
    self.kwargs = kwargs
    self.GET = request.GET
    self.POST = request.POST
    self.path = request.path.encode('utf-8')
    self.full_path = request.get_full_path().encode('utf-8')
    self.site = site_logic.getSingleton()
    self.user = user_logic.getCurrentUser()
    if users.is_current_user_admin():
      self.is_developer = True
    if self.user and self.user.is_developer:
      self.is_developer = True
    self.gae_user = users.get_current_user()
예제 #28
0
파일: site.py 프로젝트: SRabbelier/Melange
  def __call__(self, request, *args, **kwargs):
    """Custom call implementation.

    This avoids looking up unneeded data.
    """
    action = args[0] if args else ''

    if action == 'login':
      url = users.create_login_url('/')
    elif action == 'logout':
      url = users.create_logout_url('/')
    else:
      site = site_logic.getSingleton()
      program = site.active_program
      if program:
        kwargs['sponsor'] = program.scope_path
        kwargs['program'] = program.link_id
        url = reverse(program.homepage_url_name, kwargs=kwargs)
      else:
        url = reverse('edit_site_settings')

    self.redirect(url)
    return self.response
예제 #29
0
    def __call__(self, request, *args, **kwargs):
        """Custom call implementation.

    This avoids looking up unneeded data.
    """
        action = args[0] if args else ''

        if action == 'login':
            url = users.create_login_url('/')
        elif action == 'logout':
            url = users.create_logout_url('/')
        else:
            site = site_logic.getSingleton()
            program = site.active_program
            if program:
                kwargs['sponsor'] = program.scope_path
                kwargs['program'] = program.link_id
                url = reverse(program.homepage_url_name, kwargs=kwargs)
            else:
                url = reverse('edit_site_settings')

        self.redirect(url)
        return self.response
예제 #30
0
    def __init__(self, params=None):
        """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

    Params:
      params: a dict with params for this View
    """

        rights = access.Checker(params)
        rights['edit'] = ['deny']
        rights['show'] = [('checkIsMyEntity',
                           [notification_logic, 'scope_path'])]
        rights['delete'] = [('checkIsMyEntity',
                             [notification_logic, 'scope_path'])]
        rights['list'] = ['checkIsUser']
        # create is developer only for the time being to test functionality
        rights['create'] = ['checkIsDeveloper']

        new_params = {}
        new_params['logic'] = notification_logic
        new_params['rights'] = rights

        new_params['name'] = "Notification"

        new_params['no_create_with_key_fields'] = True
        new_params['create_form'] = CreateForm

        new_params['edit_redirect'] = '/%(url_name)s/list'

        new_params['public_configuration'] = {"multiselect": True}
        new_params['public_field_prefetch'] = ['from_user']
        new_params['public_field_extra'] = lambda entity: {
            "from":
            entity.from_user.name
            if entity.from_user else site_logic.getSingleton().site_name,
            "unread":
            "Not Read" if entity.unread else "Read",
        }
        new_params['public_field_props'] = {
            "unread": {
                "stype": "select",
                "editoptions": {
                    "value": ":All;^Read$:Read;^Not Read$:Not Read"
                }
            }
        }
        new_params['public_conf_extra'] = {
            "multiselect": True,
        }
        new_params['public_field_keys'] = [
            "unread",
            "from",
            "subject",
            "created_on",
        ]
        new_params['public_field_names'] = [
            "Unread", "From", "Subject", "Received on"
        ]
        new_params['public_button_global'] = [{
            'bounds': [1, 'all'],
            'id': 'mark_read',
            'caption': 'Mark as Read',
            'type': 'post',
            'parameters': {
                'url': '',
                'keys': ['key'],
                'refresh': 'current',
            }
        }, {
            'bounds': [1, 'all'],
            'id': 'mark_unread',
            'caption': 'Mark as Unread',
            'type': 'post',
            'parameters': {
                'url': '',
                'keys': ['key'],
                'refresh': 'current',
            }
        }, {
            'bounds': [1, 'all'],
            'id': 'delete',
            'caption': 'Delete Notification',
            'type': 'post',
            'parameters': {
                'url': '',
                'keys': ['key'],
                'refresh': 'current',
            }
        }]

        params = dicts.merge(params, new_params)

        params['public_row_extra'] = lambda entity: {
            "link": redirects.getPublicRedirect(entity, params)
        }

        super(View, self).__init__(params=params)
예제 #31
0
def sendSurveyReminderForProject(request, *args, **kwargs):
    """Sends a reminder mail for a given StudentProject and Survey.

  A reminder is only send if no record is on file for the given Survey and 
  StudentProject.

  Expects the following to be present in the POST dict:
    survey_key: specifies the key name for the ProjectSurvey to send reminders
                for
    survey_type: either project or grading depending on the type of Survey
    project_key: key which specifies the project to send a reminder for

  Args:
    request: Django Request object
  """

    from soc.logic import mail_dispatcher
    from soc.logic.models.site import logic as site_logic
    from soc.views.helper import redirects

    from soc.modules.gsoc.logic.models.org_admin import logic as org_admin_logic
    from soc.modules.gsoc.logic.models.student_project import logic as \
        student_project_logic
    from soc.modules.gsoc.logic.models.survey import grading_logic
    from soc.modules.gsoc.logic.models.survey import project_logic

    post_dict = request.POST

    project_key = post_dict.get('project_key')
    survey_key = post_dict.get('survey_key')
    survey_type = post_dict.get('survey_type')

    if not (project_key and survey_key and survey_type):
        # invalid task data, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid sendSurveyReminderForProject data: %s' % post_dict)

    # set logic depending on survey type specified in POST
    if survey_type == 'project':
        survey_logic = project_logic
    elif survey_type == 'grading':
        survey_logic = grading_logic

    # retrieve the project and survey
    student_project = student_project_logic.getFromKeyName(project_key)

    if not student_project:
        # no existing project found, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid project specified %s:' % project_key)

    survey = survey_logic.getFromKeyName(survey_key)

    if not survey:
        # no existing survey found, log and return OK
        return error_handler.logErrorAndReturnOK(
            'Invalid survey specified %s:' % survey_key)

    # try to retrieve an existing record
    record_logic = survey_logic.getRecordLogic()

    fields = {'project': student_project, 'survey': survey}
    record_entity = record_logic.getForFields(fields, unique=True)

    if not record_entity:
        # send reminder email because we found no record

        student_entity = student_project.student
        site_entity = site_logic.getSingleton()

        if survey_type == 'project':
            survey_redirect = redirects.getTakeSurveyRedirect(
                survey, {'url_name': 'gsoc/project_survey'})
            to_role = student_entity
            mail_template = 'soc/project_survey/mail/reminder_gsoc.html'
        elif survey_type == 'grading':
            survey_redirect = redirects.getTakeSurveyRedirect(
                survey, {'url_name': 'gsoc/grading_project_survey'})
            to_role = student_project.mentor
            mail_template = 'soc/grading_project_survey/mail/reminder_gsoc.html'

        survey_url = "http://%(host)s%(redirect)s" % {
            'redirect': survey_redirect,
            'host': system.getHostname(),
        }

        # set the context for the mail template
        mail_context = {
            'student_name': student_entity.name(),
            'project_title': student_project.title,
            'survey_url': survey_url,
            'survey_end': survey.survey_end,
            'to_name': to_role.name(),
            'site_name': site_entity.site_name,
        }

        # set the sender
        (_, sender_address) = mail_dispatcher.getDefaultMailSender()
        mail_context['sender'] = sender_address
        # set the receiver and subject
        mail_context['to'] = to_role.email
        mail_context['subject'] = 'Evaluation Survey "%s" Reminder' % (
            survey.title)

        # find all org admins for the project's organization
        org_entity = student_project.scope

        fields = {'scope': org_entity, 'status': 'active'}
        org_admin_entities = org_admin_logic.getForFields(fields)

        # collect email addresses for all found org admins
        org_admin_addresses = []

        for org_admin_entity in org_admin_entities:
            org_admin_addresses.append(org_admin_entity.email)

        if org_admin_addresses:
            mail_context['cc'] = org_admin_addresses

        # send out the email
        mail_dispatcher.sendMailFromTemplate(mail_template, mail_context)

    # return OK
    return http.HttpResponse()
예제 #32
0
def sendMailAboutGradingRecordResult(request, *args, **kwargs):
  """Sends out a mail about the result of one GradingRecord.

  Expects the following to be present in the POST dict:
    record_key: Specifies the key for the record to process.

  Args:
    request: Django Request object
  """

  from soc.logic import mail_dispatcher
  from soc.logic.models.grading_record import logic as grading_record_logic
  from soc.logic.models.org_admin import logic as org_admin_logic
  from soc.logic.models.site import logic as site_logic

  post_dict = request.POST

  # check and retrieve the record_key that has been done last
  if 'record_key' in post_dict and post_dict['record_key'].isdigit():
    record_key = int(post_dict['record_key'])
  else:
    record_key = None

  if not record_key:
    # no GradingRecord key specified, log and return OK
    error_handler.logErrorAndReturnOK(
        'No valid record_key specified in POST data: %s' % request.POST)

  record_entity = grading_record_logic.getFromID(record_key)

  if not record_entity:
    # no valid GradingRecord key specified, log and return OK
    error_handler.logErrorAndReturnOK(
        'No valid GradingRecord key specified: %s' % record_key)

  survey_group_entity = record_entity.grading_survey_group
  project_entity = record_entity.project
  student_entity = project_entity.student
  mentor_entity = project_entity.mentor
  org_entity = project_entity.scope
  site_entity = site_logic.getSingleton()

  mail_context = {
    'survey_group': survey_group_entity,
    'grading_record': record_entity,
    'project': project_entity,
    'organization': org_entity,
    'site_name': site_entity.site_name,
    'to_name': student_entity.name()
  }

  # set the sender
  (sender, sender_address) = mail_dispatcher.getDefaultMailSender()
  mail_context['sender'] = sender_address

  # set the receiver and subject
  mail_context['to'] = student_entity.email
  mail_context['cc'] = [mentor_entity.email]
  mail_context['subject'] = '%s results processed for %s' %(
      survey_group_entity.name, project_entity.title)

  # find all org admins for the project's organization
  fields = {'scope': org_entity,
            'status': 'active'}
  org_admin_entities = org_admin_logic.getForFields(fields)

  # collect email addresses for all found org admins
  org_admin_addresses = []

  for org_admin_entity in org_admin_entities:
    org_admin_addresses.append(org_admin_entity.email)

  if org_admin_addresses:
    mail_context['cc'].extend(org_admin_addresses)

  # send out the email using a template
  mail_template = 'soc/grading_record/mail/result.html'
  mail_dispatcher.sendMailFromTemplate(mail_template, mail_context)

  # return OK
  return http.HttpResponse()
예제 #33
0
def sendMailAboutGradingRecordResult(request, *args, **kwargs):
    """Sends out a mail about the result of one GradingRecord.

  Expects the following to be present in the POST dict:
    record_key: Specifies the key for the record to process.

  Args:
    request: Django Request object
  """

    from soc.logic import mail_dispatcher
    from soc.logic.models.grading_record import logic as grading_record_logic
    from soc.logic.models.org_admin import logic as org_admin_logic
    from soc.logic.models.site import logic as site_logic

    post_dict = request.POST

    # check and retrieve the record_key that has been done last
    if 'record_key' in post_dict and post_dict['record_key'].isdigit():
        record_key = int(post_dict['record_key'])
    else:
        record_key = None

    if not record_key:
        # no GradingRecord key specified, log and return OK
        error_handler.logErrorAndReturnOK(
            'No valid record_key specified in POST data: %s' % request.POST)

    record_entity = grading_record_logic.getFromID(record_key)

    if not record_entity:
        # no valid GradingRecord key specified, log and return OK
        error_handler.logErrorAndReturnOK(
            'No valid GradingRecord key specified: %s' % record_key)

    survey_group_entity = record_entity.grading_survey_group
    project_entity = record_entity.project
    student_entity = project_entity.student
    mentor_entity = project_entity.mentor
    org_entity = project_entity.scope
    site_entity = site_logic.getSingleton()

    mail_context = {
        'survey_group': survey_group_entity,
        'grading_record': record_entity,
        'project': project_entity,
        'organization': org_entity,
        'site_name': site_entity.site_name,
        'to_name': student_entity.name()
    }

    # set the sender
    (sender, sender_address) = mail_dispatcher.getDefaultMailSender()
    mail_context['sender'] = sender_address

    # set the receiver and subject
    mail_context['to'] = student_entity.email
    mail_context['cc'] = [mentor_entity.email]
    mail_context['subject'] = '%s results processed for %s' % (
        survey_group_entity.name, project_entity.title)

    # find all org admins for the project's organization
    fields = {'scope': org_entity, 'status': 'active'}
    org_admin_entities = org_admin_logic.getForFields(fields)

    # collect email addresses for all found org admins
    org_admin_addresses = []

    for org_admin_entity in org_admin_entities:
        org_admin_addresses.append(org_admin_entity.email)

    if org_admin_addresses:
        mail_context['cc'].extend(org_admin_addresses)

    # send out the email using a template
    mail_template = 'soc/grading_record/mail/result.html'
    mail_dispatcher.sendMailFromTemplate(mail_template, mail_context)

    # return OK
    return http.HttpResponse()
예제 #34
0
def sendSurveyReminderForProject(request, *args, **kwargs):
  """Sends a reminder mail for a given StudentProject and Survey.

  A reminder is only send if no record is on file for the given Survey and 
  StudentProject.

  Expects the following to be present in the POST dict:
    survey_key: specifies the key name for the ProjectSurvey to send reminders
                for
    survey_type: either project or grading depending on the type of Survey
    project_key: key which specifies the project to send a reminder for

  Args:
    request: Django Request object
  """

  from soc.logic import mail_dispatcher
  from soc.logic.models.org_admin import logic as org_admin_logic
  from soc.logic.models.site import logic as site_logic
  from soc.logic.models.student_project import logic as student_project_logic
  from soc.logic.models.survey import grading_logic
  from soc.logic.models.survey import project_logic
  from soc.views.helper import redirects

  post_dict = request.POST

  project_key = post_dict.get('project_key')
  survey_key = post_dict.get('survey_key')
  survey_type = post_dict.get('survey_type')

  if not (project_key and survey_key and survey_type):
    # invalid task data, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid sendSurveyReminderForProject data: %s' % post_dict)

  # set logic depending on survey type specified in POST
  if survey_type == 'project':
    survey_logic = project_logic
  elif survey_type == 'grading':
    survey_logic = grading_logic

  # retrieve the project and survey
  student_project = student_project_logic.getFromKeyName(project_key)

  if not student_project:
    # no existing project found, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid project specified %s:' % project_key)

  survey = survey_logic.getFromKeyName(survey_key)

  if not survey:
    # no existing survey found, log and return OK
    return error_handler.logErrorAndReturnOK(
        'Invalid survey specified %s:' % survey_key)

  # try to retrieve an existing record
  record_logic = survey_logic.getRecordLogic()

  fields = {'project': student_project,
            'survey': survey}
  record_entity = record_logic.getForFields(fields, unique=True)

  if not record_entity:
    # send reminder email because we found no record

    student_entity = student_project.student
    site_entity = site_logic.getSingleton()

    if survey_type == 'project':
      survey_redirect = redirects.getTakeSurveyRedirect(
          survey,{'url_name': 'project_survey'})
      to_role = student_entity
      mail_template = 'soc/project_survey/mail/reminder_gsoc.html'
    elif survey_type == 'grading':
      survey_redirect = redirects.getTakeSurveyRedirect(
          survey,{'url_name': 'grading_project_survey'})
      to_role = student_project.mentor
      mail_template = 'soc/grading_project_survey/mail/reminder_gsoc.html'

    survey_url = "http://%(host)s%(redirect)s" % {
      'redirect': survey_redirect,
      'host': os.environ['HTTP_HOST'],
      }

    # set the context for the mail template
    mail_context = {
        'student_name': student_entity.name(),
        'project_title': student_project.title,
        'survey_url': survey_url,
        'survey_end': survey.survey_end,
        'to_name': to_role.name(),
        'site_name': site_entity.site_name,
    }

    # set the sender
    (sender, sender_address) = mail_dispatcher.getDefaultMailSender()
    mail_context['sender'] = sender_address
    # set the receiver and subject
    mail_context['to'] = to_role.email
    mail_context['subject'] = 'Evaluation Survey "%s" Reminder' %(survey.title)

    # find all org admins for the project's organization
    org_entity = student_project.scope

    fields = {'scope': org_entity,
              'status': 'active'}
    org_admin_entities = org_admin_logic.getForFields(fields)

    # collect email addresses for all found org admins
    org_admin_addresses = []

    for org_admin_entity in org_admin_entities:
      org_admin_addresses.append(org_admin_entity.email)

    if org_admin_addresses:
      mail_context['cc'] = org_admin_addresses

    # send out the email
    mail_dispatcher.sendMailFromTemplate(mail_template, mail_context)

  # return OK
  return http.HttpResponse()
예제 #35
0
  def __init__(self, params=None):
    """Defines the fields and methods required for the base View class
    to provide the user with list, public, create, edit and delete views.

    Params:
      params: a dict with params for this View
    """

    rights = access.Checker(params)
    rights['edit'] = ['deny']
    rights['show'] = [('checkIsMyEntity', [notification_logic, 'scope_path'])]
    rights['delete'] = [('checkIsMyEntity', [notification_logic, 'scope_path'])]
    rights['list'] = ['checkIsUser']
    # create is developer only for the time being to test functionality
    rights['create'] = ['checkIsDeveloper']

    new_params = {}
    new_params['logic'] = notification_logic
    new_params['rights'] = rights

    new_params['name'] = "Notification"

    new_params['no_create_with_key_fields'] = True
    new_params['create_form'] = CreateForm

    new_params['edit_redirect'] = '/%(url_name)s/list'

    new_params['public_configuration'] = {"multiselect": True}
    new_params['public_field_prefetch'] = ['from_user']
    new_params['public_field_extra'] = lambda entity: {
        "from": entity.from_user.name if entity.from_user else
            site_logic.getSingleton().site_name,
        "unread": "Not Read" if entity.unread else "Read",
    }
    new_params['public_field_props'] = {
        "unread": {
            "stype": "select",
            "editoptions": {"value": ":All;^Read$:Read;^Not Read$:Not Read"}
        }
    }
    new_params['public_conf_extra'] = {
        "multiselect": True,
    }
    new_params['public_field_keys'] = ["unread", "from", "subject",
                                       "created_on",]
    new_params['public_field_names'] = ["Unread", "From", "Subject",
                                        "Received on"]
    new_params['public_button_global'] = [
        {
          'bounds': [1,'all'],
          'id': 'mark_read',
          'caption': 'Mark as Read',
          'type': 'post',
          'parameters': {
              'url': '',
              'keys': ['key'],
              'refresh': 'current',
              }
        },
        {
          'bounds': [1,'all'],
          'id': 'mark_unread',
          'caption': 'Mark as Unread',
          'type': 'post',
          'parameters': {
              'url': '',
              'keys': ['key'],
              'refresh': 'current',
              }
        },
        {
          'bounds': [1,'all'],
          'id': 'delete',
          'caption': 'Delete Notification',
          'type': 'post',
          'parameters': {
              'url': '',
              'keys': ['key'],
              'refresh': 'current',
              }
        }]

    params = dicts.merge(params, new_params)

    params['public_row_extra'] = lambda entity: {
        "link": redirects.getPublicRedirect(entity, params)
    }

    super(View, self).__init__(params=params)
예제 #36
0
 def testCleanRefs(self):
     """Tests that references can be cleaned.
 """
     document_prefix = 'site'
     params = {'logic': site_logic, 'document_prefix': document_prefix}
     fields = ['ref']
     clean_field = cleaning.clean_refs(params, fields)
     # Test that the format of the value of field is not validated, i.e.
     # no exception is raised even if the filled document link_id
     # is not a valid link_id
     document_link_id = 'v1_@?'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     clean_field(self.form)
     # Test that the value of field will be removed and error information
     # will be added to _errors field if it is a valid but nonexistent
     # document link_id
     document_link_id = 'a_document'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     after_cleaned_data = clean_field(self.form)
     self.assertEqual(after_cleaned_data.get('ref', None), None)
     self.assertNotEqual(self.form._errors[fields[0]], None)
     # Test that the value of field will be returned, a field named resolved_ref
     # containing the document will be added and no error messges will be added
     # if it is a valid and exisiting document link_id
     document_link_id = 'a_document'
     site = site_logic.getSingleton()
     self.form.cleaned_data = {
         'link_id': site.link_id,
         'scope_path': site.scope_path,
         'ref': document_link_id,
     }
     self.form._errors = {fields[0]: None}
     document_properties = {
         'link_id': document_link_id,
         'scope_path': site.link_id,
         'scope': site,
         'prefix': document_prefix,
         'author': self.user,
         'title': 'Home Page',
         'short_name': 'Home',
         'content': 'This is the Home Page',
         'modified_by': self.user,
     }
     document = document_logic.updateOrCreateFromFields(document_properties)
     after_cleaned_data = clean_field(self.form)
     self.assertEqual(after_cleaned_data['ref'], document_link_id)
     self.assertEqual(after_cleaned_data['resolved_ref'].link_id,
                      document_link_id)
     self.assertEqual(self.form._errors[fields[0]], None)
예제 #37
0
파일: xsrf.py 프로젝트: SRabbelier/Melange
 def _getSecretKey(self, request):
   """Gets the XSRF secret key from the request context."""
   return site_logic.getXsrfSecretKey(site_logic.getSingleton())
예제 #38
0
 def testCleanRefs(self):
   """Tests that references can be cleaned.
   """
   document_prefix = 'site'
   params = {'logic': site_logic, 'document_prefix': document_prefix}
   fields = ['ref']
   clean_field = cleaning.clean_refs(params, fields)
   # Test that the format of the value of field is not validated, i.e. 
   # no exception is raised even if the filled document link_id 
   # is not a valid link_id
   document_link_id = 'v1_@?'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   clean_field(self.form)
   # Test that the value of field will be removed and error information 
   # will be added to _errors field if it is a valid but nonexistent 
   # document link_id
   document_link_id = 'a_document'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   after_cleaned_data = clean_field(self.form)
   self.assertEqual(after_cleaned_data.get('ref', None), None)
   self.assertNotEqual(self.form._errors[fields[0]], None)
   # Test that the value of field will be returned, a field named resolved_ref
   # containing the document will be added and no error messges will be added 
   # if it is a valid and exisiting document link_id
   document_link_id = 'a_document'
   site = site_logic.getSingleton()
   self.form.cleaned_data = {
       'link_id': site.link_id,
       'scope_path': site.scope_path,
       'ref': document_link_id,
       }
   self.form._errors = {fields[0]: None}
   document_properties = {
       'link_id': document_link_id,
       'scope_path': site.link_id,
       'scope': site,
       'prefix': document_prefix,
       'author': self.user,
       'title': 'Home Page',
       'short_name': 'Home',
       'content': 'This is the Home Page',
       'modified_by': self.user,
       }
   document = document_logic.updateOrCreateFromFields(document_properties)
   after_cleaned_data = clean_field(self.form)
   self.assertEqual(after_cleaned_data['ref'], document_link_id)
   self.assertEqual(after_cleaned_data['resolved_ref'].link_id, 
                    document_link_id)
   self.assertEqual(self.form._errors[fields[0]], None)
예제 #39
0
 def _getSecretKey(self, request):
     """Gets the XSRF secret key from the request context."""
     return site_logic.getXsrfSecretKey(site_logic.getSingleton())