-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new and edit for organization #222
Open
shreyas-satish
wants to merge
5
commits into
main
Choose a base branch
from
orgview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
edba52b
added new and edit for organization
shreyas-satish 66653a8
rm print
shreyas-satish b01d0f8
fixed email validation and access_token generation
shreyas-satish e4313fa
no longer checking for request method inside org form filter
3cbc222
fixed conflict
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from boxoffice.models import db, Organization | ||
from baseframe.forms.sqlalchemy import QuerySelectField | ||
import baseframe.forms as forms | ||
from coaster.utils import buid | ||
from baseframe import __ | ||
from .utils import validate_json, format_json | ||
|
||
__all__ = ['OrgForm', 'NewOrgForm'] | ||
|
||
|
||
def get_default_details(): | ||
return { | ||
u'access_token': buid(), | ||
u'address': u'', | ||
u'cin': u'', | ||
u'logo': u'', | ||
u'pan': u'', | ||
u'refund_policy': u'', | ||
u'support_email': u'', | ||
u'ticket_faq': u'', | ||
u'website': u'' | ||
} | ||
|
||
|
||
class OrgForm(forms.Form): | ||
contact_email = forms.EmailField(__("Contact email"), | ||
validators=[ | ||
forms.validators.DataRequired(__("We need a valid email address")), | ||
forms.validators.Length(min=5, max=80, message=__("%%(max)d characters maximum")), | ||
forms.validators.ValidEmail(__("This does not appear to be a valid email address"))], | ||
filters=[forms.filters.strip()]) | ||
details = forms.TextAreaField(__("Details"), filters=[format_json], | ||
validators=[validate_json], default=get_default_details) | ||
invoicer = QuerySelectField(__("Parent organization"), get_label='title', | ||
validators=[forms.validators.DataRequired(__("Please select a parent organization"))]) | ||
|
||
def set_queries(self): | ||
self.invoicer.query = Organization.query.filter( | ||
Organization.invoicer == None).options(db.load_only('id', 'title')) | ||
|
||
|
||
class NewOrgForm(OrgForm): | ||
organization = forms.RadioField(u"Organization", validators=[forms.validators.DataRequired("Select an organization")], | ||
description=u"Select the organization you’d like to setup Boxoffice for") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import json | ||
import six | ||
import baseframe.forms as forms | ||
from baseframe import __ | ||
|
||
|
||
def validate_json(form, field): | ||
try: | ||
json.loads(field.data) | ||
except ValueError: | ||
raise forms.validators.StopValidation(__("Invalid JSON")) | ||
|
||
|
||
def format_json(data): | ||
# `json.loads` doesn't raise an exception for "null" | ||
# so assign a default value of `{}` | ||
if not data or data == 'null': | ||
data = {} | ||
elif isinstance(data, six.string_types): | ||
# This happens when putting JSON data from the form into the database | ||
data = json.loads(data) | ||
return json.dumps(data, indent=4, sort_keys=True) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
boxoffice/static/build/main_invoice.14875c7f9092817d91d9.js
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
boxoffice/static/build/main_invoice.bfd69cdb099ad90caf9d.js
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"assets":{"main_order":"main_order.bfd69cdb099ad90caf9d.js","main_invoice":"main_invoice.bfd69cdb099ad90caf9d.js","main_admin":"main_admin.bfd69cdb099ad90caf9d.js"}} | ||
{"assets":{"main_order":"main_order.14875c7f9092817d91d9.js","main_invoice":"main_invoice.14875c7f9092817d91d9.js","main_admin":"main_admin.14875c7f9092817d91d9.js"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import admin, item_collection, order, participant, login, admin_item_collection, admin_order, admin_discount, admin_report, admin_item, admin_category | ||
from . import admin, org, item_collection, order, participant, login, admin_item_collection, admin_order, admin_discount, admin_report, admin_item, admin_category |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from flask import g, Markup, request, flash, url_for, redirect | ||
from coaster.views import load_models | ||
from baseframe import _ | ||
from baseframe.forms import render_message, render_redirect, render_form | ||
from ..models import db, Organization | ||
from ..forms import OrgForm, NewOrgForm | ||
from .. import app, lastuser | ||
|
||
|
||
@lastuser.requires_permission('siteadmin') | ||
@lastuser.requires_login | ||
@app.route('/admin/o/new', methods=['GET', 'POST']) | ||
def new_org(): | ||
# Step 1: Get a list of organizations this user owns | ||
existing = Organization.query.filter(Organization.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_orgs = [] | ||
for user_org in g.user.organizations_owned(): | ||
if user_org['userid'] not in existing_ids: | ||
new_orgs.append((user_org['userid'], user_org['title'])) | ||
if not new_orgs: | ||
return render_message( | ||
title=_(u"No organizations found"), | ||
message=Markup(_(u"You do not have any organizations that are not setup on Boxoffice. " | ||
u'Would you like to <a href="{link}">create a new organization</a>?').format( | ||
link=lastuser.endpoint_url('/organizations/new')))) | ||
eligible_orgs = [] | ||
for orgid, title in new_orgs: | ||
eligible_orgs.append((orgid, title)) | ||
if not eligible_orgs: | ||
return render_message( | ||
title=_(u"No organizations available"), | ||
message=_(u"To setup Boxoffice for an organization, you must be the owner of the organization.")) | ||
|
||
# Step 3: Ask user to select organization | ||
form = NewOrgForm() | ||
form.organization.choices = eligible_orgs | ||
if request.method == 'GET': | ||
form.organization.data = new_orgs[0][0] | ||
if form.validate_on_submit(): | ||
# Step 4: Make a profile | ||
user_org = [user_org for user_org in g.user.organizations_owned() if user_org['userid'] == form.organization.data][0] | ||
organization = Organization(name=user_org['name'], title=user_org['title'], userid=user_org['userid']) | ||
form.populate_obj(organization) | ||
db.session.add(organization) | ||
db.session.commit() | ||
flash(_(u"Created an organization for {org}").format(org=organization.title), "success") | ||
return redirect(url_for('org', org=organization.name), code=303) | ||
return render_form( | ||
form=form, | ||
title=_(u"Setup Boxoffice for your organization..."), | ||
submit="Next", | ||
formid="org_new", | ||
cancel_url=url_for('index'), | ||
ajax=False) | ||
|
||
|
||
@app.route('/admin/o/<name>/edit', methods=['GET', 'POST']) | ||
@load_models( | ||
(Organization, {'name': 'name'}, 'org'), | ||
permission='org_admin') | ||
def edit_org(org): | ||
form = OrgForm(obj=org) | ||
if form.validate_on_submit(): | ||
form.populate_obj(org) | ||
db.session.commit() | ||
flash(_("Your changes have been saved"), 'info') | ||
return redirect(url_for('org', org=org.name), code=303) | ||
return render_form( | ||
form=form, | ||
title=_("Edit organization settings"), | ||
submit=_("Save changes"), | ||
cancel_url='/admin/o/{{org}}'.format(org=org.name), | ||
ajax=False) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the logic used in Funnel's
/new
handler. This code looks fragile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's mostly borrowed from there. https://github.com/hasgeek/funnel/blob/master/funnel/views/profile.py#L34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, then that needs to be tossed as well. We can live with this for now, knowing that both places will need to be changed after hasgeek/lastuser#232.