示例#1
0
   def post(self, path):
      user = users.get_current_user()
      if user is None:
         self.redirect(users.create_login_url(self.request.uri))
         return

      if not utils.is_editor(user):
         # Error 401, user is not authorized.
         self.error(401)
         self.template_render('401.html', {})
         return

      plasmid = models.Plasmid.get_by_key_name(path)
      features = json.loads(plasmid.features)

      # Check if this is a delete request.
      if self.request.get('delete', None) is None:
         # It is a new feature request.
         form = FeatureForm(data=self.request.POST)
         if form.is_valid():
            features.append({
              'name': form.cleaned_data['name'],
              'start': form.cleaned_data['start'],
              'end': form.cleaned_data['end'],
              'orientation': form.cleaned_data['orientation'],
              'ftype': form.cleaned_data['ftype'],
            })
            # Save feature to data store.
            plasmid.features = json.dumps(features)
            plasmid.put()
            # Clean form.
            form = FeatureForm()
      else:
         # It is a delete request.
         delete_feature = int(self.request.get('delete'))
         features.pop(delete_feature)
         plasmid.features = json.dumps(features)
         plasmid.put()
         form = FeatureForm()

      template_vals = {
         'plasmid': plasmid,
         'zip_features': enumerate(features),
         'can_edit': utils.is_editor(users.get_current_user()),
         'form': form,
      }
      self.template_render('plasmid.html', template_vals)
示例#2
0
   def post(self):
      """Handle new plasmid data post."""
      user = users.get_current_user()
      if user is None:
         self.redirect(users.create_login_url(self.request.uri))
         return

      if not utils.is_editor(user):
         # Error 401, user is not authorized.
         self.error(401)
         self.template_render('401.html', {})
         return

      form = PlasmidForm(data=self.request.POST)

      if form.is_valid():
         name = form.cleaned_data['name']
         seq = form.cleaned_data['seq']
         comments = form.cleaned_data['comments']

         nid = utils.get_new_entity_id('plasmid')
         new_plasmid = models.Plasmid(
             key_name = str(nid),
             nid = nid,
             name = name,
             seq = seq,
             comments = comments,
             features = '[]'
         )
         new_plasmid.put()
         message = 'Plasmid #%d has been stored.' % nid

         template_vals = {
            'form': PlasmidForm(),
            'entity': 'plasmid',
            'message': message,
         }

      else:
         template_vals = {
            'form': form,
            'entity': 'plasmid',
            'message': ''
         }

      self.template_render('new_entity.html', template_vals)
示例#3
0
   def get(self, path):
      user = users.get_current_user()

      plasmid = models.Plasmid.get_by_key_name(path)
      if not plasmid:
         self.template_render('404.html', {})
         return

      features = json.loads(plasmid.features)

      template_vals = {
         'plasmid': plasmid,
         'zip_features': enumerate(features),
         'can_edit': user and utils.is_editor(user),
         'form': FeatureForm()
      }
      self.template_render('plasmid.html', template_vals)
示例#4
0
   def post(self):
      """Handle new prep data post."""
      user = users.get_current_user()
      if user is None:
         self.redirect(users.create_login_url(self.request.uri))
         return
      if not utils.is_editor(user):
         # Error 401, user is not authorized.
         self.error(401)
         self.template_render('401.html')
         return

      form = PrepForm(data=self.request.POST)

      if form.is_valid():
         preptype = form.cleaned_data['preptype']
         plasmid_id = form.cleaned_data['plasmid_id']
         comments = form.cleaned_data['comments']
         nid = utils.get_new_entity_id('prep')

         new_prep = models.Prep(
             key_name = str(nid),
             nid = nid,
             plasmid_id = plasmid_id,
             str_id = utils.get_str_id(plasmid_id, preptype),
             comments = comments
         )
         new_prep.put()
         message = 'Prep %s has been stored.' % new_prep.str_id

         template_vals = {
            'form': PrepForm(),
            'entity': 'prep',
            'message': message,
         }
      else:
         template_vals = {
            'form': form,
            'entity': 'prep',
            'message': ''
         }

      self.template_render('new_entity.html', template_vals)