Skip to content
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

Remove CalendarSource and external events #1593

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 1 addition & 84 deletions apps/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,20 @@

from flask_login import current_user

from wtforms.validators import Optional, DataRequired, URL
from wtforms.validators import Optional, DataRequired
from wtforms import (
SubmitField,
BooleanField,
HiddenField,
StringField,
FieldList,
FormField,
SelectField,
IntegerField,
)
import logging_tree

from main import db
from models.payment import Payment, BankAccount, BankPayment, BankTransaction
from models.purchase import Purchase
from models.ical import CalendarSource
from models.feature_flag import FeatureFlag, DB_FEATURE_FLAGS, refresh_flags
from models.site_state import SiteState, VALID_STATES, refresh_states, get_states
from models.scheduled_task import tasks, ScheduledTaskResult
Expand Down Expand Up @@ -278,86 +275,6 @@ def payment_config_verify():
)


@admin.route("/schedule-feeds")
def schedule_feeds():
feeds = CalendarSource.query.all()
return render_template("admin/schedule-feeds.html", feeds=feeds)


class ScheduleForm(Form):
feed_name = StringField("Feed Name", [DataRequired()])
url = StringField("URL", [DataRequired(), URL()])
enabled = BooleanField("Feed Enabled")
location = SelectField("Location")
published = BooleanField("Publish events from this feed")
priority = IntegerField("Priority", [Optional()])
preview = SubmitField("Preview")
submit = SubmitField("Save")
delete = SubmitField("Delete")

def update_feed(self, feed):
feed.name = self.feed_name.data
feed.url = self.url.data
feed.enabled = self.enabled.data
feed.published = self.published.data
feed.priority = self.priority.data

def init_from_feed(self, feed):
self.feed_name.data = feed.name
self.url.data = feed.url
self.enabled.data = feed.enabled
self.published.data = feed.published
self.priority.data = feed.priority

if feed.mapobj:
self.location.data = str(feed.mapobj.id)
else:
self.location.data = ""


@admin.route("/schedule-feeds/<int:feed_id>", methods=["GET", "POST"])
def schedule_feed(feed_id):
feed = CalendarSource.query.get_or_404(feed_id)
form = ScheduleForm()

form.location.choices = []

if form.validate_on_submit():
if form.delete.data:
for event in feed.events:
db.session.delete(event)
db.session.delete(feed)
db.session.commit()
flash("Feed deleted")
return redirect(url_for(".schedule_feeds", feed_id=feed_id))

form.update_feed(feed)
db.session.commit()
msg = "Updated feed %s" % feed.name
flash(msg)
app.logger.info(msg)
return redirect(url_for(".schedule_feed", feed_id=feed_id))

form.init_from_feed(feed)
return render_template("admin/edit-feed.html", feed=feed, form=form)


@admin.route("/schedule-feeds/new", methods=["GET", "POST"])
def new_feed():
form = ScheduleForm()

if form.validate_on_submit():
feed = CalendarSource("")
form.update_feed(feed)
db.session.add(feed)
db.session.commit()
msg = "Created feed %s" % feed.name
flash(msg)
app.logger.info(msg)
return redirect(url_for(".schedule_feed", feed_id=feed.id))
return render_template("admin/edit-feed.html", form=form)


@admin.route("/scheduled-tasks")
def scheduled_tasks():
data = []
Expand Down
36 changes: 0 additions & 36 deletions apps/api/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from . import api
from main import db
from models.cfp import Proposal
from models.ical import CalendarEvent
from models.admin_message import AdminMessage
from models.event_tickets import EventTicket

Expand Down Expand Up @@ -101,40 +100,6 @@ def put(self, proposal_id):
return {"is_favourite": new_state}


class FavouriteExternal(Resource):
def get(self, event_id):
if not current_user.is_authenticated:
abort(401)

event = CalendarEvent.query.get_or_404(event_id)
current_state = event in current_user.calendar_favourites

return {"is_favourite": current_state}

def put(self, event_id):
"""Put with no data to toggle"""
if not current_user.is_authenticated:
abort(401)

event = CalendarEvent.query.get_or_404(event_id)
current_state = event in current_user.calendar_favourites

data = request.get_json()
if data.get("state") is not None:
new_state = bool(data["state"])
else:
new_state = not current_state

if new_state and not current_state:
current_user.calendar_favourites.append(event)
elif current_state and not new_state:
current_user.calendar_favourites.remove(event)

db.session.commit()

return {"is_favourite": new_state}


class UpdateLotteryPreferences(Resource):
def post(self, proposal_type):
if proposal_type not in ["workshop", "youthworkshop"]:
Expand Down Expand Up @@ -183,6 +148,5 @@ def get(self):

api.add_resource(ProposalResource, "/proposal/<int:proposal_id>")
api.add_resource(FavouriteProposal, "/proposal/<int:proposal_id>/favourite")
api.add_resource(FavouriteExternal, "/external/<int:event_id>/favourite")
api.add_resource(ScheduleMessage, "/schedule_messages")
api.add_resource(UpdateLotteryPreferences, "/schedule/tickets/<proposal_type>/preferences")
3 changes: 1 addition & 2 deletions apps/schedule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ def feed_redirect(fmt):

from . import base # noqa
from . import feeds # noqa
from . import external # noqa
from . import attendee_content # noqa
from . import tasks # noqa

63 changes: 20 additions & 43 deletions apps/schedule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from main import db
from models import event_year
from models.cfp import Proposal, Venue
from models.ical import CalendarSource, CalendarEvent
from models.user import generate_api_token
from models.admin_message import AdminMessage
from models.event_tickets import EventTicket
Expand Down Expand Up @@ -87,10 +86,8 @@ def line_up():
# (Because we don't want a bias in starring)
random.Random(current_user.get_id()).shuffle(proposals)

externals = CalendarSource.get_enabled_events()

return render_template(
"schedule/line-up.html", proposals=proposals, externals=externals
"schedule/line-up.html", proposals=proposals,
)


Expand All @@ -101,30 +98,20 @@ def add_favourite():

event_id = int(request.form["fave"])
event_type = request.form["event_type"]
if event_type == "proposal":
proposal = Proposal.query.get_or_404(event_id)
if proposal in current_user.favourites:
current_user.favourites.remove(proposal)
else:
current_user.favourites.append(proposal)

db.session.commit()
return redirect(
url_for(".main_year", year=event_year())
+ "#proposal-{}".format(proposal.id)
)
if event_type != "proposal":
abort(400)

proposal = Proposal.query.get_or_404(event_id)
if proposal in current_user.favourites:
current_user.favourites.remove(proposal)
else:
event = CalendarEvent.query.get_or_404(event_id)
if event in current_user.calendar_favourites:
current_user.calendar_favourites.remove(event)
else:
current_user.calendar_favourites.append(event)
current_user.favourites.append(proposal)

db.session.commit()
return redirect(
url_for(".main_year", year=event_year()) + "#event-{}".format(event.id)
)
db.session.commit()
return redirect(
url_for(".main_year", year=event_year())
+ "#proposal-{}".format(proposal.id)
)


@schedule.route("/favourites", methods=["GET", "POST"])
Expand All @@ -133,38 +120,28 @@ def favourites():
if (request.method == "POST") and current_user.is_authenticated:
event_id = int(request.form["fave"])
event_type = request.form["event_type"]
if event_type == "proposal":
proposal = Proposal.query.get_or_404(event_id)
if proposal in current_user.favourites:
current_user.favourites.remove(proposal)
else:
current_user.favourites.append(proposal)

db.session.commit()
return redirect(url_for(".favourites") + "#proposal-{}".format(proposal.id))
if event_type != "proposal":
abort(400)

proposal = Proposal.query.get_or_404(event_id)
if proposal in current_user.favourites:
current_user.favourites.remove(proposal)
else:
event = CalendarEvent.query.get_or_404(event_id)
if event in current_user.calendar_favourites:
current_user.calendar_favourites.remove(event)
else:
current_user.calendar_favourites.append(event)
current_user.favourites.append(proposal)

db.session.commit()
return redirect(url_for(".favourites") + "#event-{}".format(event.id))
db.session.commit()
return redirect(url_for(".favourites") + "#proposal-{}".format(proposal.id))

if current_user.is_anonymous:
return redirect(url_for("users.login", next=url_for(".favourites")))

proposals = [p for p in current_user.favourites if not p.hide_from_schedule]
externals = current_user.calendar_favourites

token = generate_api_token(app.config["SECRET_KEY"], current_user.id)

return render_template(
"schedule/favourites.html",
proposals=proposals,
externals=externals,
token=token,
)

Expand Down
50 changes: 3 additions & 47 deletions apps/schedule/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from models import event_year
from models.cfp import Proposal, Venue
from models.ical import CalendarSource

from main import external_url
from . import event_tz
Expand Down Expand Up @@ -59,33 +58,6 @@ def _get_proposal_dict(proposal: Proposal, favourites_ids):
return res


def _get_ical_dict(event, favourites_ids):
res = {
"id": -event.id,
"start_date": event_tz.localize(event.start_dt),
"end_date": event_tz.localize(event.end_dt),
"venue": event.location or "(Unknown)",
"latlon": event.latlon,
"map_link": event.map_link,
"title": event.summary,
"speaker": "",
"user_id": None,
"description": event.description,
"type": "talk",
"may_record": False,
"is_fave": event.id in favourites_ids,
"source": "external",
"link": external_url(
".item_external", year=event_year(), slug=event.slug, event_id=event.id
),
}
if event.type in ["workshop", "youthworkshop"]:
res["cost"] = event.display_cost
res["equipment"] = event.display_participant_equipment
res["age_range"] = event.display_age_range
return res


def _filter_obj_to_dict(filter_obj):
"""Request.args uses a MulitDict this lets us pass filter_obj as plain dicts
and have everything work as expected.
Expand All @@ -103,10 +75,9 @@ def _get_scheduled_proposals(filter_obj={}, override_user=None):
user = current_user

if user.is_anonymous:
proposal_favourites = external_favourites = []
proposal_favourites = []
else:
proposal_favourites = [f.id for f in user.favourites]
external_favourites = [f.id for f in user.calendar_favourites]

schedule = Proposal.query.filter(
Proposal.is_accepted,
Expand All @@ -118,14 +89,6 @@ def _get_scheduled_proposals(filter_obj={}, override_user=None):

schedule = [_get_proposal_dict(p, proposal_favourites) for p in schedule]

ical_sources = CalendarSource.query.filter_by(enabled=True, published=True)

for source in ical_sources:
for e in source.events:
d = _get_ical_dict(e, external_favourites)
d["venue"] = source.mapobj.name
schedule.append(d)

if "is_favourite" in filter_obj and filter_obj["is_favourite"]:
schedule = [s for s in schedule if s.get("is_fave", False)]

Expand Down Expand Up @@ -171,16 +134,9 @@ def _get_priority_sorted_venues(venues_to_allow):
main_venues = Venue.query.filter().all()
main_venue_names = [(v.name, "main", v.priority) for v in main_venues]

ical_sources = CalendarSource.query.filter_by(enabled=True, published=True)
ical_source_names = [
(v.mapobj.name, "ical", v.priority)
for v in ical_sources
if v.mapobj and v.events
]

res = []
seen_names = []
for venue in main_venue_names + ical_source_names:
for venue in main_venue_names:
name = venue[0]
if name not in seen_names and name in venues_to_allow:
seen_names.append(name)
Expand All @@ -193,5 +149,5 @@ def _get_priority_sorted_venues(venues_to_allow):
}
)

res = sorted(res, key=lambda v: (v["source"] != "ical", v["order"]), reverse=True)
res = sorted(res, key=lambda v: v["order"], reverse=True)
return res
Loading