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

Fixes "Implement on/off buttons for Include, Required and Public " #86

Open
wants to merge 4 commits into
base: development
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
14 changes: 11 additions & 3 deletions src/pretalx/orga/forms/cfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,24 @@ def __init__(self, *args, obj, **kwargs):
self.fields[field_name].widget.attrs["placeholder"] = ""
for attribute in self.request_require_fields:
field_name = f"cfp_ask_{attribute}"
visibility = obj.cfp.fields.get(attribute, default_fields()[attribute])["visibility"]
if visibility == "optional":
css_class = "btn btn-outline-dark btn-sm"
elif visibility == "required":
css_class = "btn btn-outline-success btn-sm"
else:
css_class = "btn btn-outline-danger btn-sm"
self.fields[field_name] = forms.ChoiceField(
required=True,
initial=obj.cfp.fields.get(attribute, default_fields()[attribute])[
"visibility"
],
choices=[
("do_not_ask", _("Do not ask")),
("optional", _("Ask, but do not require input")),
("required", _("Ask and require input")),
("do_not_ask", _("Not Active")),
("optional", _("Optional")),
("required", _("Required")),
],
widget=forms.Select(attrs={'class': css_class}),
)
if not obj.is_multilingual:
self.fields.pop("cfp_ask_content_locale", None)
Expand Down
64 changes: 53 additions & 11 deletions src/pretalx/orga/templates/orga/cfp/question_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
<tr>
<th>{% translate "Question" %}</th>
<th>{% translate "Target" %}</th>
<th class="text-center">{% translate "required" %}</th>
<th class="text-center">{% translate "active" %}</th>
<th class="numeric">{% translate "Answers" %}</th>
<th class="text-center">{% translate "Required" %}</th>
<th class="text-center">{% translate "Active" %}</th>
<th class="text-center">{% translate "Public" %}</th>
<th class="numeric text-center">{% translate "Answers" %}</th>
<th></th>
</tr>
</thead>
Expand All @@ -47,17 +48,58 @@
{{ question.get_target_display }}
</td>
<td class="text-center">
<i class="fa fa-{{ question.required|yesno:'check-circle text-success,times-circle text-danger' }}">
</i>
{% if question.question_required == "require after" or question.freeze_after%}
<i class="fa fa-clock-o" title="{% translate "This question’s availability depends on a deadline." %}"> </i>
{% endif %}
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<a href="{{ question.urls.required }}"
{% if question.question_required == "required" %}
class="btn btn-sm btn-outline-primary"
title="{% translate "Always Required" %}"
{% elif question.question_required == "optional" %}
class="btn btn-sm btn-outline-secondary"
title="{% translate "Always Optional" %}"
{% else %}
class="btn btn-sm btn-outline-danger"
title="{% translate "Required After A Deadline" %}"
{% endif %}
>
{% if question.question_required == "required" %}
Required
{% elif question.question_required == "optional" %}
Optional
{% else %}
Deadline
{% endif %}
</a>
</div>
</td>
<td class="text-center">
<i class="fa fa-{{ question.active|yesno:'check-circle text-success,times-circle text-danger' }}">
</i>
<a href="{{ question.urls.active }}" >
{% if question.active %}
<i class="fa fa-toggle-on text-dark"></i>
{% else %}
<i class="fa fa-toggle-off text-dark"></i>
{% endif %}
</a>
</td>
<td class="text-center">
{% if question.answer_count == 0%}
<a href="{{ question.urls.public }}" >
{% if question.is_public == True %}
<i class="fa fa-toggle-on text-dark "></i>
{% else %}
<i class="fa fa-toggle-off text-dark"></i>
{% endif %}
</a>
{% else %}
{% if question.is_public == True %}
<i class="fa fa-toggle-on"
title= "{% translate "This question is already public"%}"></i>
{% else %}
<i class="fa fa-toggle-off"
title= "{% translate "This question has answers and cannot be made public"%}"></i>
{% endif %}
{% endif %}
</td>
<td class="numeric">
<td class="numeric text-center">
{{ question.answer_count }}
</td>
<td class="action-column">
Expand Down
15 changes: 15 additions & 0 deletions src/pretalx/orga/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,21 @@
cfp.CfPQuestionToggle.as_view(),
name="cfp.question.toggle",
),
path(
"active",
cfp.CfPQuestionActive.as_view(),
name="cfp.question.active",
),
path(
"required",
cfp.CfPQuestionRequired.as_view(),
name="cfp.question.required",
),
path(
"public",
cfp.CfPQuestionPublic.as_view(),
name="cfp.question.public",
),
]
),
),
Expand Down
62 changes: 62 additions & 0 deletions src/pretalx/orga/views/cfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,68 @@ def dispatch(self, request, *args, **kwargs):
return redirect(question.urls.base)


class CfPQuestionActive(PermissionRequired, View):
permission_required = "orga.edit_question"

def get_object(self) -> Question:
return Question.all_objects.filter(
pk=self.kwargs.get("pk")
).first()

def dispatch(self, request, *args, **kwargs):
question = self.get_object()
question.active = not question.active
question.save(update_fields=["active"])
return redirect(question.urls.list)


class CfPQuestionRequired(PermissionRequired, View):
permission_required = "orga.edit_question"

def get_object(self) -> Question:
return Question.all_objects.filter(
pk=self.kwargs.get("pk")
).first()

def dispatch(self, request, *args, **kwargs):
question = self.get_object()

current_value = question.question_required

if current_value == "optional":
question.question_required = "required"
elif current_value == "required":
question.question_required = "after_deadline"
return redirect(question.urls.edit)
else:
question.question_required = "optional"

question.save(update_fields=["question_required"])
return redirect(question.urls.list)


class CfPQuestionPublic(PermissionRequired, View):
permission_required = "orga.edit_question"

def get_object(self) -> Question:
return Question.all_objects.filter(
pk=self.kwargs.get("pk")
).first()

def dispatch(self, request, *args, **kwargs):
question = self.get_object()

current_value = question.is_public

if current_value is True:
question.is_public = False
else:
question.is_public = True

question.save(update_fields=["is_public"])
return redirect(question.urls.list)


class CfPQuestionRemind(EventPermissionRequired, TemplateView):
template_name = "orga/cfp/question_remind.html"
permission_required = "orga.view_question"
Expand Down
4 changes: 4 additions & 0 deletions src/pretalx/submission/models/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ def read_only(self):

class urls(EventUrls):
base = "{self.event.cfp.urls.questions}{self.pk}/"
list = "{self.event.cfp.urls.questions}"
edit = "{base}edit"
up = "{base}up"
down = "{base}down"
delete = "{base}delete"
toggle = "{base}toggle"
active = "{base}active"
required = "{base}required"
public = "{base}public"

def __str__(self):
return str(self.question)
Expand Down
Loading