From 27024114045d1babe63bfd0265aa648815ee4ace Mon Sep 17 00:00:00 2001 From: kracekumar Date: Mon, 22 Apr 2013 00:13:45 +0530 Subject: [PATCH 1/6] Added edit choices --- hacknight/forms/event.py | 2 +- hacknight/views/event.py | 13 ++++++++++++- hacknight/views/login.py | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/hacknight/forms/event.py b/hacknight/forms/event.py index a1f7ed8..58ec80f 100644 --- a/hacknight/forms/event.py +++ b/hacknight/forms/event.py @@ -10,7 +10,7 @@ STATUS_CHOICES = [ (EVENT_STATUS.DRAFT, 'Draft'), - (EVENT_STATUS.PUBLISHED, 'Published'), + (EVENT_STATUS.PUBLISHED, 'Public'), (EVENT_STATUS.ACTIVE, 'Active'), (EVENT_STATUS.COMPLETED, 'Completed'), (EVENT_STATUS.CANCELLED, 'Cancelled'), diff --git a/hacknight/views/event.py b/hacknight/views/event.py index f5d87c8..27c966a 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -8,7 +8,7 @@ from coaster.views import load_model, load_models from baseframe.forms import render_redirect, render_form, render_delete_sqla from hacknight import app, mail -from hacknight.models import db, Profile, Event, User, Participant, PARTICIPANT_STATUS +from hacknight.models import db, Profile, Event, User, Participant, PARTICIPANT_STATUS, EVENT_STATUS from hacknight.forms.event import EventForm, ConfirmWithdrawForm, SendEmailForm from hacknight.forms.participant import ParticipantForm from hacknight.views.login import lastuser @@ -23,6 +23,15 @@ def send_email(sender, to, subject, body, html=None): mail.send(msg) +# EDIT form choices +# https://github.com/hasgeek/hacknight/issues/168 +EDIT_FORM_CHOICES = [ + (EVENT_STATUS.DRAFT, 'Draft'), + (EVENT_STATUS.PUBLISHED, 'Public'), + (EVENT_STATUS.CLOSED, 'Closed') +] + + @app.route('//', methods=["GET"]) @load_models( (Profile, {'name': 'profile'}, 'profile'), @@ -85,6 +94,8 @@ def event_edit(profile, event): if not workflow.can_edit(): abort(403) form = EventForm(obj=event) + form.status.choices = EDIT_FORM_CHOICES + form.status.default = event.status if form.validate_on_submit(): form.populate_obj(event) event.make_name() diff --git a/hacknight/views/login.py b/hacknight/views/login.py index 97e3e9f..2cda13d 100644 --- a/hacknight/views/login.py +++ b/hacknight/views/login.py @@ -66,4 +66,3 @@ def lastuser_error(error, error_description=None, error_uri=None): u"Description: %s\n" u"URI: %s" % (error, error_description, error_uri), mimetype="text/plain") - From 09a39927dccc7e6889cd0c6ff9df2ee46206e8e6 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Wed, 24 Apr 2013 19:34:27 +0530 Subject: [PATCH 2/6] Added workflow states --- hacknight/views/event.py | 14 +++++++++----- hacknight/views/workflow.py | 9 +++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/hacknight/views/event.py b/hacknight/views/event.py index 27c966a..a27c751 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -25,11 +25,11 @@ def send_email(sender, to, subject, body, html=None): # EDIT form choices # https://github.com/hasgeek/hacknight/issues/168 -EDIT_FORM_CHOICES = [ - (EVENT_STATUS.DRAFT, 'Draft'), - (EVENT_STATUS.PUBLISHED, 'Public'), - (EVENT_STATUS.CLOSED, 'Closed') -] +EDIT_FORM_CHOICES = { + EVENT_STATUS.DRAFT: [(EVENT_STATUS.DRAFT, 'Draft'), (EVENT_STATUS.PUBLISHED, 'Public')], + EVENT_STATUS.PUBLISHED: [(EVENT_STATUS.PUBLISHED, 'Public'), (EVENT_STATUS.CLOSED, 'Closed')], + EVENT_STATUS.CLOSED: [(EVENT_STATUS.CLOSED, 'Closed'), (EVENT_STATUS.PUBLISHED, 'Public')] +} @app.route('//', methods=["GET"]) @@ -94,6 +94,10 @@ def event_edit(profile, event): if not workflow.can_edit(): abort(403) form = EventForm(obj=event) + try: + form.status.choices = EDIT_FORM_CHOICES[event.status] + except KeyError: + form.status.choices = EDIT_FORM_CHOICES[EVENT_STATUS.DRAFT] form.status.choices = EDIT_FORM_CHOICES form.status.default = event.status if form.validate_on_submit(): diff --git a/hacknight/views/workflow.py b/hacknight/views/workflow.py index 8cd1725..d0629d7 100644 --- a/hacknight/views/workflow.py +++ b/hacknight/views/workflow.py @@ -96,13 +96,14 @@ class EventWorkflow(DocumentWorkflow): cancelled = WorkflowState(EVENT_STATUS.CANCELLED, title=u"Cancelled") rejected = WorkflowState(EVENT_STATUS.REJECTED, title=u"Rejected") withdrawn = WorkflowState(EVENT_STATUS.WITHDRAWN, title=u"Withdrawn") + published = WorkflowState(EVENT_STATUS.PUBLISHED, title="Published") #: States in which an owner can edit - editable = WorkflowStateGroup([draft, active, closed, completed, cancelled, rejected, withdrawn], title=u"Editable") - public = WorkflowStateGroup([active, closed], title=u"Public") + editable = WorkflowStateGroup([draft, published, closed], title=u"Editable") + public = WorkflowStateGroup([published, closed], title=u"Public") openit = WorkflowStateGroup([draft], title=u"Open it") #: States in which a reviewer can view - reviewable = WorkflowStateGroup([draft, active, closed, rejected, completed], + reviewable = WorkflowStateGroup([draft, published], title=u"Reviewable") def permissions(self): @@ -116,7 +117,7 @@ def permissions(self): base_permissions.extend(lastuser.permissions()) return base_permissions - @draft.transition(active, 'owner', title=u"Open", category="primary", + @draft.transition(published, 'owner', title=u"Open", category="primary", description=u"Open the hacknight for registrations.", view="event_open") def openit(self): """ From 12355c98e971eeba62b63b293d35e2905879b016 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Thu, 25 Apr 2013 09:45:52 +0530 Subject: [PATCH 3/6] Added conditional check for create project --- hacknight/views/event.py | 4 ++-- hacknight/views/project.py | 5 ++++- hacknight/views/workflow.py | 9 +++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/hacknight/views/event.py b/hacknight/views/event.py index a27c751..6f9dba9 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -28,7 +28,8 @@ def send_email(sender, to, subject, body, html=None): EDIT_FORM_CHOICES = { EVENT_STATUS.DRAFT: [(EVENT_STATUS.DRAFT, 'Draft'), (EVENT_STATUS.PUBLISHED, 'Public')], EVENT_STATUS.PUBLISHED: [(EVENT_STATUS.PUBLISHED, 'Public'), (EVENT_STATUS.CLOSED, 'Closed')], - EVENT_STATUS.CLOSED: [(EVENT_STATUS.CLOSED, 'Closed'), (EVENT_STATUS.PUBLISHED, 'Public')] + EVENT_STATUS.CLOSED: [(EVENT_STATUS.CLOSED, 'Closed'), (EVENT_STATUS.PUBLISHED, 'Public')], + EVENT_STATUS.ACTIVE: [(EVENT_STATUS.PUBLISHED, 'Public'), (EVENT_STATUS.CLOSED, 'Closed')] } @@ -98,7 +99,6 @@ def event_edit(profile, event): form.status.choices = EDIT_FORM_CHOICES[event.status] except KeyError: form.status.choices = EDIT_FORM_CHOICES[EVENT_STATUS.DRAFT] - form.status.choices = EDIT_FORM_CHOICES form.status.default = event.status if form.validate_on_submit(): form.populate_obj(event) diff --git a/hacknight/views/project.py b/hacknight/views/project.py index e36660c..13830c8 100644 --- a/hacknight/views/project.py +++ b/hacknight/views/project.py @@ -32,7 +32,10 @@ def project_new(profile, event, form=None): abort(403) if participant.status != PARTICIPANT_STATUS.CONFIRMED: abort(403) - + workflow = event.workflow() + if not workflow.create_projects(): + flash("You cannot create project since the hacknight is closed.") + return redirect(event.url_for()) form = ProjectForm() if form.validate_on_submit(): project = Project(event=event, user=g.user) diff --git a/hacknight/views/workflow.py b/hacknight/views/workflow.py index d0629d7..01b472e 100644 --- a/hacknight/views/workflow.py +++ b/hacknight/views/workflow.py @@ -1,9 +1,10 @@ -# -*- coding: utf-8- *- +# -*- coding: utf-8 -*- from flask import g from coaster.docflow import DocumentWorkflow, WorkflowState, WorkflowStateGroup from hacknight.models.participant import Participant, PARTICIPANT_STATUS from hacknight.models.event import Event, EVENT_STATUS +from hacknight.models.project import Project from hacknight.views.login import lastuser @@ -99,9 +100,10 @@ class EventWorkflow(DocumentWorkflow): published = WorkflowState(EVENT_STATUS.PUBLISHED, title="Published") #: States in which an owner can edit - editable = WorkflowStateGroup([draft, published, closed], title=u"Editable") + editable = WorkflowStateGroup([draft, active, published, closed], title=u"Editable") public = WorkflowStateGroup([published, closed], title=u"Public") openit = WorkflowStateGroup([draft], title=u"Open it") + create_projects = WorkflowStateGroup([draft, active, published], title="States in which projects can be created") #: States in which a reviewer can view reviewable = WorkflowStateGroup([draft, published], title=u"Reviewable") @@ -204,4 +206,7 @@ def can_delete(self): """ return 'owner' in self.permissions() and self.editable() + def is_active(self): + return self.create_projects() + EventWorkflow.apply_on(Event) From 8b448fe0fff182f5c8fae87058340eea9442a2ea Mon Sep 17 00:00:00 2001 From: kracekumar Date: Thu, 25 Apr 2013 12:31:43 +0530 Subject: [PATCH 4/6] removed unused project import --- hacknight/views/workflow.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hacknight/views/workflow.py b/hacknight/views/workflow.py index 01b472e..97f679b 100644 --- a/hacknight/views/workflow.py +++ b/hacknight/views/workflow.py @@ -4,7 +4,6 @@ from coaster.docflow import DocumentWorkflow, WorkflowState, WorkflowStateGroup from hacknight.models.participant import Participant, PARTICIPANT_STATUS from hacknight.models.event import Event, EVENT_STATUS -from hacknight.models.project import Project from hacknight.views.login import lastuser From 83bc85933c5b229ac3f484a9fbe9b2fa7e627d19 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Fri, 26 Apr 2013 12:15:28 +0530 Subject: [PATCH 5/6] Change Hacknight state from sidebar --- hacknight/models/event.py | 4 ++- hacknight/templates/event.html | 16 +++++++++++ hacknight/views/event.py | 40 ++++++++++++++------------ hacknight/views/workflow.py | 51 ++++++++++++++++++++-------------- 4 files changed, 72 insertions(+), 39 deletions(-) diff --git a/hacknight/models/event.py b/hacknight/models/event.py index 9dc3c77..4e4e436 100644 --- a/hacknight/models/event.py +++ b/hacknight/models/event.py @@ -93,7 +93,7 @@ def permissions(self, user, inherited=None): perms.add('send-email') return perms - def url_for(self, action='view', _external=False): + def url_for(self, action='view', _external=False, **kwargs): if action == 'view': return url_for('event_view', profile=self.profile.name, event=self.name, _external=_external) elif action == 'edit': @@ -112,3 +112,5 @@ def url_for(self, action='view', _external=False): return url_for('event_export', profile=self.profile.name, event=self.name, _external=_external) elif action == 'send_email': return url_for('event_send_email', profile=self.profile.name, event=self.name, _external=_external) + elif action == 'event_change': + return url_for('event_change', profile=self.profile.name, event=self.name, method_name=kwargs['method_name'], _external=_external) diff --git a/hacknight/templates/event.html b/hacknight/templates/event.html index 2615133..ce3cc61 100644 --- a/hacknight/templates/event.html +++ b/hacknight/templates/event.html @@ -92,6 +92,11 @@

{{ self.title() }}

  • Edit details...
  • Delete event...
  • Email participants...
  • + {% with transitions = workflow.transitions() %} + {% for key in transitions %} +
  • {{ transitions[key]['description'] }}
  • + {% endfor %} + {% endwith %} {% endif -%} {% if event.sponsors %} @@ -206,6 +211,17 @@

    New project...

    map.setView(venue, map.getZoom()); }; {% endif %} + // Add event handler for hacknight event state change + $(".event_change").on('click', function(event){ + event.preventDefault(); + $.ajax({ + url: this.getAttribute('href'), + type: this.getAttribute('data-method'), + success: function(msg) { //reload same page + window.location.reload(true); + } + }); + }); }); diff --git a/hacknight/views/event.py b/hacknight/views/event.py index 6f9dba9..d07c853 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -8,7 +8,7 @@ from coaster.views import load_model, load_models from baseframe.forms import render_redirect, render_form, render_delete_sqla from hacknight import app, mail -from hacknight.models import db, Profile, Event, User, Participant, PARTICIPANT_STATUS, EVENT_STATUS +from hacknight.models import db, Profile, Event, User, Participant, PARTICIPANT_STATUS from hacknight.forms.event import EventForm, ConfirmWithdrawForm, SendEmailForm from hacknight.forms.participant import ParticipantForm from hacknight.views.login import lastuser @@ -23,21 +23,12 @@ def send_email(sender, to, subject, body, html=None): mail.send(msg) -# EDIT form choices -# https://github.com/hasgeek/hacknight/issues/168 -EDIT_FORM_CHOICES = { - EVENT_STATUS.DRAFT: [(EVENT_STATUS.DRAFT, 'Draft'), (EVENT_STATUS.PUBLISHED, 'Public')], - EVENT_STATUS.PUBLISHED: [(EVENT_STATUS.PUBLISHED, 'Public'), (EVENT_STATUS.CLOSED, 'Closed')], - EVENT_STATUS.CLOSED: [(EVENT_STATUS.CLOSED, 'Closed'), (EVENT_STATUS.PUBLISHED, 'Public')], - EVENT_STATUS.ACTIVE: [(EVENT_STATUS.PUBLISHED, 'Public'), (EVENT_STATUS.CLOSED, 'Closed')] -} - - @app.route('//', methods=["GET"]) @load_models( (Profile, {'name': 'profile'}, 'profile'), (Event, {'name': 'event', 'profile': 'profile'}, 'event')) def event_view(profile, event): + workflow = event.workflow() participants = [r[0] for r in db.session.query(Participant, User).filter( Participant.status != PARTICIPANT_STATUS.WITHDRAWN, Participant.event == event).join( (User, Participant.user)).options( @@ -58,7 +49,8 @@ def event_view(profile, event): rest_participants=rest_participants, applied=applied, current_participant=current_participant, - sponsors=event.sponsors) + sponsors=event.sponsors, + workflow=workflow) @app.route('//new', methods=['GET', 'POST']) @@ -95,11 +87,7 @@ def event_edit(profile, event): if not workflow.can_edit(): abort(403) form = EventForm(obj=event) - try: - form.status.choices = EDIT_FORM_CHOICES[event.status] - except KeyError: - form.status.choices = EDIT_FORM_CHOICES[EVENT_STATUS.DRAFT] - form.status.default = event.status + del form.status if form.validate_on_submit(): form.populate_obj(event) event.make_name() @@ -318,3 +306,21 @@ def event_send_email(profile, event): return render_redirect(event.url_for()) return render_form(form=form, title="Send email to participants", submit=u"Send", cancel_url=event.url_for(), ajax=False) + + +@app.route('///change/', methods=['POST']) +@lastuser.requires_login +@load_models( + (Profile, {'name': 'profile'}, 'profile'), + (Event, {'name': 'event', 'profile': 'profile'}, 'event'), permission='edit') +def event_change(profile, event): + if request.is_xhr: + workflow = event.workflow() + method_name = request.view_args['method_name'] + try: + getattr(workflow, method_name)() + flash("Event state changed", "success") + except AttributeError: + flash("Unable to change event state", "error") + db.session.commit() + return render_redirect(event.url_for()) diff --git a/hacknight/views/workflow.py b/hacknight/views/workflow.py index 97f679b..ce916a9 100644 --- a/hacknight/views/workflow.py +++ b/hacknight/views/workflow.py @@ -119,7 +119,7 @@ def permissions(self): return base_permissions @draft.transition(published, 'owner', title=u"Open", category="primary", - description=u"Open the hacknight for registrations.", view="event_open") + description=u"Make hacknight public", view="event_change") def openit(self): """ Open the hacknight. @@ -128,7 +128,7 @@ def openit(self): self.document.status = EVENT_STATUS.PUBLISHED @draft.transition(cancelled, 'owner', title=u"Cancel", category="warning", - description=u"Cancel the hacknight, before opening.", view="event_cancel") + description=u"Cancel hacknight", view="event_change") def cancel_draft(self): """ Cancel the hacknight @@ -136,44 +136,53 @@ def cancel_draft(self): self.document.status = EVENT_STATUS.CANCELLED @active.transition(cancelled, 'owner', title=u"Cancel", category="warning", - description=u"Cancel the hacknight, before opening.", view="event_cancel") + description=u"Cancel hacknight", view="event_change") def cancel_active(self): """ Cancel the hacknight """ self.document.status = EVENT_STATUS.CANCELLED - @draft.transition(rejected, 'owner', title=u"Rejected", category="danger", - description=u"Reject the hacknight proposed by someone else", view="event_reject") - def reject(self): + @active.transition(closed, 'owner', title=u"Close", category="primary", + description=u"Close registrations", view="event_change") + def close(self): """ - Reject the hacknight + Close the hacknight """ - pass + self.document.status = EVENT_STATUS.CLOSED - @draft.transition(withdrawn, 'owner', title=u"Withdraw", category="danger", - description=u"Withdraw the hacknight", view="event_withdraw") - def withdraw(self): + + @published.transition(cancelled, 'owner', title=u"Cancel", category="warning", + description=u"Cancel hacknight", view="event_change") + def deactive(self): """ - Withdraw the hacknight + Cancel the hacknight """ - pass + self.document.status = EVENT_STATUS.CANCELLED - @active.transition(closed, 'owner', title=u"Close", category="primary", - description=u"Close registrations for the hacknight", view="event_close") - def close(self): + @published.transition(closed, 'owner', title=u"Close", category="primary", + description=u"Close registration", view="event_change") + def published_close(self): """ Close the hacknight """ - pass + self.document.status = EVENT_STATUS.CLOSED - @closed.transition(completed, 'owner', title=u"Complete", category="success", - description=u"hacknight completed", view="event_completed") - def complete(self): + @closed.transition(active, 'owner', title=u"Complete", category="success", + description=u"Reopen hacknight", view="event_change") + def reopen(self): """ Hacknight is now completed. """ - pass + self.document.status = EVENT_STATUS.ACTIVE + + @cancelled.transition(active, 'owner', title=u"Complete", category="success", + description=u"Reopen hacknight", view="event_change") + def cancel_reopen(self): + """ + Hacknight is now completed. + """ + self.document.status = EVENT_STATUS.ACTIVE def is_public(self): """ From 2259df6be8a61fc6f37ff329fcfd341952f4c2c6 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sun, 19 May 2013 21:17:49 +0530 Subject: [PATCH 6/6] removed unwanted states --- hacknight/forms/event.py | 15 +------- hacknight/models/event.py | 12 ++---- hacknight/templates/event.html | 14 +++---- hacknight/views/event.py | 1 - hacknight/views/index.py | 4 +- hacknight/views/project.py | 2 +- hacknight/views/workflow.py | 70 ++++++++++------------------------ 7 files changed, 34 insertions(+), 84 deletions(-) diff --git a/hacknight/forms/event.py b/hacknight/forms/event.py index 0228956..149ece8 100644 --- a/hacknight/forms/event.py +++ b/hacknight/forms/event.py @@ -3,23 +3,11 @@ from flask import Markup import flask.ext.wtf as wtf from baseframe.forms import Form, RichTextField, DateTimeField, ValidName, AvailableName -from hacknight.models import Venue, EVENT_STATUS +from hacknight.models import Venue __all__ = ['EventForm', 'ConfirmWithdrawForm', 'SendEmailForm'] -STATUS_CHOICES = [ - (EVENT_STATUS.DRAFT, 'Draft'), - (EVENT_STATUS.PUBLISHED, 'Public'), - (EVENT_STATUS.ACTIVE, 'Active'), - (EVENT_STATUS.COMPLETED, 'Completed'), - (EVENT_STATUS.CANCELLED, 'Cancelled'), - (EVENT_STATUS.CLOSED, 'Closed'), - (EVENT_STATUS.REJECTED, 'Rejected'), - (EVENT_STATUS.WITHDRAWN, 'Withdrawn') -] - - class EventForm(Form): title = wtf.TextField("Title", description="Name of the Event", validators=[wtf.Required(), wtf.NoneOf(values=["new"]), wtf.validators.length(max=250)]) name = wtf.TextField("URL name", validators=[wtf.Optional(), ValidName(), @@ -39,7 +27,6 @@ class EventForm(Form): ticket_price = wtf.TextField("Ticket price", description="Entry fee, if any, to be paid at the venue", validators=[wtf.validators.length(max=250)]) total_participants = wtf.IntegerField("Venue capacity", description="The number of people this venue can accommodate. Registrations will be closed after that. Use 0 to indicate unlimited capacity", default=50, validators=[wtf.Required()]) website = wtf.html5.URLField("Website", description="Related Website (Optional)", validators=[wtf.Optional(), wtf.validators.length(max=250), wtf.URL()]) - status = wtf.SelectField("Event status", description="Current status of this hacknight", coerce=int, choices=STATUS_CHOICES) def validate_end_datetime(self, field): if field.data < self.start_datetime.data: diff --git a/hacknight/models/event.py b/hacknight/models/event.py index 8205420..d986ae4 100644 --- a/hacknight/models/event.py +++ b/hacknight/models/event.py @@ -24,13 +24,8 @@ class PROFILE_TYPE: class EVENT_STATUS: DRAFT = 0 - PUBLISHED = 1 - ACTIVE = 2 - COMPLETED = 3 - CANCELLED = 4 - CLOSED = 5 - REJECTED = 6 - WITHDRAWN = 7 + PUBLIC = 1 + CLOSED = 2 class Profile(BaseNameMixin, db.Model): @@ -92,8 +87,7 @@ def confirmed_participant_is(self, user): def permissions(self, user, inherited=None): perms = super(Event, self).permissions(user, inherited) - if user is not None and user.userid == self.profile.userid or self.status in [EVENT_STATUS.PUBLISHED, - EVENT_STATUS.ACTIVE, EVENT_STATUS.COMPLETED, EVENT_STATUS.CANCELLED, + if user is not None and user.userid == self.profile.userid or self.status in [EVENT_STATUS.PUBLIC, EVENT_STATUS.CLOSED]: perms.add('view') if user is not None and self.profile.userid in user.user_organizations_owned_ids(): diff --git a/hacknight/templates/event.html b/hacknight/templates/event.html index 2189e02..bc5095a 100644 --- a/hacknight/templates/event.html +++ b/hacknight/templates/event.html @@ -91,15 +91,15 @@

    {{ self.title() }}

    {% endif %} {%- if event.owner_is(g.user) %} -
  • Manage event
  • -
  • Export participants list
  • -
  • Edit details...
  • -
  • Delete event...
  • -
  • Email participants...
  • -
  • Email template...
  • +
  • Manage event
  • +
  • Export participants list
  • +
  • Edit details...
  • +
  • Delete event...
  • +
  • Email participants...
  • +
  • Email template...
  • {% with transitions = workflow.transitions() %} {% for key in transitions %} -
  • {{ transitions[key]['description'] }}
  • +
  • {{ transitions[key]['description'] }}
  • {% endfor %} {% endwith %} {% endif -%} diff --git a/hacknight/views/event.py b/hacknight/views/event.py index aa29884..baa4823 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -97,7 +97,6 @@ def event_edit(profile, event): if not workflow.can_edit(): abort(403) form = EventForm(obj=event) - del form.status if form.validate_on_submit(): old_name = event.name form.populate_obj(event) diff --git a/hacknight/views/index.py b/hacknight/views/index.py index 38ae4b1..7b7fd83 100644 --- a/hacknight/views/index.py +++ b/hacknight/views/index.py @@ -10,8 +10,8 @@ @app.route('/') def index(): # TODO: Filter events by status - upcoming_events = Event.query.filter(Event.end_datetime > datetime.utcnow(), Event.status != EVENT_STATUS.DRAFT, Event.status != EVENT_STATUS.CANCELLED).order_by(Event.start_datetime.asc()).all() - past_events = Event.query.filter(Event.end_datetime < datetime.utcnow(), Event.status != EVENT_STATUS.DRAFT, Event.status != EVENT_STATUS.CANCELLED).order_by(Event.end_datetime.desc()).all() + upcoming_events = Event.query.filter(Event.end_datetime > datetime.utcnow(), Event.status != EVENT_STATUS.DRAFT).order_by(Event.start_datetime.asc()).all() + past_events = Event.query.filter(Event.end_datetime < datetime.utcnow(), Event.status != EVENT_STATUS.DRAFT).order_by(Event.end_datetime.desc()).all() return render_template('index.html', upcoming_events=upcoming_events, past_events=past_events) diff --git a/hacknight/views/project.py b/hacknight/views/project.py index 13830c8..3c50509 100644 --- a/hacknight/views/project.py +++ b/hacknight/views/project.py @@ -34,7 +34,7 @@ def project_new(profile, event, form=None): abort(403) workflow = event.workflow() if not workflow.create_projects(): - flash("You cannot create project since the hacknight is closed.") + flash("You cannot create projects since the hacknight is closed.") return redirect(event.url_for()) form = ProjectForm() if form.validate_on_submit(): diff --git a/hacknight/views/workflow.py b/hacknight/views/workflow.py index 011326a..47da0f1 100644 --- a/hacknight/views/workflow.py +++ b/hacknight/views/workflow.py @@ -90,24 +90,19 @@ class EventWorkflow(DocumentWorkflow): state_attr = 'status' draft = WorkflowState(EVENT_STATUS.DRAFT, title=u"Draft") - active = WorkflowState(EVENT_STATUS.ACTIVE, title=u"Active") closed = WorkflowState(EVENT_STATUS.CLOSED, title=u"Closed") - completed = WorkflowState(EVENT_STATUS.COMPLETED, title=u"Completed") - cancelled = WorkflowState(EVENT_STATUS.CANCELLED, title=u"Cancelled") - rejected = WorkflowState(EVENT_STATUS.REJECTED, title=u"Rejected") - withdrawn = WorkflowState(EVENT_STATUS.WITHDRAWN, title=u"Withdrawn") - published = WorkflowState(EVENT_STATUS.PUBLISHED, title="Published") + public = WorkflowState(EVENT_STATUS.PUBLIC, title=u"Public") #: States in which an owner can edit - editable = WorkflowStateGroup([draft, active, published, closed], title=u"Editable") - public = WorkflowStateGroup([published, closed], title=u"Public") - appliable = WorkflowStateGroup([active, published], title="User can apply for an event") + editable = WorkflowStateGroup([draft, public, closed], title=u"Editable") + public_states = WorkflowStateGroup([public, closed], title=u"Public") + appliable = WorkflowStateGroup([public], title="User can apply for an event") openit = WorkflowStateGroup([draft], title=u"Open it") - create_projects = WorkflowStateGroup([draft, active, published], title="States in which projects can be created") + create_projects = WorkflowStateGroup([draft, public], title="States in which projects can be created") #: States in which a reviewer can view - reviewable = WorkflowStateGroup([draft, published], + reviewable = WorkflowStateGroup([draft, public], title=u"Reviewable") def permissions(self): @@ -121,83 +116,58 @@ def permissions(self): base_permissions.extend(lastuser.permissions()) return base_permissions - @draft.transition(published, 'owner', title=u"Open", category="primary", + @draft.transition(public, 'owner', title=u"Open", category="primary", description=u"Make hacknight public", view="event_change") def openit(self): """ Open the hacknight. """ - if not self.document.status == EVENT_STATUS.PUBLISHED: - self.document.status = EVENT_STATUS.PUBLISHED + if not self.document.status == EVENT_STATUS.PUBLIC: + self.document.status = EVENT_STATUS.PUBLIC - @draft.transition(cancelled, 'owner', title=u"Cancel", category="warning", + @draft.transition(closed, 'owner', title=u"Cancel", category="warning", description=u"Cancel hacknight", view="event_change") def cancel_draft(self): """ Cancel the hacknight """ - self.document.status = EVENT_STATUS.CANCELLED - - @active.transition(cancelled, 'owner', title=u"Cancel", category="warning", - description=u"Cancel hacknight", view="event_change") - def cancel_active(self): - """ - Cancel the hacknight - """ - self.document.status = EVENT_STATUS.CANCELLED - - @active.transition(closed, 'owner', title=u"Close", category="primary", - description=u"Close registrations", view="event_change") - def close(self): - """ - Close the hacknight - """ self.document.status = EVENT_STATUS.CLOSED - - @published.transition(cancelled, 'owner', title=u"Cancel", category="warning", + @public.transition(closed, 'owner', title=u"Cancel", category="warning", description=u"Cancel hacknight", view="event_change") - def deactive(self): + def cancel_public(self): """ Cancel the hacknight """ - self.document.status = EVENT_STATUS.CANCELLED + self.document.status = EVENT_STATUS.CLOSED - @published.transition(closed, 'owner', title=u"Close", category="primary", - description=u"Close registration", view="event_change") - def published_close(self): + @public.transition(closed, 'owner', title=u"Close", category="primary", + description=u"Close Hacknight", view="event_change") + def close(self): """ Close the hacknight """ self.document.status = EVENT_STATUS.CLOSED - @closed.transition(active, 'owner', title=u"Complete", category="success", + @closed.transition(public, 'owner', title=u"Complete", category="success", description=u"Reopen hacknight", view="event_change") def reopen(self): """ Hacknight is now completed. """ - self.document.status = EVENT_STATUS.ACTIVE - - @cancelled.transition(active, 'owner', title=u"Complete", category="success", - description=u"Reopen hacknight", view="event_change") - def cancel_reopen(self): - """ - Hacknight is now completed. - """ - self.document.status = EVENT_STATUS.ACTIVE + self.document.status = EVENT_STATUS.PUBLIC def is_public(self): """ Is the hacknight public? """ - return self.public() + return self.public_states() def can_view(self): """ Can the current user view this? """ - return self.public() or 'owner' in self.permissions() + return self.public_states() or 'owner' in self.permissions() def can_edit(self): """