Beispiel #1
0
 def post(self, user_token):
   team = Team.all().filter('user_token =', user_token).get()
   if team is None:
     # just make sure this pledge exists
     user_info = config_NOCOMMIT.pledge_service.loadPledgeInfo(user_token)
     if user_info is None:
       return self.notfound()
   form = TeamForm(self.request.POST, team)
   if not form.validate():
     return self.render_template("new_from_pledge.html", form=form)
   if team is None:
     gravatar = "https://secure.gravatar.com/avatar/%s?%s" % (
       hashlib.md5(user_info['email'].lower()).hexdigest(),
       urllib.urlencode({'s': str('120')}))
     team = Team.create(title=form.title.data,
                        description=form.description.data,
                        zip_code=form.zip_code.data,
                        user_token=user_token,
                        gravatar=gravatar)
   else:
     form.populate_obj(team)
   self.add_to_user(team)
   team.primary_slug = Slug.new(team)  
   try:
     result = config_NOCOMMIT.pledge_service.updateMailchimp(team) 
   except Exception as e:
     logging.error('Exception updating mailChimp: ' + str(e))
     logging.info(traceback.format_exc())
   team.put()
   if self.logged_in:
     return self.redirect("/t/%s" % team.primary_slug)
   return self.redirect("/dashboard/add_admin_from_pledge/%s" % user_token)
Beispiel #2
0
 def post(self, user_token):
     team = Team.all().filter('user_token =', user_token).get()
     if team is None:
         # just make sure this pledge exists
         user_info = config_NOCOMMIT.pledge_service.loadPledgeInfo(
             user_token)
         if user_info is None:
             return self.notfound()
     form = TeamForm(self.request.POST, team)
     if not form.validate():
         return self.render_template("new_from_pledge.html", form=form)
     if team is None:
         gravatar = "https://secure.gravatar.com/avatar/%s?%s" % (
             hashlib.md5(user_info['email'].lower()).hexdigest(),
             urllib.urlencode({'s': str('120')}))
         team = Team.create(title=form.title.data,
                            description=form.description.data,
                            zip_code=form.zip_code.data,
                            user_token=user_token,
                            gravatar=gravatar)
     else:
         form.populate_obj(team)
     self.add_to_user(team)
     team.primary_slug = Slug.new(team)
     try:
         result = config_NOCOMMIT.pledge_service.updateMailchimp(team)
     except Exception as e:
         logging.error('Exception updating mailChimp: ' + str(e))
         logging.info(traceback.format_exc())
     team.put()
     if self.logged_in:
         return self.redirect("/t/%s" % team.primary_slug)
     return self.redirect("/dashboard/add_admin_from_pledge/%s" %
                          user_token)
Beispiel #3
0
def add():
    form = TeamForm()
    if request.method == 'POST' and form.validate_on_submit():
        team = Team()
        form.populate_obj(team)
        db.session.add(team)
        db.session.commit()
        return redirect(url_for(".index"))
    elif request.method == 'POST':
        flash('Failed validation', 'danger alert-auto-dismiss')
    return render_template("teams/team_form.html", form=form, id=None)
Beispiel #4
0
def edit_team(team_id=None):
    model = get_object_or_404(Team, Team.id == team_id)
    if g.user not in model.members and not g.user.is_admin():
        return redirect(url_for('index'))
    form = TeamForm(obj=model)

    if form.validate_on_submit():
        form.populate_obj(model)
        db.session.add(model)
        db.session.commit()
        flash('Team updated', category='success')
        return redirect(url_for('team', team_id=model.id))
    return render_template('edit_team.html', team=model, form=form)
Beispiel #5
0
def edit(team_id):
    team = Team.query.get(team_id)
    form = TeamForm(obj=team)
    del form.number

    if request.method == 'POST' and form.validate_on_submit():
        form.populate_obj(team)
        db.session.commit()
        return redirect(url_for(".index"))
    elif request.method == 'POST':
        flash('Failed validation', 'danger alert-auto-dismiss')
    return render_template("teams/team_form.html",
                           form=form,
                           number=team.number,
                           id=team.id)
Beispiel #6
0
 def post(self, slug):
   team, _, is_admin = self.validate(slug)
   if team is None:
     return
   if not is_admin:
     return self.redirect("/t/%s" % team.primary_slug)
   form = TeamForm(self.request.POST, team)
   if not form.validate():
     return self.render_template("edit_team.html", form=form)
   form.populate_obj(team)
   team.primary_slug = Slug.new(team)
   try:
     result = config_NOCOMMIT.pledge_service.updateMailchimp(team) 
   except Exception as e:
     logging.error('Exception updating mailChimp: ' + str(e))
     logging.info(traceback.format_exc())
 
   team.put()
   self.redirect("/t/%s" % team.primary_slug)
Beispiel #7
0
    def post(self, slug):
        team, _, is_admin = self.validate(slug)
        if team is None:
            return
        if not is_admin:
            return self.redirect("/t/%s" % team.primary_slug)
        form = TeamForm(self.request.POST, team)
        if not form.validate():
            return self.render_template("edit_team.html", form=form)
        form.populate_obj(team)
        team.primary_slug = Slug.new(team)
        try:
            result = config_NOCOMMIT.pledge_service.updateMailchimp(team)
        except Exception as e:
            logging.error('Exception updating mailChimp: ' + str(e))
            logging.info(traceback.format_exc())

        team.put()
        self.redirect("/t/%s" % team.primary_slug)