def __init__(self, *args, **kwargs): super(WorkScheduleForm, self).__init__(*args, **kwargs) workers = Worker.objects.filter( preference=Preference.current_preference().year).order_by("name") self.fields["invites"].choices = [(worker.pk, worker.name) for worker in workers] self.fields["invites"].widget.attrs["class"] = "chosen"
def __init__(self, *args, **kwargs): super(PenaltyForm, self).__init__(*args, **kwargs) pref = Preference.current_preference() users = User.objects.filter(is_active=True, is_staff=True, year=pref.year) self.fields["user"].queryset = users
def list_companies(request): if request.user.is_staff: user_companies = (Company.objects.filter( contact=request.user).order_by("status", "name").select_related( "package", "contact").prefetch_related("company_contacts", "contracts")) # Put "Not intereset" last temp_companies = [] # Queries are lazy, use list() to execute not_interested_companies = [] signed_companies = [] for company in list(user_companies): if company.status == 1: not_interested_companies.append(company) elif company.status == 3: signed_companies.append(company) else: temp_companies.append(company) user_companies = temp_companies + signed_companies + not_interested_companies else: user_companies = None companies = (Company.objects.filter( active=True).order_by("name").select_related( "contact", "package").prefetch_related("waiting_for_package", "contracts")) return render( request, "company/base.html", { "companies": companies, "user_companies": user_companies, "year": Preference.current_preference().year, "title": _("Companies"), }, )
def __init__(self, *args, **kwargs): super(ResponsibilityForm, self).__init__(*args, **kwargs) users = User.objects.filter( is_active=True, is_staff=True, year=Preference.current_preference().year ).order_by("first_name") self.fields["contact"].choices = [("", "----")] + [ (user.pk, user.get_full_name()) for user in users ]
def utils_processor(request): """ Return site information in templates. """ context = {} context["preferences"] = Preference.current_preference() return context
def under_development(request, **kwargs): year = Preference.current_preference().year return render( request, "static/under_development.html", { "title": _("Under Development"), "year": year }, )
def __init__(self, *args, **kwargs): super(CompanyForm, self).__init__(*args, **kwargs) users = User.objects.filter( is_active=True, is_staff=True, year=Preference.current_preference().year ).order_by("first_name") self.fields["contact"].choices = [("", "----")] + [ (user.pk, user.get_full_name()) for user in users ] waiting_lists = Package.objects.filter(is_full=True, has_waiting_list=True) self.fields["waiting_for_package"].queryset = waiting_lists
def __init__(self, *args, **kwargs): super(MeetingForm, self).__init__(*args, **kwargs) pref = Preference.current_preference() users = User.objects.filter(is_active=True, is_staff=True, year=pref.year) self.fields["referee"].queryset = users self.fields["invites"].choices = [(user.pk, user.get_full_name()) for user in users]
def process_request(self, request): if (request.path == reverse("itdagene.under_development") or "login" in request.path): return development = Preference.current_preference().development_mode if development: if request.user.is_authenticated: if not request.user.is_staff: return HttpResponseRedirect( reverse("itdagene.under_development")) else: return HttpResponseRedirect( reverse("itdagene.under_development"))
def add(request): form = MeetingForm() if request.method == "POST": form = MeetingForm(request.POST) if form.is_valid(): meeting = form.save() meeting.preference = Preference.current_preference() meeting.save() add_message(request, SUCCESS, _("Meeting added.")) return redirect(reverse("itdagene.meetings.list")) return render(request, "meetings/form.html", { "form": form, "title": _("Add Meeting") })
def add(request): form = ExperienceForm() if request.method == "POST": form = ExperienceForm(request.POST) if form.is_valid(): data = form.save(commit=False) data.year = Preference.get_preference_by_year(request.user.year) data.save() add_message(request, SUCCESS, _("Experience added.")) return redirect(reverse("itdagene.experiences.view", args=[data.pk])) return render( request, "experiences/form.html", {"form": form, "title": _("Add Experience")} )
def view(request, id): company = get_object_or_404( Company.objects.select_related().prefetch_related(), pk=id) evaluation, created = Evaluation.objects.get_or_create( company=company, preference=Preference.current_preference()) return render( request, "company/view.html", { "company": company, "evaluation": evaluation, "title": company, "description": _("Company"), }, )
def report(request, year=None): if year is None: preferences = Preference.current_preference() else: preferences = get_object_or_404(Preference, year=year) evaluations = Evaluation.objects.filter(preference=preferences, has_answers=True) if evaluations.count(): if evaluations.exclude(internship_marathon_rating=0).count(): avg_internship_marathon_rating = ( sum([e.internship_marathon_rating for e in evaluations]) / evaluations.exclude(internship_marathon_rating=0).count() ) if evaluations.exclude(course_rating=0).count(): avg_course_rating = ( sum([e.course_rating for e in evaluations]) / evaluations.exclude(course_rating=0).count() ) if evaluations.exclude(visitors_rating=0).count(): avg_visitors_rating = ( sum([e.visitors_rating for e in evaluations]) / evaluations.count() ) if evaluations.exclude(interview_location_rating=0).count(): avg_interview_location_rating = ( sum([e.interview_location_rating for e in evaluations]) / evaluations.exclude(interview_location_rating=0).count() ) if evaluations.exclude(banquet_rating=0).count(): avg_banquet_rating = ( sum([e.banquet_rating for e in evaluations]) / evaluations.exclude(banquet_rating=0).count() ) percentage_want_to_come_back = ( evaluations.filter(want_to_come_back=True).count() / evaluations.count() ) * 100 title = _("Evaluation of itDAGENE") description = preferences.year prev_year = preferences.year - 1 return render(request, "feedback/evaluations/report.html", locals())
def edit(request): current_pref = Preference.current_preference() current_year = current_pref.year form = PreferenceForm(instance=current_pref) if request.method == "POST": form = PreferenceForm(request.POST, instance=current_pref) if form.is_valid(): preference = form.save(commit=False) preference.active = True if preference.year != current_year: preference, created = Preference.objects.get_or_create( year=preference.year, defaults={ "active": True, "start_date": datetime.strptime("%s-09-11" % preference.year, "%Y-%m-%d"), "end_date": datetime.strptime("%s-09-12" % preference.year, "%Y-%m-%d"), }, ) else: preference.save(log_it=False, notify_subscribers=False) for preference_object in Preference.objects.exclude( id=preference.id): preference_object.active = False preference_object.save(log_it=False, notify_subscribers=False) cache.set("pref", preference) return redirect(reverse("itdagene.itdageneadmin.preferences.edit")) return render( request, "admin/preferences/edit.html", { "pref": current_pref, "form": form, "title": _("Preferences") }, )
def save(self, commit=True): pref = Preference.current_preference() meeting = super(MeetingForm, self).save(commit=commit) for i in self.cleaned_data["invites"]: user = get_object_or_404(User, id=i, is_staff=True, is_active=True, year=pref.year) ReplyMeeting.objects.get_or_create(meeting=meeting, user_id=user.id) if self.cleaned_data["invite_current_board"]: for user in User.objects.filter(year=pref.year, is_staff=True, is_active=True): ReplyMeeting.objects.get_or_create(meeting=meeting, user_id=user.id) return meeting
def user_detail(request, pk): try: if not request.user.is_staff: person = ( User.objects.filter(Q(is_staff=True) | Q(id=request.user.id)) .filter(is_active=True, year=request.user.year) .get(pk=pk) ) else: person = User.objects.filter(is_active=True).order_by("username").get(pk=pk) except Exception: raise Http404 current_year = Preference.current_preference().year return render( request, "users/detail.html", { "person": person, "current_year": current_year, "title": _("User Detail"), "description": person.get_full_name(), }, )
def resolve_current_meta_data(self, info): return Preference.current_preference()
def resolve_poster(self, info): return Preference.current_preference().hsp_poster
def resolve_video(self, info): return Preference.current_preference().hsp_video
def resolve_intro(self, info): return Preference.current_preference().hsp_intro
def save(self): pref = Preference.current_preference() worker = super(WorkerForm, self).save(commit=False) worker.preference = pref.year worker.save() return worker
def current_contract(self): c = Contract.objects.filter( company=self, timestamp__year=Preference.current_preference().year) if c.count() > 0: return c[0] return None