14 |
14 |
15 from pytask.taskapp.models import Task, TaskComment, TaskClaim, TextBook |
15 from pytask.taskapp.models import Task, TaskComment, TaskClaim, TextBook |
16 from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \ |
16 from pytask.taskapp.forms import CreateTaskForm, EditTaskForm, \ |
17 TaskCommentForm, ClaimTaskForm, \ |
17 TaskCommentForm, ClaimTaskForm, \ |
18 ChoiceForm, EditTaskForm, CreateTextbookForm |
18 ChoiceForm, EditTaskForm, CreateTextbookForm |
19 from pytask.taskapp.utils import getTask |
19 from pytask.taskapp.utils import getTask, getTextBook |
20 from pytask.profile.utils import get_notification |
20 from pytask.profile.utils import get_notification |
21 |
21 |
22 |
22 |
23 @login_required |
23 @login_required |
24 def create_task(request): |
24 def create_task(request): |
206 new_textbook = TextBook(**data) |
206 new_textbook = TextBook(**data) |
207 new_textbook.save() |
207 new_textbook.save() |
208 |
208 |
209 new_textbook.chapters = form.cleaned_data['chapters'] |
209 new_textbook.chapters = form.cleaned_data['chapters'] |
210 |
210 |
211 textbook_url = "/task/textbook/tid=%s"%new_textbook.uniq_key |
211 textbook_url = "/task/textbook/view/tid=%s"%new_textbook.uniq_key |
212 return redirect(textbook_url) |
212 return redirect(textbook_url) |
213 else: |
213 else: |
214 context.update({"form": form}) |
214 context.update({"form": form}) |
215 return render_to_response("task/create_textbook.html", context) |
215 return render_to_response("task/create_textbook.html", context) |
216 else: |
216 else: |
217 form = CreateTextbookForm() |
217 form = CreateTextbookForm() |
218 context.update({"form": form}) |
218 context.update({"form": form}) |
219 return render_to_response("task/create_textbook.html", context) |
219 return render_to_response("task/create_textbook.html", context) |
|
220 |
|
221 def view_textbook(request, tid): |
|
222 |
|
223 textbook = getTextBook(tid) |
|
224 textbook_url = "/task/textbook/view/tid=%s"%textbook.uniq_key |
|
225 |
|
226 user = request.user |
|
227 if not user.is_authenticated(): |
|
228 return render_to_response("task/view_textbook.html") |
|
229 |
|
230 profile = user.get_profile() |
|
231 |
|
232 context = {"user": user, |
|
233 "profile": profile, |
|
234 "textbook": textbook, |
|
235 } |
|
236 |
|
237 context.update(csrf(request)) |
|
238 |
|
239 chapters = Task.objects.filter(status="UP") |
|
240 |
|
241 can_edit = True if user == textbook.created_by and textbook.status == "UP"\ |
|
242 else False |
|
243 |
|
244 can_approve = True if profile.rights in ["MG", "DC"] and \ |
|
245 textbook.status == "UP" else False |
|
246 |
|
247 context.update({"chapters": chapters, |
|
248 "can_edit": can_edit, |
|
249 "can_approve": can_approve}) |
|
250 return render_to_response("task/view_textbook.html", context) |
220 |
251 |
221 @login_required |
252 @login_required |
222 def claim_task(request, tid): |
253 def claim_task(request, tid): |
223 |
254 |
224 task_url = "/task/view/tid=%s"%tid |
255 task_url = "/task/view/tid=%s"%tid |