Exemplo n.º 1
0
def employer_add(request):
  if request.method == 'POST':
    return employer_post(request)
  employer = Employer()
  ctx = dict(existing_employer=False,
         employer=employer,
         employer_form=EmployerEditForm())
  return render_main('main/employer_add.html', ctx, request)
Exemplo n.º 2
0
def employer_edit(request, employer_id):
  if request.method == 'POST':
    return employer_post(request)
  employer = Employer.objects.get(id=employer_id)
  ctx = dict(existing_employer=True,
    employer=employer,
    employer_form=EmployerEditForm.from_employer(employer))
  return render_main('main/employer_add.html', ctx, request)
Exemplo n.º 3
0
def index(request):
  ctx = dict(feeds=[
  FeedObj('Comprehensive', 'Everything going on in UWCR.', '/feeds/all.rss'),
  FeedObj('Reviews', 'All new submitted reviews.', '/feeds/reviews.rss'),
  FeedObj('Q&A', 'All questions and answers.', '/feeds/qna.rss'),
  # RSS Feed for feedbacks is too obscure.
  # FeedObj('Feedbacks', 'All feedbacks', '/feeds/feedbacks.rss'),
])
  return render_main('main/feeds.html', ctx, request)
Exemplo n.º 4
0
def employer(request):
  if request.GET.get('q'):
    emp = get_employers(request.GET.get('q'), 1)
    if len(emp): return redirect(emp[0].browse_link)

  request.json_output['CURRENT_SCREEN'] = 'theenemy_employer'
  _basic_qs = Employer.objects.visible().select_related('employermeta')
  recent_employers = _basic_qs.order_by('-employermeta__modified')[:5]
  most_jobs_employers = _basic_qs.order_by('-employermeta__num_uwpostings')[:5]
  most_reviews_employers = _basic_qs.order_by('-employermeta__num_userpostings')[:5]

  postings = UserPostings.objects.all().order_by('created').select_related('employer').reverse()[:15]
  def with_metastrings(metastring_lambda, employers):
    output = []
    for emp in employers:
      emp.metastring = metastring_lambda(emp)
      output.append(emp)
    return output
  def render_posting(posting):
    def trunc(string, length):
      if length < 0:
        raise ValueError, "length must be nonnegative."
      if length > 3:
        return string[:length]
      "Truncates the given string to the given lenght."
      if len(string) < length:
        return string
      else:
        return string[:length - 3] + '...'
    return djangof('''<div class='result'>
<a href="{{posting.tracked_link}}"><strong>{{employer_name}}</strong> - {{posting}}</a>{{stars}}
</div>''', {'posting':posting,
            'employer_name': trunc(posting.employer.name, 30),
            'stars':mark_safe(star_image(16) * max(0, posting.overall))}
    )
  def render_employer(employer, metastring_lambda):
    return djangof('''
<div class='result'>
<a href="{{emp.browse_link}}">{{emp.name}}</a>
<span class='timedelta' style='vertical-align:top;'>{{metastring}}</span>
</div>
''', {'emp': employer, 'metastring' : metastring_lambda(employer)})
  empty_results = [
    _SearchOutput('Recently updated', map(lambda emp : render_employer(emp, lambda e: e.employermeta.modified_time_passed) , recent_employers), ''),
#    _SearchOutput('Most job postings',with_metastrings(lambda e: '%d postings' % e.employermeta.num_uwpostings, most_jobs_employers)),
#    _SearchOutput('Most reviews', with_metastrings(lambda e: '%d rankings' % e.employermeta.num_userpostings, most_reviews_employers)),
    _SearchOutput('Recent Reviews', map(render_posting, postings),
      mark_safe('<a href="/reviews/">Show all reviews</a>'))
  ]
  ctx = dict(
    employer_browse_form=EmployerBrowseForm(),
    empty_results=empty_results
  )
  request.json_output['SEARCH_EXAMPLES'] = EmployerBrowseForm.EXAMPLES
  # need to get the list of recently updated companies
  return render_main('main/employer_search.html', ctx, request)
Exemplo n.º 5
0
def all_reviews(request):
  EmployerPosting = collections.namedtuple('EmployerPosting', ['employer', 'postings'])
  postings = UserPostings.objects.all().order_by('employer')
  eids = [p.employer_id for p in postings]
  employers = dict((e.id, e) for e in Employer.objects.filter(id__in=eids))
  for p in postings:
    p._employer_cache = employers[p.employer_id]

  employer_postings = [EmployerPosting(employers[eid], list(ps)) for eid, ps in itertools.groupby(postings, key=lambda p: p.employer_id)]
  employer_postings.sort(key=lambda (emp, ps): len(ps))

  ctx = dict(employer_postings=employer_postings)
  return render_main('main/all_reviews.html', ctx, request)
Exemplo n.º 6
0
def employer_postings(request, employer_id):
  default_sort_by = 'open_date'
  default_order = 'desc'
  # duplicate logic between service and view?
  uw_postings_queryset = UWPostings.objects.get_uwpostings_queryset(Employer(pk=employer_id), default_sort_by, order=default_order)
  uw_postings_paginator = Paginator(uw_postings_queryset, UWPOSTINGS_PAGE_SIZE)
  uw_postings = uw_postings_paginator.page(1)
  filter_message = human_readable_query_func('', default_sort_by, default_order)
  request.json_output['order'] = default_order
  request.json_output['sort_by'] = default_sort_by
  ctx = dict(
    uw_postings=uw_postings,
    uw_postings_count=uw_postings_paginator.count,
    sort_bys=[SortBy(col, SORT_BY_HUMAN_READABLE[col], 'asc' if col != 'open_date' else 'desc')
              for col in ['open_date', 'job_title']],
    filter_message=filter_message
  )
  return render_main('main/employer_job_posting.html', ctx, request)
Exemplo n.º 7
0
def accounts(request):
  request.json_output['CURRENT_SCREEN'] = 'looers_accounts'
  user = request.user
  postings = UserPostings.objects.filter(user=user)
  for posting in postings:
    posting.show_anonymize = not posting.is_anonymous
    posting.show_hide_comment = posting.has_comments and not posting.is_comment_hidden
  questions = user.question_set.filter(deleted=False).order_by('id')
  answers = user.answer_set.filter(deleted=False).order_by('id')
  qacount = len(questions) + len(answers)
  ctx = dict(
    password_form=PasswordChangeForm(user),
    subscriptions=Subscription.objects.filter(user=user, is_active=True),
    postings=postings,
    show_hide_all_comment=any(x.show_hide_comment for x in postings),
    show_anonymize_all=any(x.show_anonymize for x in postings),
    questions=questions,
    answers=answers,
    question_answer_count=qacount,
  )
  return render_main('main/account.html', ctx, request)
Exemplo n.º 8
0
def employer_worked(request, employer_id):
  ctx = {}
  return render_main('main/employer_worked.html', ctx, request)
Exemplo n.º 9
0
def employer_detail(request, employer_id=None, employer_name=None):
  # set the current screen.
  request.json_output[CURRENT_SCREEN] = 'employer_detail'
  try:
    # obtain employer.
    if employer_id is not None: employer = Employer.objects.get(id=employer_id)
    elif employer_name is not None: employer = Employer.objects.get(slug=employer_name)
    else:
      raise Http404
  except Employer.DoesNotExist:
    raise Http404
  # fetch the crunchbase logo, save if necessary.
  changed = employer.fetch_crunchbase_logo_url()
  if changed:
    employer.save()
  possible_positions = [unescape_html(x['job_title']) for x in UWPostings.objects.filter(uwcr_emp=employer, visible=True)\
    .values('job_title').distinct().order_by('job_title')]
  request.json_output['POSSIBLE_POSITIONS'] = possible_positions
  # overall ranking
  averages = {}
  for var in ('pay', 'workload', 'num_interns', 'dresscode', 'overall'):
    averages[var] = UserPostings.objects.get_aggregate(employer, var) #cal avg
  icons = filter(lambda i: i.image != "none",
    [Icon(var, avg.mean, avg.count) for var, avg in averages.iteritems()]) #icons
  overall = mark_safe(
    star_image(22) * int(round(averages['overall'].mean))
    );
  # construct the context.
  request.json_output['employer_id'] = employer.id
  employer.inc_num_viewed()

  user = request.user
  postings_submitted = UserPostings.objects.filter(user=user, employer=employer)

  ctx = dict()
  if len(postings_submitted) > 0:
    if len(postings_submitted) > 1:
      logger.warning('The user %s has submitted multiple user postings.' % user.username)
    posting = postings_submitted[0]
    already_submitted_rankings = True

    # BEGIN HACK ###
    # To display the 'pay' as the dropdown select, it must be an integer.
    posting.pay = int(posting.pay)
    # END HACK ###
    ctx.update(
      employer_ranking_basic=EmployerRankingBasic.from_userposting(posting),
      employer_ranking_numeric=EmployerRankingNumeric(instance=posting),
      employer_ranking_comments=EmployerRankingComments(instance=posting),
      settings_form=EmployerRankingSettings({'anonymous':posting.is_anonymous}), # no instance?
    )
  else:
    posting = None
    already_submitted_rankings = False
    ctx.update(
      employer_ranking_basic=EmployerRankingBasic({'employer_id':employer.id}),
      employer_ranking_numeric=EmployerRankingNumeric(),
      employer_ranking_comments=EmployerRankingComments(),
      settings_form=EmployerRankingSettings(),
    )
  ctx.update(employer=employer,
    icons=icons,
    overall=mark_safe(overall),
    # fields for "I worked here" screen.
    # determine whether the user has already submitted ranking.
    already_submitted_rankings=already_submitted_rankings,
    posting=posting,
  )
  # analytics.
  tasks.create_viewed.delay(employer, user)
  return render_main('main/employer_detail.html', ctx, request)
Exemplo n.º 10
0
def feedback(request):
  fbs = Feedback.objects.all().order_by('-created')[:10]
  return render_main('main/feedback.html', dict(
    feedform=FeedbackForm(),
    feedbacks=fbs
  ), request)
Exemplo n.º 11
0
def help(request):
  return render_main('main/help.html', dict(), request)
Exemplo n.º 12
0
def about(request):
  return redirect('/help/')
  return render_main('main/about.html', dict(), request)
Exemplo n.º 13
0
def home(request):
  return redirect('/employer/')
  return render_main('main/home.html', dict(), request)
Exemplo n.º 14
0
def browse_account(request, user_id):
  return render_main('main/account.html', {}, request)