コード例 #1
0
ファイル: video.py プロジェクト: fesp21/hasgeek.tv
def add_new_video(channel, playlist):
    form = VideoAddForm()
    if form.validate_on_submit():
        stream_playlist = channel.playlist_for_stream(create=True)
        video = Video(playlist=playlist if playlist is not None else stream_playlist)
        form.populate_obj(video)
        try:
            process_video(video, new=True)
            process_slides(video)
        except (DataProcessingError, ValueError) as e:
            flash(e.message, category="error")
            return render_form(form=form, title=u"New Video", submit=u"Add",
                               cancel_url=channel.url_for(), ajax=False)
        video.make_name()
        if playlist is not None and video not in playlist.videos:
            playlist.videos.append(video)
        if video not in stream_playlist.videos:
            stream_playlist.videos.append(video)
        db.session.commit()
        flash(u"Added video '%s'." % video.title, 'success')
        return render_redirect(video.url_for('edit'))
    if playlist is None:
        cancel_url = channel.url_for()
    else:
        cancel_url = playlist.url_for()
    return render_form(form=form, title=u"New Video", submit=u"Add",
                       cancel_url=cancel_url, ajax=False)
コード例 #2
0
ファイル: usergroup.py プロジェクト: Nirmal1212/funnel
def usergroup_edit(profile, space, kwargs):
    group = kwargs.get('group')
    form = UserGroupForm(model=UserGroup, parent=space)
    if group is not None:
        usergroup = UserGroup.query.filter_by(name=group, proposal_space=space).first_or_404()
        form.edit_id = usergroup.id
        if request.method == 'GET':
            form.name.data = usergroup.name
            form.title.data = usergroup.title
            form.users.data = '\r\n'.join([u.email or u.username or '' for u in usergroup.users])
    if form.validate_on_submit():
        if group is None:
            usergroup = UserGroup(proposal_space=space)
        usergroup.name = form.name.data
        usergroup.title = form.title.data
        formdata = [line.strip() for line in
            form.users.data.replace('\r', '\n').replace(',', '\n').split('\n') if line]
        usersdata = lastuser.getusers(names=formdata)
        users = []
        for userdata in usersdata or []:
            user = User.query.filter_by(userid=userdata['userid']).first()
            if user is None:
                user = User(userid=userdata['userid'], fullname=userdata['title'])
                db.session.add(user)
            users.append(user)
        usergroup.users = users
        db.session.commit()
        return redirect(usergroup.url_for(), code=303)
    if group is None:
        return render_form(form=form, title=_("New user group"), submit=_("Create user group"))

    else:
        return render_form(form=form, title=_("Edit user group"), submit=_("Save changes"))
コード例 #3
0
ファイル: profile.py プロジェクト: nibrahim/lastuser
def profile_edit(newprofile=False):
    form = ProfileForm(obj=g.user)
    form.fullname.description = current_app.config.get("FULLNAME_REASON")
    form.email.description = current_app.config.get("EMAIL_REASON")
    form.username.description = current_app.config.get("USERNAME_REASON")
    form.description.description = current_app.config.get("BIO_REASON")
    form.timezone.description = current_app.config.get("TIMEZONE_REASON")
    if g.user.email or newprofile is False:
        del form.email

    if newprofile is True:
        del form.description

    if form.validate_on_submit():
        # Can't auto-populate here because user.email is read-only
        g.user.fullname = form.fullname.data
        g.user.username = form.username.data
        if not newprofile:
            g.user.description = form.description.data
        g.user.timezone = form.timezone.data

        if newprofile and not g.user.email:
            useremail = UserEmailClaim(user=g.user, email=form.email.data)
            db.session.add(useremail)
            send_email_verify_link(useremail)
            db.session.commit()
            user_data_changed.send(g.user, changes=["profile", "email-claim"])
            flash("Your profile has been updated. We sent you an email to confirm your address", category="success")
        else:
            db.session.commit()
            user_data_changed.send(g.user, changes=["profile"])
            flash("Your profile has been updated.", category="success")

        if newprofile:
            return render_redirect(get_next_url(), code=303)
        else:
            return render_redirect(url_for("profile"), code=303)
    if newprofile:
        return render_form(
            form,
            title="Update profile",
            formid="profile_new",
            submit="Continue",
            message=u"Hello, %s. Please spare a minute to fill out your profile." % g.user.fullname,
            ajax=True,
        )
    else:
        return render_form(form, title="Edit profile", formid="profile_edit", submit="Save changes", ajax=True)
コード例 #4
0
def workspace_new():
    # Step 1: Get a list of organizations this user owns
    existing = Workspace.query.filter(Workspace.userid.in_(g.user.organizations_owned_ids())).all()
    existing_ids = [e.userid for e in existing]
    # Step 2: Prune list to organizations without a workspace
    new_workspaces = []
    for org in g.user.organizations_owned():
        if org['userid'] not in existing_ids:
            new_workspaces.append((org['userid'], org['title']))
    if not new_workspaces:
        return render_message(
            title=u"No organizations remaining",
            message=u"You do not have any organizations that do not yet have a workspace.")

    # Step 3: Ask user to select organization
    form = NewWorkspaceForm()
    form.workspace.choices = new_workspaces
    if form.validate_on_submit():
        # Step 4: Make a workspace
        org = [org for org in g.user.organizations_owned() if org['userid'] == form.workspace.data][0]
        workspace = Workspace(name=org['name'], title=org['title'], userid=org['userid'],
            currency=form.currency.data, fullname=form.fullname.data, address=form.address.data,
            cin=form.cin.data,pan=form.pan.data,tin=form.tin.data,tan=form.tan.data)
        db.session.add(workspace)
        db.session.commit()
        flash("Created new workspace for %s" % workspace.title, "success")
        return render_redirect(url_for('workspace_view', workspace=workspace.name), code=303)
    return render_form(form=form, title="Create a new organization workspace", submit="Create",
        formid="workspace_new", cancel_url=url_for('index'), ajax=False)
コード例 #5
0
ファイル: profile.py プロジェクト: hasgeek/lastuser
def verify_phone(phoneclaim):
    if phoneclaim.verification_expired:
        flash(_("You provided an incorrect verification code too many times"), 'danger')
        # Block attempts to verify this number, but also keep the claim so that a new
        # claim cannot be made. A periodic sweep to delete old claims is needed.
        return render_redirect(url_for('.account'), code=303)

    form = VerifyPhoneForm()
    form.phoneclaim = phoneclaim
    if form.validate_on_submit():
        if UserPhone.get(phoneclaim.phone) is None:
            if not current_auth.user.phones:
                primary = True
            else:
                primary = False
            userphone = UserPhone(user=current_auth.user, phone=phoneclaim.phone, gets_text=True)
            userphone.primary = primary
            db.session.add(userphone)
            db.session.delete(phoneclaim)
            db.session.commit()
            flash(_("Your phone number has been verified"), 'success')
            user_data_changed.send(current_auth.user, changes=['phone'])
            return render_redirect(url_for('.account'), code=303)
        else:
            db.session.delete(phoneclaim)
            db.session.commit()
            flash(_("This phone number has already been claimed by another user"), 'danger')
    elif request.method == 'POST':
        phoneclaim.verification_attempts += 1
        db.session.commit()
    return render_form(form=form, title=_("Verify phone number"), formid='phone_verify',
        submit=_("Verify"), ajax=True)
コード例 #6
0
ファイル: proposal.py プロジェクト: Nirmal1212/funnel
def proposal_new(profile, space):
    form = ProposalForm(model=Proposal, parent=space)
    del form.session_type  # We don't use this anymore
    form.section.query = ProposalSpaceSection.query.filter_by(proposal_space=space, public=True).order_by("title")
    if len(list(form.section.query.all())) == 0:
        # Don't bother with sections when there aren't any
        del form.section
    if request.method == "GET":
        form.email.data = g.user.email
        form.phone.data = g.user.phone
    if form.validate_on_submit():
        proposal = Proposal(user=g.user, proposal_space=space)
        with db.session.no_autoflush:
            proposal.votes.vote(g.user)  # Vote up your own proposal by default
        form.populate_obj(proposal.formdata)
        proposal.name = make_name(proposal.title)
        db.session.add(proposal)
        db.session.commit()
        flash(_("Your new session has been saved"), "info")
        return redirect(proposal.url_for(), code=303)
    return render_form(
        form=form,
        title=_("Submit a session proposal"),
        submit=_("Submit proposal"),
        message=Markup(
            _('This form uses <a href="http://daringfireball.net/projects/markdown/">Markdown</a> for formatting.')
        ),
    )
コード例 #7
0
ファイル: proposal.py プロジェクト: Nirmal1212/funnel
def proposal_edit(profile, space, proposal):
    form = ProposalForm(obj=proposal.formdata, model=Proposal, parent=space)
    if not proposal.session_type:
        del form.session_type  # Remove this if we're editing a proposal that had no session type
    form.section.query = ProposalSpaceSection.query.filter_by(proposal_space=space, public=True).order_by("title")
    if len(list(form.section.query.all())) == 0:
        # Don't bother with sections when there aren't any
        del form.section
    if proposal.user != g.user:
        del form.speaking
    if form.validate_on_submit():
        form.populate_obj(proposal.formdata)
        proposal.name = make_name(proposal.title)
        proposal.edited_at = datetime.utcnow()
        db.session.commit()
        flash(_("Your changes have been saved"), "info")
        return redirect(proposal.url_for(), code=303)
    return render_form(
        form=form,
        title=_("Edit session proposal"),
        submit=_("Save changes"),
        message=Markup(
            _('This form uses <a href="http://daringfireball.net/projects/markdown/">Markdown</a> for formatting.')
        ),
    )
コード例 #8
0
ファイル: video.py プロジェクト: hasgeek/hasgeek.tv
def video_new(channel, playlist):
    """
    Add a new video
    """
    form = VideoAddForm()
    if request.method == 'GET':
        if playlist is None:
            cancel_url = channel.url_for()
        else:
            cancel_url = playlist.url_for()
        html_form = render_form(form=form, title=_("New Video"), submit=_("Add"),
                           cancel_url=cancel_url, ajax=False, with_chrome=False)
        return {'channel': dict(channel.current_access()), 'playlist': dict(playlist.current_access()), 'form': html_form}
    if form.validate_on_submit():
        stream_playlist = channel.playlist_for_stream(create=True)
        video = Video(playlist=playlist if playlist is not None else stream_playlist)
        form.populate_obj(video)
        try:
            process_video(video, new=True)
            process_slides(video)
        except (DataProcessingError, ValueError) as e:
            return {'status': 'error', 'errors': {'video_url': [e.message]}}, 400
        video.make_name()
        if playlist is not None and video not in playlist.videos:
            playlist.videos.append(video)
        if video not in stream_playlist.videos:
            stream_playlist.videos.append(video)
        db.session.commit()
        return {'status': 'ok', 'doc': _("Added video {title}.".format(title=video.title)), 'result': {'new_video_edit_url': video.url_for('edit')}}, 201
    else:
        return {'status': 'error', 'errors': form.errors}, 400
コード例 #9
0
ファイル: order.py プロジェクト: hasgeek/boxoffice
def process_partial_refund_for_order(data_dict):
    order = data_dict['order']
    form = data_dict['form']
    request_method = data_dict['request_method']

    if request_method == 'GET':
        return jsonify(form_template=render_form(form=form, title=u"Partial refund", submit=u"Refund", with_chrome=False))
    if form.validate_on_submit():
        requested_refund_amount = form.amount.data
        payment = OnlinePayment.query.filter_by(order=order, pg_payment_status=RAZORPAY_PAYMENT_STATUS.CAPTURED).one()
        rp_resp = razorpay.refund_payment(payment.pg_paymentid, requested_refund_amount)
        rp_refund = rp_resp.json()
        if rp_resp.status_code == 200:
            transaction = PaymentTransaction(order=order, transaction_type=TRANSACTION_TYPE.REFUND,
                online_payment=payment, currency=CURRENCY.INR, pg_refundid=rp_refund['id'],
                refunded_at=func.utcnow())
            form.populate_obj(transaction)
            db.session.add(transaction)
            db.session.commit()
            send_order_refund_mail.queue(order.id, transaction.amount, transaction.note_to_user)
            return api_success(result={'order_net_amount': order.net_amount},
                doc=_(u"Refund processed for order"), status_code=200)
        else:
            raise PaymentGatewayError("Refund failed for order - {order} with the following details - {msg}".format(order=order.id,
                msg=rp_refund['error']['description']), 424,
            "Refund failed. {reason}. Please try again or contact support at {email}.".format(reason=rp_refund['error']['description'], email=order.organization.contact_email))
    else:
        return api_error(message='Invalid input',
            status_code=403,
            errors=form.errors)
コード例 #10
0
ファイル: login.py プロジェクト: bugrevelio/lastuser
def reset_email(user, kwargs):
    resetreq = PasswordResetRequest.query.filter_by(user=user, reset_code=kwargs['secret']).first()
    if not resetreq:
        return render_message(title=_("Invalid reset link"),
            message=_(u"The reset link you clicked on is invalid"))
    if resetreq.created_at < datetime.utcnow() - timedelta(days=1):
        # Reset code has expired (> 24 hours). Delete it
        db.session.delete(resetreq)
        db.session.commit()
        return render_message(title=_("Expired reset link"),
            message=_(u"The reset link you clicked on has expired"))

    # Logout *after* validating the reset request to prevent DoS attacks on the user
    logout_internal()
    db.session.commit()
    # Reset code is valid. Now ask user to choose a new password
    form = PasswordResetForm()
    form.edit_user = user
    if form.validate_on_submit():
        user.password = form.password.data
        db.session.delete(resetreq)
        db.session.commit()
        return render_message(title=_("Password reset complete"), message=Markup(
            _(u"Your password has been reset. You may now <a href=\"{loginurl}\">login</a> with your new password.").format(
                loginurl=escape(url_for('.login')))))
    return render_form(form=form, title=_("Reset password"), formid='reset', submit=_("Reset password"),
        message=Markup(_(u"Hello, <strong>{fullname}</strong>. You may now choose a new password.").format(
            fullname=escape(user.fullname))),
        ajax=False)
コード例 #11
0
ファイル: event.py プロジェクト: iambibhas/hacknight
def event_apply(profile, event):
    workflow = event.workflow()
    if not workflow.can_apply():
        flash("Hacknight is not accepting participants now, please try after sometime.")
        return render_redirect(event.url_for())
    values = {'profile': profile.name, 'event': event.name}
    participant = Participant.get(g.user, event)
    if not participant:
        # If no participant is found create a new participant entry
        # First collect some information about the new participant
        user = g.user
        form = ParticipantForm(obj=user)
        if form.validate_on_submit():
            total_participants = Participant.query.filter_by(event_id=event.id).count()
            participant = Participant(user=user, event=event)
            form.populate_obj(participant)
            participant.save_defaults()
            participant.status = PARTICIPANT_STATUS.PENDING if event.maximum_participants < total_participants else PARTICIPANT_STATUS.WL
            db.session.add(participant)
            db.session.commit()
            flash(u"Your request to participate has been recorded; you will be notified by the event manager", "success")
        else:
            return render_form(form=form, message=Markup(event.apply_instructions) if event.apply_instructions else "",
                title="Participant Details", submit=u"Participate",
                cancel_url=event.url_for(), ajax=False)
    # FIXME: Don't change anything unless this is a POST request
    elif participant.status == PARTICIPANT_STATUS.WITHDRAWN:
        participant.status = PARTICIPANT_STATUS.PENDING
        db.session.commit()
        flash(u"Your request to participate has been recorded; you will be notified by the event manager", "success")
    else:
        flash(u"Your request is pending", "error")
    return render_redirect(event.url_for(), code=303)
コード例 #12
0
ファイル: location.py プロジェクト: acharyasarvesh/hasjob
def location_new():
    if not (lastuser.has_permission('siteadmin') or (g.board and g.board.owner_is(g.user))):
        abort(403)
    now = datetime.utcnow()
    geonames = OrderedDict([(r.geonameid, None) for r in
        db.session.query(JobLocation.geonameid, db.func.count(JobLocation.geonameid).label('count')).join(
            JobPost).filter(JobPost.status.in_(POSTSTATUS.LISTED), JobPost.datetime > now - agelimit,
            ~JobLocation.geonameid.in_(db.session.query(Location.id).filter(Location.board == g.board))
            ).group_by(JobLocation.geonameid).order_by(db.text('count DESC')).limit(100)])
    data = location_geodata(geonames.keys())
    for row in data.values():
        geonames[row['geonameid']] = row
    choices = [('%s/%s' % (row['geonameid'], row['name']), row['picker_title']) for row in geonames.values()]
    form = NewLocationForm()
    form.geoname.choices = choices

    if form.validate_on_submit():
        geonameid, name = form.geoname.data.split('/', 1)
        geonameid = int(geonameid)
        title = geonames[geonameid]['use_title']
        location = Location(id=geonameid, board=g.board, name=name, title=title)
        db.session.add(location)
        db.session.commit()
        return redirect(location.url_for('edit'), code=303)

    return render_form(form=form, title=_("Add a location"), submit=_("Next"))
コード例 #13
0
ファイル: profile.py プロジェクト: MarammanDisco/lastuser
def profile_new():
    form = ProfileNewForm(obj=g.user)
    form.fullname.description = app.config.get('FULLNAME_REASON')
    form.email.description = app.config.get('EMAIL_REASON')
    form.username.description = app.config.get('USERNAME_REASON')
    form.description.description = app.config.get('BIO_REASON')
    if form.validate_on_submit():
        # Can't auto-populate here because user.email is read-only
        g.user.fullname = form.fullname.data
        g.user.username = form.username.data
        g.user.description = form.description.data
        if form.existing_email is None:
            useremail = UserEmailClaim(user=g.user, email=form.email.data)
            db.session.add(useremail)
            db.session.commit()
            send_email_verify_link(useremail)
            flash("Your profile was successfully updated. We sent you an email to confirm your address", category='success')
        else:
            db.session.commit()
            flash("Your profile was successfully updated.", category='success')

        return render_redirect(get_next_url(), code=303)
    return render_form(form, title="Update profile", formid="profile_new", submit="Continue",
        message=u"Hello, %s. Please spare a minute to fill out your profile." % g.user.fullname,
        ajax=True)
コード例 #14
0
ファイル: client.py プロジェクト: MarammanDisco/lastuser
def client_edit(client):
    form = RegisterClientForm(obj=client)
    form.client_owner.choices = available_client_owners()
    if request.method == 'GET':
        if client.user:
            form.client_owner.data = client.user.userid
        else:
            form.client_owner.data = client.org.userid

    if form.validate_on_submit():
        if client.user != form.user or client.org != form.org:
            # Ownership has changed. Remove existing permission assignments
            for perm in UserClientPermissions.query.filter_by(client=client).all():
                db.session.delete(perm)
            for perm in TeamClientPermissions.query.filter_by(client=client).all():
                db.session.delete(perm)
            flash("This application’s owner has changed, so all previously assigned permissions "
                "have been revoked", "warning")
        form.populate_obj(client)
        client.user = form.user
        client.org = form.org
        if not client.team_access:
            # This client does not have access to teams in organizations. Remove all existing assignments
            for cta in ClientTeamAccess.query.filter_by(client=client).all():
                db.session.delete(cta)
        db.session.commit()
        return render_redirect(url_for('client_info', key=client.key), code=303)

    return render_form(form=form, title="Edit application", formid="client_edit",
        submit="Save changes", ajax=True)
コード例 #15
0
ファイル: org.py プロジェクト: haseebgit/lastuser
def team_edit(org, team):
    form = TeamForm(obj=team)
    if form.validate_on_submit():
        form.populate_obj(team)
        db.session.commit()
        return render_redirect(url_for("org_info", name=org.name), code=303)
    return render_form(form=form, title=u"Edit team: %s" % team.title, formid="team_edit", submit="Save", ajax=False)
コード例 #16
0
ファイル: login.py プロジェクト: MarammanDisco/lastuser
def reset_email(user, kwargs):
    logout_internal()
    resetreq = PasswordResetRequest.query.filter_by(user=user, reset_code=kwargs["secret"]).first()
    if not resetreq:
        return render_message(title="Invalid reset link", message=Markup("The reset link you clicked on is invalid."))
    if resetreq.created_at < datetime.utcnow() - timedelta(days=1):
        # Reset code has expired (> 24 hours). Delete it
        db.session.delete(resetreq)
        db.session.commit()
        return render_message(title="Expired reset link", message=Markup("The reset link you clicked on has expired."))

    # Reset code is valid. Now ask user to choose a new password
    form = PasswordResetForm()
    if form.validate_on_submit():
        user.password = form.password.data
        db.session.delete(resetreq)
        db.session.commit()
        return render_message(
            title="Password reset complete",
            message=Markup(
                'Your password has been reset. You may now <a href="%s">login</a> with your new password.'
                % escape(url_for("login"))
            ),
        )
    return render_form(
        form=form,
        title="Reset password",
        formid="reset",
        submit="Reset password",
        message=Markup("Hello, <strong>%s</strong>. You may now choose a new password." % user.fullname),
        ajax=True,
    )
コード例 #17
0
ファイル: event.py プロジェクト: michalumni/hiku
def event_edit(profile, event):
    workflow = event.workflow()
    if not workflow.can_edit():
        abort(403)
    form = EventForm(obj=event)
    if form.venue.data:
        form.start_datetime.timezone = form.venue.data.timezone
        form.end_datetime.timezone = form.venue.data.timezone
    else:
        form.start_datetime.timezone = app.config['TIMEZONE']
        form.end_datetime.timezone = app.config['TIMEZONE']
    if form.validate_on_submit():
        old_name = event.name
        form.populate_obj(event)
        if not event.name:
            event.make_name()
        if event.name != old_name:
            redirect_to = EventRedirect.query.filter_by(name=old_name, profile=profile).first()
            if redirect_to:
                redirect_to.event = event
            else:
                redirect_to = EventRedirect(name=old_name, profile=profile, event=event)
                db.session.add(redirect_to)
        db.session.commit()
        flash(u"Your edits to %s are saved" % event.title, "success")
        return render_redirect(event.url_for(), code=303)
    return render_form(form=form, title="Edit Event", submit=u"Save",
        cancel_url=event.url_for(), ajax=False)
コード例 #18
0
ファイル: board.py プロジェクト: abhinaykumar/hasjob
def board_new():
    # Step 1: Get a list of organizations this user owns
    existing = Board.query.filter(Board.userid.in_(g.user.organizations_owned_ids())).all()
    existing_ids = [e.userid for e in existing]
    # Step 2: Prune list to organizations without a board
    new_boards = []
    for org in g.user.organizations_owned():
        if org['userid'] not in existing_ids:
            new_boards.append((org['userid'], org['title']))
    if not new_boards:
        return render_message(
            title=u"No organizations found",
            message=Markup(u"You do not have any organizations that do not already have a board. "
                u'Would you like to <a href="%s">create a new organization</a>?' %
                    lastuser.endpoint_url('/organizations/new')))
    # Step 3: Ask user to select organization
    form = NewBoardForm()
    form.board.choices = new_boards
    if request.method == 'GET':
        form.board.data = new_boards[0][0]
    if form.validate_on_submit():
        # Step 4: Make a board
        org = [org for org in g.user.organizations_owned() if org['userid'] == form.board.data][0]
        board = Board(name=org['name'], title=org['title'], userid=org['userid'])
        db.session.add(board)
        db.session.commit()
        flash(u"Created a board for %s" % board.title, 'success')
        return render_redirect(url_for('board_edit', board=board.name), code=303)
    return render_form(form=form, title="Create a board for your organization...", submit="Next",
        formid="board_new", cancel_url=url_for('index'), ajax=False)
コード例 #19
0
ファイル: video.py プロジェクト: kracekumar/hasgeek.tv
def video_edit(channel, playlist, video, kwargs):
    """
    Edit video
    """
    if video.channel.userid not in g.user.user_organization_ids():
        # User isn't authorized to edit
        abort(403)

    if playlist != video.playlist:
        # This video isn't in this playlist. Redirect to canonical URL
        return redirect(url_for('video_edit', channel=video.channel.name, playlist=video.playlist.name, video=video.url_name))

    if kwargs['video'] != video.url_name:
        # Video's URL has changed. Redirect user to prevent old/invalid names
        # showing in the URL
        return redirect(url_for('video_delete', channel=channel.name, playlist=playlist.name, video=video.url_name))

    form = VideoEditForm(obj=video)
    if form.validate_on_submit():
        form.populate_obj(video)
        video.process_slides()
        db.session.commit()
        flash(u"Edited video '%s'." % video.title, 'success')
        return render_redirect(url_for('video_view', channel=channel.name, playlist=playlist.name, video=video.url_name))
    return render_form(form=form, title=u"Edit video", submit=u"Save",
        cancel_url=url_for('video_view', channel=channel.name, playlist=playlist.name, video=video.url_name),
        ajax=True)
コード例 #20
0
ファイル: profile.py プロジェクト: HashResearch/lastuser
def profile_edit(newprofile=False):
    form = ProfileForm(obj=g.user)
    form.edit_user = g.user
    form.fullname.description = current_app.config.get('FULLNAME_REASON')
    form.email.description = current_app.config.get('EMAIL_REASON')
    form.username.description = current_app.config.get('USERNAME_REASON')
    form.description.description = current_app.config.get('BIO_REASON')
    form.timezone.description = current_app.config.get('TIMEZONE_REASON')
    if g.user.email or newprofile is False:
        del form.email

    if newprofile is True:
        del form.description

    if form.validate_on_submit():
        # Can't auto-populate here because user.email is read-only
        g.user.fullname = form.fullname.data
        g.user.username = form.username.data
        if not newprofile:
            g.user.description = form.description.data
        g.user.timezone = form.timezone.data

        if newprofile and not g.user.email:
            useremail = UserEmailClaim.get(user=g.user, email=form.email.data)
            if useremail is None:
                useremail = UserEmailClaim(user=g.user, email=form.email.data)
                db.session.add(useremail)
            send_email_verify_link(useremail)
            db.session.commit()
            user_data_changed.send(g.user, changes=['profile', 'email-claim'])
            flash("Your profile has been updated. We sent you an email to confirm your address", category='success')
        else:
            db.session.commit()
            user_data_changed.send(g.user, changes=['profile'])
            flash("Your profile has been updated.", category='success')

        if newprofile:
            return render_redirect(get_next_url(), code=303)
        else:
            return render_redirect(url_for('profile'), code=303)
    if newprofile:
        return render_form(form, title="Update profile", formid="profile_new", submit="Continue",
            message=Markup(u"Hello, <strong>{fullname}</strong>. Please spare a minute to fill out your profile.".format(
                fullname=escape(g.user.fullname))),
            ajax=True)
    else:
        return render_form(form, title="Edit profile", formid="profile_edit", submit="Save changes", ajax=True)
コード例 #21
0
ファイル: client.py プロジェクト: MarammanDisco/lastuser
def resource_edit(client, resource):
    form = ResourceForm(obj=resource)
    if form.validate_on_submit():
        form.populate_obj(resource)
        db.session.commit()
        flash("Your resource has been edited", 'success')
        return render_redirect(url_for('client_info', key=client.key), code=303)
    return render_form(form=form, title="Edit resource", formid="resource_edit", submit="Save changes", ajax=True)
コード例 #22
0
ファイル: event.py プロジェクト: hasgeek/funnel
def ticket_client_edit(profile, project, ticket_client):
    form = TicketClientForm(obj=ticket_client, model=TicketClient)
    if form.validate_on_submit():
        form.populate_obj(ticket_client)
        db.session.commit()
        flash(_(u"Your changes have been saved"), 'info')
        return redirect(project.url_for('admin'), code=303)
    return render_form(form=form, title=_(u"Edit ticket client"), submit=_(u"Save changes"))
コード例 #23
0
ファイル: section.py プロジェクト: hasgeek/funnel
 def edit(self):
     form = SectionForm(obj=self.obj, model=Section, parent=self.obj.parent)
     if form.validate_on_submit():
         form.populate_obj(self.obj)
         db.session.commit()
         flash(_("Your section has been edited"), 'info')
         return redirect(self.obj.project.url_for('sections'), code=303)
     return render_form(form=form, title=_("Edit section"), submit=_("Save changes"))
コード例 #24
0
ファイル: event.py プロジェクト: braunmagrin/funnel
def event_edit(profile, space, event):
    form = EventForm(obj=event, model=Event)
    if form.validate_on_submit():
        form.populate_obj(event)
        db.session.commit()
        flash(_(u"Your changes have been saved"), 'info')
        return redirect(space.url_for('admin'), code=303)
    return render_form(form=form, title=_(u"Edit event"), submit=_(u"Save changes"))
コード例 #25
0
ファイル: video.py プロジェクト: hasgeek/hasgeek.tv
def video_edit(channel, playlist, video):
    """
    Edit video
    """
    current_speakers = [speaker.userid for speaker in video.speakers]
    form = VideoEditForm(obj=video)
    if request.method == 'GET':
        html_form = render_form(form=form, title=_("Edit Video"), submit=_("Save"),
            cancel_url=video.url_for(), ajax=False, with_chrome=False)
        return {'video': dict(video.current_access()), 'form': html_form}
    if form.validate():
        form.populate_obj(video)
        if not video.name:
            video.make_name()
        if video.video_url != form.video_url.data:
            try:
                process_video(video, new=False)
            except (DataProcessingError, ValueError) as e:
                return {'status': 'error', 'errors': {'video_url': [e.message]}}, 400
        if video.slides_url != form.slides_url.data:
            try:
                process_slides(video)
                if video.video_slides_mapping:
                    video.video_slides_mapping_json = make_presentz_json(video, json.loads(video.video_slides_mapping))
            except (DataProcessingError, ValueError) as e:
                return {'status': 'error', 'errors': {'slides_url': [e.message]}}, 400
        new_speakers = [new_speaker.userid for new_speaker in form.speakers.data]
        for current_speaker in current_speakers:
            # Remove speaker
            if current_speaker not in new_speakers:
                speaker_channel = Channel.query.filter_by(userid=current_speaker).first()
                if speaker_channel:
                    speaker_playlist = speaker_channel.playlist_for_speaking_in()
                    if speaker_playlist:
                        speaker_playlist.videos.remove(video)
        for new_speaker in new_speakers:
            # Add speaker
            if new_speaker not in current_speakers:
                userinfo = lastuser.getuser_by_userid(new_speaker)
                if userinfo:
                    speaker_channel = Channel.query.filter_by(userid=new_speaker).first()
                    if speaker_channel is None:
                        # Create a channel for this speaker. They have never logged in to hasgeek.tv
                        # at this point, but when they do, the channel will be waiting for them
                        speaker_channel = Channel(userid=userinfo['userid'], name=userinfo['name'] or userinfo['userid'],
                            title=userinfo['title'], type=CHANNEL_TYPE.PERSON)
                        db.session.add(speaker_channel)
                    else:
                        speaker_channel.title = userinfo['title']
                        speaker_channel.name = userinfo['name'] or userinfo['userid']
                    speaker_playlist = speaker_channel.playlist_for_speaking_in(create=True)
                    if video not in speaker_playlist.videos:
                        speaker_playlist.videos.append(video)
                else:
                    return {'status': 'error', 'errors': ['Could not find a user matching that name or email address']}, 400
        db.session.commit()
        return {'status': 'ok', 'doc': _("Edited video {title}.".format(title=video.title)), 'result': {}}, 201
    return {'status': 'error', 'errors': form.errors}, 400
コード例 #26
0
ファイル: client.py プロジェクト: MarammanDisco/lastuser
def resource_action_edit(client, resource, action):
    form = ResourceActionForm(obj=action)
    form.edit_resource = resource
    if form.validate_on_submit():
        form.populate_obj(action)
        db.session.commit()
        flash("Your action has been edited", 'success')
        return render_redirect(url_for('client_info', key=client.key), code=303)
    return render_form(form=form, title="Edit action", formid="action_edit", submit="Save changes", ajax=True)
コード例 #27
0
ファイル: venue.py プロジェクト: hasgeek/funnel
 def edit(self):
     form = VenueRoomForm(obj=self.obj)
     if form.validate_on_submit():
         form.populate_obj(self.obj)
         self.obj.make_name(reserved=RESERVED_VENUEROOM)
         db.session.commit()
         flash(_(u"Saved changes to this room"), 'success')
         return render_redirect(self.obj.venue.project.url_for('venues'), code=303)
     return render_form(form=form, title=_("Edit room"), submit=_("Save"), cancel_url=self.obj.venue.project.url_for('venues'), ajax=False)
コード例 #28
0
ファイル: org.py プロジェクト: haseebgit/lastuser
def team_new(org):
    form = TeamForm()
    if form.validate_on_submit():
        team = Team(org=org)
        form.populate_obj(team)
        db.session.add(team)
        db.session.commit()
        return render_redirect(url_for("org_info", name=org.name), code=303)
    return render_form(form=form, title=u"Create new team", formid="team_new", submit="Create", ajax=False)
コード例 #29
0
ファイル: venue.py プロジェクト: Nirmal1212/funnel
def venue_edit(profile, space, venue):
    form = VenueForm(obj=venue)
    if form.validate_on_submit():
        form.populate_obj(venue)
        venue.make_name(reserved=RESERVED_VENUE)
        db.session.commit()
        flash(_(u"Saved changes to this venue"), 'success')
        return render_redirect(space.url_for('venues'), code=303)
    return render_form(form=form, title=_("Edit venue"), submit=_("Save"), cancel_url=space.url_for('venues'), ajax=False)
コード例 #30
0
ファイル: profile.py プロジェクト: Nirmal1212/funnel
def profile_new():
    # Step 1: Get a list of organizations this user owns
    existing = Profile.query.filter(
        Profile.userid.in_(g.user.organizations_owned_ids())).all()
    existing_ids = [e.userid for e in existing]
    # Step 2: Prune list to organizations without a profile
    new_profiles = []
    for org in g.user.organizations_owned():
        if org['userid'] not in existing_ids:
            new_profiles.append((org['userid'], org['title']))
    if not new_profiles:
        return render_message(
            title=_(u"No organizations found"),
            message=Markup(
                _(u"You do not have any organizations that do not already have a Talkfunnel. "
                  u'Would you like to <a href="{link}">create a new organization</a>?'
                  ).format(link=lastuser.endpoint_url('/organizations/new'))))
    eligible_profiles = []
    for orgid, title in new_profiles:
        if Team.query.filter_by(orgid=orgid).first() is not None:
            eligible_profiles.append((orgid, title))
    if not eligible_profiles:
        return render_message(
            title=_(u"No organizations available"),
            message=
            _(u"To create a Talkfunnel for an organization, you must be the owner of the organization."
              ))

    # Step 3: Ask user to select organization
    form = NewProfileForm()
    form.profile.choices = eligible_profiles
    if request.method == 'GET':
        form.profile.data = new_profiles[0][0]
    if form.validate_on_submit():
        # Step 4: Make a profile
        org = [
            org for org in g.user.organizations_owned()
            if org['userid'] == form.profile.data
        ][0]
        profile = Profile(
            name=org['name'], title=org['title'], userid=org['userid'])
        db.session.add(profile)
        db.session.commit()
        flash(
            _(u"Created a profile for {profile}").format(
                profile=profile.title), "success")
        return render_redirect(profile.url_for('edit'), code=303)
    return render_form(
        form=form,
        title=_(u"Create a Talkfunnel for your organization..."),
        message=
        _(u"Talkfunnel is a free service while in beta. Sign up now to help us test the service."
          ),
        submit="Next",
        formid="profile_new",
        cancel_url=url_for('index'),
        ajax=False)
コード例 #31
0
def domain_edit(domain):
    obj = Domain.get(domain)
    if not obj:
        abort(404)
    if not (lastuser.has_permission('siteadmin') or obj.editor_is(g.user)):
        abort(403)
    form = DomainForm(obj=obj)
    if form.validate_on_submit():
        form.populate_obj(obj)
        db.session.commit()
        flash(_("Your changes have been saved"), 'success')
        return render_redirect(obj.url_for(), code=303)
    return render_form(form=form,
                       title="Edit organization profile",
                       cancel_url=obj.url_for())
コード例 #32
0
def board_edit(board):
    form = BoardForm(obj=board)
    if form.validate_on_submit():
        form.populate_obj(board)
        db.session.commit()
        flash(u"Edited board settings.", 'success')
        return render_redirect(url_for('index', subdomain=board.name),
                               code=303)

    return render_form(form=form,
                       title=u"Edit board settings",
                       submit="Save",
                       formid="board_edit",
                       cancel_url=url_for('index', subdomain=board.name),
                       ajax=False)
コード例 #33
0
def sponsor_new(profile, event, form=None):
    if profile.userid not in g.user.user_organizations_owned_ids():
        abort(403)

    form = SponsorForm()
    if form.validate_on_submit():
        sponsor = Sponsor(event=event)
        form.populate_obj(sponsor)
        sponsor.make_name()
        db.session.add(sponsor)
        db.session.commit()
        flash("Sponsor added")
        return render_redirect(event.url_for(), code=303)
    return render_form(form=form, title=u"New Sponsor", submit=u"Save",
        cancel_url=event.url_for(), ajax=False)
コード例 #34
0
    def edit(self):
        form = CampaignActionForm(obj=self.obj)
        if form.validate_on_submit():
            form.populate_obj(self.obj)
            db.session.commit()
            flash(u"Edited campaign action ‘%s’" % self.obj.title,
                  'interactive')
            return redirect(self.obj.parent.url_for(), code=303)

        return render_form(form=form,
                           title=u"Edit campaign action",
                           submit="Save",
                           formid="campaign_action_edit",
                           cancel_url=self.obj.parent.url_for(),
                           ajax=False)
コード例 #35
0
ファイル: profile.py プロジェクト: haseebgit/lastuser
def change_password():
    if g.user.pw_hash is None:
        form = PasswordResetForm()
    else:
        form = PasswordChangeForm()
    if form.validate_on_submit():
        g.user.password = form.password.data
        db.session.commit()
        flash("Your new password has been saved.", category='success')
        return render_redirect(url_for('profile'), code=303)
    return render_form(form=form,
                       title="Change password",
                       formid="changepassword",
                       submit="Change password",
                       ajax=True)
コード例 #36
0
 def new_team(self):
     form = TeamForm()
     if form.validate_on_submit():
         team = Team(organization=self.obj)
         db.session.add(team)
         form.populate_obj(team)
         db.session.commit()
         team_data_changed.send(team,
                                changes=['new'],
                                user=current_auth.user)
         return render_redirect(self.obj.url_for('view'), code=303)
     return render_form(form=form,
                        title=_("Create new team"),
                        formid='new_team',
                        submit=_("Create"))
コード例 #37
0
def campaign_action_new(campaign):
    form = CampaignActionForm()
    if request.method == 'GET':
        form.seq.data = max([a.seq for a in campaign.actions] or [0]) + 1
    if form.validate_on_submit():
        action = CampaignAction(campaign=campaign)
        db.session.add(action)
        form.populate_obj(action)
        action.make_name()
        db.session.commit()
        flash(u"Added campaign action ‘%s’" % action.title, 'interactive')
        return redirect(url_for('campaign_view', campaign=campaign.name), code=303)

    return render_form(form=form, title=u"Add a new campaign action…", submit="Save",
        formid="campaign_action_new", cancel_url=url_for('campaign_view', campaign=campaign.name), ajax=False)
コード例 #38
0
ファイル: profile.py プロジェクト: haseebgit/lastuser
def add_phone():
    form = NewPhoneForm()
    if form.validate_on_submit():
        userphone = UserPhoneClaim(user=g.user, phone=form.phone.data)
        db.session.add(userphone)
        send_phone_verify_code(userphone)
        db.session.commit()
        flash("We sent a verification code to your phone number.", 'success')
        return render_redirect(url_for('verify_phone', number=userphone.phone),
                               code=303)
    return render_form(form=form,
                       title="Add a phone number",
                       formid="phone_add",
                       submit="Add phone",
                       ajax=True)
コード例 #39
0
ファイル: admin.py プロジェクト: biletnam/boxoffice-4
def jsonify_org(data):
    item_collections_list = ItemCollection.query.filter(
        ItemCollection.organization == data['org']).order_by(
            'created_at desc').all()
    html_form = render_form(form=ItemCollectionForm(),
                            title=u"New Item Collection",
                            submit=u"Save",
                            ajax=False,
                            with_chrome=False)
    return jsonify(id=data['org'].id,
                   org_title=data['org'].title,
                   item_collections=[
                       dict(ic.current_access())
                       for ic in item_collections_list
                   ],
                   form=html_form)
コード例 #40
0
ファイル: proposal.py プロジェクト: vishwatejharer/funnel
 def edit_labels(self):
     form = ProposalLabelsAdminForm(model=Proposal,
                                    obj=self.obj,
                                    parent=self.obj.project)
     if form.validate_on_submit():
         form.populate_obj(self.obj)
         db.session.commit()
         flash(_("Labels have been saved for this proposal."), 'info')
         return redirect(self.obj.url_for(), 303)
     else:
         flash(_("Labels could not be saved for this proposal."), 'error')
         return render_form(
             form,
             submit=_("Save changes"),
             title=_("Edit labels for '{}'").format(self.obj.title),
         )
コード例 #41
0
def campaign_action_edit(campaign, action):
    form = CampaignActionForm(obj=action)
    if form.validate_on_submit():
        form.populate_obj(action)
        db.session.commit()
        flash(u"Edited campaign action ‘%s’" % action.title, 'interactive')
        return redirect(url_for('campaign_view', campaign=campaign.name),
                        code=303)

    return render_form(form=form,
                       title=u"Edit campaign action",
                       submit="Save",
                       formid="campaign_action_edit",
                       cancel_url=url_for('campaign_view',
                                          campaign=campaign.name),
                       ajax=False)
コード例 #42
0
ファイル: campaign.py プロジェクト: freshy969/hasjob
    def action_new(self):
        self.form_header = Markup(render_template('campaign_action_edit_header.html.jinja2', campaign=self.obj))
        form = CampaignActionForm()
        if request.method == 'GET':
            form.seq.data = max([a.seq for a in self.obj.actions] or [0]) + 1
        if form.validate_on_submit():
            action = CampaignAction(campaign=self.obj)
            db.session.add(action)
            form.populate_obj(action)
            action.name = suuid()  # Use a random name since it needs to be permanent
            db.session.commit()
            flash(u"Added campaign action ‘%s’" % action.title, 'interactive')
            return redirect(self.obj.url_for(), code=303)

        return render_form(form=form, title=u"Add a new campaign action…", submit="Save",
            formid="campaign_action_new", cancel_url=self.obj.url_for(), ajax=False)
コード例 #43
0
 def edit(self):
     form = TeamForm(obj=self.obj)
     if form.validate_on_submit():
         form.populate_obj(self.obj)
         db.session.commit()
         team_data_changed.send(self.obj,
                                changes=['edit'],
                                user=current_auth.user)
         return render_redirect(self.obj.organization.url_for(), code=303)
     return render_form(
         form=form,
         title=_("Edit team: {title}").format(title=self.obj.title),
         formid='team_edit',
         submit=_("Save"),
         ajax=False,
     )
コード例 #44
0
ファイル: ticket_event.py プロジェクト: vishwatejharer/funnel
 def new_event(self):
     form = TicketEventForm()
     if form.validate_on_submit():
         ticket_event = TicketEvent(project=self.obj)
         form.populate_obj(ticket_event)
         ticket_event.make_name()
         try:
             db.session.add(ticket_event)
             db.session.commit()
         except IntegrityError:
             db.session.rollback()
             flash(_("This event already exists."), 'info')
         return redirect(self.obj.url_for('admin'), code=303)
     return render_form(form=form,
                        title=_("New Event"),
                        submit=_("Add event"))
コード例 #45
0
ファイル: event.py プロジェクト: ultimatecoder/funnel
def new_event(profile, space):
    form = EventForm()
    if form.validate_on_submit():
        event = Event(proposal_space=space)
        form.populate_obj(event)
        event.make_name()
        try:
            db.session.add(event)
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
            flash(_(u"This event already exists."), 'info')
        return redirect(space.url_for('admin'), code=303)
    return render_form(form=form,
                       title=_(u"New Event"),
                       submit=_(u"Add Event"))
コード例 #46
0
ファイル: setup.py プロジェクト: geohacker/kharcha
def budget_new():
    form = BudgetForm()
    if form.validate_on_submit():
        budget = Budget()
        form.populate_obj(budget)
        budget.make_name()
        db.session.add(budget)
        db.session.commit()
        flash("Created new budget '%s'." % budget.title, "success")
        return render_redirect(url_for('budget', name=budget.name), code=303)
    return render_form(form=form,
                       title=u"Create new budget",
                       formid="budget_new",
                       submit=u"Create",
                       cancel_url=url_for('budget_list'),
                       ajax=True)
コード例 #47
0
ファイル: profile.py プロジェクト: vishwatejharer/funnel
 def edit(self):
     form = ProfileForm(obj=self.obj, model=Profile)
     if self.obj.user:
         form.make_for_user()
     if form.validate_on_submit():
         form.populate_obj(self.obj)
         db.session.commit()
         flash(_("Your changes have been saved"), 'info')
         return redirect(self.obj.url_for(), code=303)
     return render_form(
         form=form,
         title=_("Edit profile details"),
         submit=_("Save changes"),
         cancel_url=self.obj.url_for(),
         ajax=False,
     )
コード例 #48
0
 def edit(self):
     form = VenueRoomForm(obj=self.obj)
     if form.validate_on_submit():
         form.populate_obj(self.obj)
         self.obj.make_name(reserved=RESERVED_VENUEROOM)
         db.session.commit()
         flash(_("Saved changes to this room"), 'success')
         return render_redirect(self.obj.venue.project.url_for('venues'),
                                code=303)
     return render_form(
         form=form,
         title=_("Edit room"),
         submit=_("Save"),
         cancel_url=self.obj.venue.project.url_for('venues'),
         ajax=False,
     )
コード例 #49
0
    def edit(self):
        form = CampaignForm(obj=self.obj)
        if form.validate_on_submit():
            form.populate_obj(self.obj)
            db.session.commit()
            flash("Edited campaign settings", 'success')
            return render_redirect(self.obj.url_for(), code=303)

        return render_form(
            form=form,
            title="Edit campaign settings",
            submit="Save",
            formid="campaign_edit",
            cancel_url=self.obj.url_for(),
            ajax=False,
        )
コード例 #50
0
ファイル: org.py プロジェクト: supreethsubbaraya/lastuser
 def edit(self):
     form = OrganizationForm(obj=self.obj)
     form.name.description = current_app.config.get('ORG_NAME_REASON')
     form.title.description = current_app.config.get('ORG_TITLE_REASON')
     if form.validate_on_submit():
         form.populate_obj(self.obj)
         db.session.commit()
         org_data_changed.send(self.obj,
                               changes=['edit'],
                               user=current_auth.user)
         return render_redirect(self.obj.url_for('view'), code=303)
     return render_form(form=form,
                        title=_("Edit organization"),
                        formid='org_edit',
                        submit=_("Save"),
                        ajax=False)
コード例 #51
0
ファイル: setup.py プロジェクト: geohacker/kharcha
def category_edit(name):
    category = Category.query.filter_by(name=name).first_or_404()
    form = CategoryForm(obj=category)
    if form.validate_on_submit():
        form.populate_obj(category)
        category.make_name()
        db.session.commit()
        flash("Edited category '%s'" % category.title, "success")
        return render_redirect(url_for('category', name=category.name),
                               code=303)
    return render_form(form=form,
                       title=u"Edit category",
                       formid='category_edit',
                       submit=u"Save",
                       cancel_url=url_for('category', name=category.name),
                       ajax=True)
コード例 #52
0
def venueroom_new(space, venue):
    form = VenueRoomForm()
    if form.validate_on_submit():
        room = VenueRoom()
        form.populate_obj(room)
        room.venue = venue
        room.make_name(reserved=RESERVED_VENUEROOM)
        db.session.add(room)
        db.session.commit()
        flash(_(u"You have added a room at this venue"), 'success')
        return render_redirect(space.url_for('venues'), code=303)
    return render_form(form=form,
                       title=_("New room"),
                       submit=_("Create"),
                       cancel_url=space.url_for('venues'),
                       ajax=False)
コード例 #53
0
def venue_new(space):
    form = VenueForm()
    if form.validate_on_submit():
        venue = Venue()
        form.populate_obj(venue)
        venue.proposal_space = space
        venue.make_name(reserved=RESERVED_VENUE)
        db.session.add(venue)
        db.session.commit()
        flash(_(u"You have added a new venue to the event"), 'success')
        return render_redirect(space.url_for('venues'), code=303)
    return render_form(form=form,
                       title=_("New venue"),
                       submit=_("Create"),
                       cancel_url=space.url_for('venues'),
                       ajax=False)
コード例 #54
0
ファイル: client.py プロジェクト: gantir/lastuser
def resource_new(client):
    form = ResourceForm()
    form.edit_id = None
    if form.validate_on_submit():
        resource = Resource(client=client)
        form.populate_obj(resource)
        db.session.add(resource)
        db.session.commit()
        flash("Your new resource has been saved", 'success')
        return render_redirect(url_for('.client_info', key=client.key),
                               code=303)
    return render_form(form=form,
                       title="Define a resource",
                       formid="resource_new",
                       submit="Define resource",
                       ajax=True)
コード例 #55
0
def profile_edit():
    form = ProfileForm(obj=g.user)
    form.fullname.description = app.config.get('FULLNAME_REASON')
    form.username.description = app.config.get('USERNAME_REASON')
    form.description.description = app.config.get('BIO_REASON')
    if form.validate_on_submit():
        form.populate_obj(g.user)
        db.session.commit()

        flash("Your profile was successfully edited.", category='success')
        return render_redirect(url_for('profile'), code=303)
    return render_form(form,
                       title="Edit profile",
                       formid="profile_edit",
                       submit="Save changes",
                       ajax=True)
コード例 #56
0
def campaign_new():
    form = CampaignForm()
    if request.method == 'GET' and g.board:
        form.boards.data = [g.board]
    if form.validate_on_submit():
        campaign = Campaign(user=g.user)
        form.populate_obj(campaign)
        campaign.name = suuid()  # Use a random name since it's also used in user action submit forms
        db.session.add(campaign)
        db.session.commit()
        flash(u"Created a campaign", 'success')
        return render_redirect(url_for('campaign_view', campaign=campaign.name), code=303)

    return render_form(form=form, title=u"Create a campaign…", submit="Next",
        message=u"Campaigns appear around the job board and provide a call to action for users",
        formid="campaign_new", cancel_url=url_for('campaign_list'), ajax=False)
コード例 #57
0
    def edit(self, **kwargs):
        if 'edit-filterset' not in g.board.current_permissions:
            abort(403)

        form = FiltersetForm(obj=self.obj)
        if form.validate_on_submit():
            form.populate_obj(self.obj)
            try:
                db.session.commit()
                flash(u"Updated filterset", 'success')
                return render_redirect(self.obj.url_for(), code=303)
            except ValueError:
                db.session.rollback()
                flash(u"There already exists a filterset with the selected criteria", 'interactive')
        return render_form(form=form, title=u"Edit filterset…", submit="Update",
            formid="filterset_edit", ajax=False)
コード例 #58
0
ファイル: org.py プロジェクト: gantir/lastuser
def org_edit(org):
    form = OrganizationForm(obj=org)
    form.name.description = current_app.config.get('ORG_NAME_REASON')
    form.title.description = current_app.config.get('ORG_TITLE_REASON')
    form.description.description = current_app.config.get(
        'ORG_DESCRIPTION_REASON')
    if form.validate_on_submit():
        form.populate_obj(org)
        db.session.commit()
        org_data_changed.send(org, changes=['edit'], user=g.user)
        return render_redirect(url_for('.org_info', name=org.name), code=303)
    return render_form(form=form,
                       title="New Organization",
                       formid="org_edit",
                       submit="Save",
                       ajax=False)
コード例 #59
0
def jsonify_new_item_collection(item_collection_dict):
    ic_form = ItemCollectionForm()
    if request.method == 'GET':
        return jsonify(form_template=render_form(form=ic_form,
            title="New item collection", submit="Create", ajax=False, with_chrome=False))
    if ic_form.validate_on_submit():
        ic = ItemCollection(organization=item_collection_dict['organization'])
        ic_form.populate_obj(ic)
        if not ic.name:
            ic.make_name()
        db.session.add(ic)
        db.session.commit()
        return api_success(result={'item_collection': dict(ic.current_access())},
            doc=_("New item collection created"), status_code=201)
    return api_error(message=_("There was a problem with creating the item collection"),
        errors=ic_form.errors, status_code=400)
コード例 #60
0
ファイル: sponsor.py プロジェクト: raj88iitr/hacknight
def sponsor_edit(profile, event, sponsor):
    if profile.userid not in g.user.user_organizations_owned_ids():
        abort(403)

    else:
        form = SponsorForm(obj=sponsor)
        if form.validate_on_submit():
            form.populate_obj(sponsor)
            sponsor.make_name()
            db.session.commit()
            flash(u"Your changes have been saved", 'success')
            return render_redirect(sponsor.url_for(), code=303)
        return render_form(form=form,
                           title=u"Edit sponsor",
                           submit=u"Save",
                           cancel_url=sponsor.url_for(),
                           ajax=True)