Skip to content

Commit 2dbc92e

Browse files
Merge pull request #1689 from learning-unlimited/mgersh-dead-code
Various dead code removal
2 parents 8b6839d + c9ea37f commit 2dbc92e

17 files changed

+1
-458
lines changed

esp/esp/program/models/__init__.py

-29
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,6 @@ def getFriendlyName(self):
111111
""" Return a human-readable name that identifies this Program Module """
112112
return self.admin_title
113113

114-
def getSummaryCalls(self):
115-
"""
116-
Returns a list of the summary view functions for the specified module
117-
118-
Only returns functions that are both listed in summary_calls,
119-
and that are valid functions for this class.
120-
121-
Returns an empty list if no calls are found.
122-
"""
123-
callNames = this.summary_calls.split(',')
124-
125-
calls = []
126-
myClass = this.getPythonClass()
127-
128-
129-
130-
for i in callNames:
131-
try:
132-
calls.append(getattr(myClass, i))
133-
except:
134-
pass
135-
136-
return calls
137-
138-
139114
def getPythonClass(self):
140115
"""
141116
Gets the Python class that's associated with this ProgramModule database record
@@ -1284,10 +1259,6 @@ def confirmStudentReg(self, user):
12841259
if records.count() == 0:
12851260
record = Record.objects.create(user=self.user, event="reg_confirmed", program=self.program)
12861261

1287-
def cancelStudentRegConfirmation(self, user):
1288-
""" Cancel the registration confirmation for the specified student """
1289-
raise ESPError("Error: You can't cancel a registration confirmation! Confirmations are final!")
1290-
12911262
def save(self, *args, **kwargs):
12921263
""" update the timestamp and clear getLastProfile cache """
12931264
self.last_ts = datetime.now()

esp/esp/program/modules/handlers/adminclass.py

-102
Original file line numberDiff line numberDiff line change
@@ -193,92 +193,6 @@ def reviewClass(self, request, tl, one, two, module, extra, prog):
193193

194194
return HttpResponse('')
195195

196-
@aux_call
197-
@needs_admin
198-
def attendees(self, request, tl, one, two, module, extra, prog):
199-
""" Mark students as having attended the program, or as having registered for the specified class """
200-
saved_record = False
201-
202-
if request.method == 'POST':
203-
if not( request.POST.has_key('class_id') and request.POST.has_key('ids_to_enter') ):
204-
raise ESPError("Error: The server lost track of your data! Please go back to the main page of this feature and try entering it again.")
205-
206-
usernames = []
207-
ids = []
208-
209-
for id in [ x for x in request.POST['ids_to_enter'].split('\n') if x.strip() != '' ]:
210-
try: # We're going to accept both usernames and user ID's.
211-
# Assume that valid integers are user ID's
212-
# and things that aren't valid integers are usernames.
213-
if id[0] == '0':
214-
id_trimmed = id.strip()[:-1]
215-
else:
216-
id_trimmed = id
217-
218-
id_val = int(id_trimmed)
219-
ids.append(id_val)
220-
except ValueError:
221-
usernames.append( id.strip() )
222-
223-
Q_Users = Q(id=-1) # in case usernames and ids are both empty
224-
if usernames:
225-
Q_Users |= Q(username__in = usernames)
226-
227-
if ids:
228-
Q_Users |= Q(id__in = ids)
229-
230-
users = ESPUser.objects.filter( Q_Users )
231-
232-
if request.POST['class_id'] == 'program':
233-
already_registered_users = prog.students()['attended']
234-
else:
235-
cls = ClassSection.objects.get(id = request.POST['class_id'])
236-
already_registered_users = cls.students()
237-
238-
already_registered_ids = [ i.id for i in already_registered_users ]
239-
240-
new_attendees = ESPUser.objects.filter( Q_Users )
241-
if already_registered_ids != []:
242-
new_attendees = new_attendees.exclude( id__in = already_registered_ids )
243-
new_attendees = new_attendees.distinct()
244-
245-
no_longer_attending = ESPUser.objects.filter( id__in = already_registered_ids )
246-
if ids != [] or usernames != []:
247-
no_longer_attending = no_longer_attending.exclude( Q_Users )
248-
no_longer_attending = no_longer_attending.distinct()
249-
250-
if request.POST['class_id'] == 'program':
251-
for stu in no_longer_attending:
252-
prog.cancelStudentRegConfirmation(stu)
253-
for stu in new_attendees:
254-
prog.confirmStudentReg(stu)
255-
else:
256-
for stu in no_longer_attending:
257-
cls.unpreregister_student(stu)
258-
for stu in new_attendees:
259-
cls.preregister_student(stu, overridefull=True)
260-
261-
saved_record = True
262-
else:
263-
if request.GET.has_key('class_id'):
264-
if request.GET['class_id'] == 'program':
265-
is_program = True
266-
registered_students = prog.students()['attended']
267-
else:
268-
is_program = False
269-
cls = ClassSection.objects.get(id = request.GET['class_id'])
270-
registered_students = cls.students()
271-
272-
context = { 'is_program': is_program,
273-
'prog': prog,
274-
'cls': cls,
275-
'registered_students': registered_students,
276-
'class_id': request.GET['class_id'] }
277-
278-
return render_to_response(self.baseDir()+'attendees_enter_users.html', request, context)
279-
280-
return render_to_response(self.baseDir()+'attendees_selectclass.html', request, { 'saved_record': saved_record, 'prog': prog })
281-
282196
@aux_call
283197
@needs_admin
284198
def deletesection(self, request, tl, one, two, module, extra, prog):
@@ -482,22 +396,6 @@ def changeoption(self, request,tl,one,two,module,extra,prog):
482396

483397
return self.goToCore(tl)
484398

485-
@needs_admin
486-
def main(self, request, tl, one, two, module, extra, prog):
487-
""" Display a teacher eg page """
488-
context = {}
489-
modules = self.program.getModules(request.user, 'manage')
490-
491-
for module in modules:
492-
context = module.prepare(context)
493-
494-
495-
context['modules'] = modules
496-
context['one'] = one
497-
context['two'] = two
498-
499-
return render_to_response(self.baseDir()+'mainpage.html', request, context)
500-
501399
@aux_call
502400
@needs_admin
503401
def deleteclass(self, request, tl, one, two, module, extra, prog):

esp/esp/seltests/seltests.py

+1-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django_selenium.testcases import SeleniumTestCase
2-
from esp.seltests.util import try_ajax_login, try_normal_login, logout
2+
from esp.seltests.util import try_normal_login, logout
33
from esp.users.models import ESPUser
44
from esp.utils.models import TemplateOverride
55

@@ -41,36 +41,7 @@ def setUpNormalLogin(self):
4141
"""
4242
to.save()
4343

44-
def setUpAjaxLogin(self):
45-
if(self.good_version == -1):
46-
to, created = TemplateOverride.objects.get_or_create(name='index.html', version=1)
47-
else:
48-
to = TemplateOverride.objects.filter(name='index.html')[0]
49-
to.content = """
50-
{% extends "elements/html" %}
51-
52-
{% block body %}
53-
{% include "users/loginbox_ajax.html" %}
54-
{% endblock %}
55-
"""
56-
to.save()
57-
5844
def test_csrf_delete(self):
59-
# First set up and test AJAX login
60-
self.setUpAjaxLogin()
61-
62-
self.open_url("/")
63-
try_ajax_login(self, "student", "student")
64-
self.failUnless(self.is_text_present('Student Student'))
65-
logout(self)
66-
67-
self.delete_cookie("esp_csrftoken")
68-
69-
try_ajax_login(self, "student", "student")
70-
self.failUnless(self.is_text_present('Student Student'))
71-
logout(self)
72-
73-
7445
# Now set up and test normal login
7546
self.setUpNormalLogin()
7647
self.open_url("/") # Load index

esp/esp/seltests/util.py

-21
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33

44
def noActiveAjaxJQuery(driver):
55
return driver.execute_script("return $j.active == 0")
6-
def waitForAjaxJQuery(driver):
7-
while(not noActiveAjaxJQuery(driver)):
8-
time.sleep(1)
9-
def noActiveAjaxForms(driver):
10-
return driver.execute_script("return numAjaxConnections == 0")
11-
def waitForAjaxForms(driver):
12-
while(not noActiveAjaxForms(driver)):
13-
time.sleep(1)
146

157
def try_login(driver, username, password):
168
elem = WebDriverWait(driver, 10).until(
@@ -25,19 +17,6 @@ def try_normal_login(driver, username, password):
2517
try_login(driver, username, password)
2618
driver.open_url("/")
2719

28-
def try_ajax_login(driver, username, password):
29-
try_login(driver, username, password)
30-
try:
31-
WebDriverWait(driver, 10).until(noActiveAjaxForms)
32-
except Exception as exc:
33-
exc_type = type(exc)
34-
message = exc.message
35-
if message:
36-
message += "\n"
37-
message += "Wait for ajax login timed out."
38-
raise exc_type(message)
39-
driver.open_url("/")
40-
4120
def logout(driver):
4221
driver.open_url("/myesp/signout/")
4322
driver.open_url("/")

esp/esp/users/lighttpd_trac_auth.py

-65
This file was deleted.

esp/esp/users/models/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ def save(self, *args, **kwargs):
129129
class ESPUserManager(Manager):
130130
pass
131131

132-
def get_studentreg_model():
133-
from esp.program.models import StudentRegistration
134-
return StudentRegistration
135-
136132
class ESPUser(User, AnonymousUser):
137133
""" Create a user of the ESP Website
138134
This user extends the auth.User of django"""

esp/esp/users/tests.py

-6
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,6 @@ def runTest(self):
309309
for key in self.keys:
310310
self.assertTrue(content.has_key(key), "Key %s missing from Ajax response to %s" % (key, self.path))
311311

312-
class AjaxLoginExistenceTest(AjaxExistenceChecker):
313-
def __init__(self, *args, **kwargs):
314-
super(AjaxLoginExistenceTest, self).__init__(*args, **kwargs)
315-
self.path = '/myesp/ajax_login/'
316-
self.keys = ['loginbox_html']
317-
318312
class AjaxScheduleExistenceTest(AjaxExistenceChecker, ProgramFrameworkTest):
319313
def runTest(self):
320314
self.path = '/learn/%s/ajax_schedule' % self.program.getUrlBase()

esp/esp/users/urls.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from esp.users.views.registration import GradeChangeRequestView
44

55
urlpatterns = patterns('esp.users.views',
6-
(r'^ajax_login/?', 'ajax_login'),
76
(r'^register/?$', 'user_registration_phase1',),
87
(r'^register/information/?$', 'user_registration_phase2'),
98
(r'^activate/?$', 'registration.activate_account',),

esp/esp/users/views/__init__.py

-38
Original file line numberDiff line numberDiff line change
@@ -97,44 +97,6 @@ def login_checked(request, *args, **kwargs):
9797
return reply
9898

9999

100-
def ajax_login(request, *args, **kwargs):
101-
import simplejson as json
102-
from django.contrib.auth import authenticate
103-
from django.template.loader import render_to_string
104-
105-
username = None
106-
password = None
107-
if request.method == 'POST':
108-
username = request.POST['username']
109-
password = request.POST['password']
110-
111-
username = filter_username(username, password)
112-
113-
user = authenticate(username=username, password=password)
114-
if user is not None:
115-
if user.is_active:
116-
result_str = 'Login successful'
117-
user, forwarded = UserForwarder.follow(ESPUser(user))
118-
if forwarded:
119-
result_str = 'Logged in as "%s" ("%s" is marked as a duplicate account)' % (user.username, username)
120-
auth_login(request, user)
121-
else:
122-
result_str = 'Account disabled'
123-
else:
124-
result_str = 'Invalid username or password'
125-
126-
request.user = ESPUser(user)
127-
content = render_to_string('users/loginbox_content.html', RequestContext(request, {'request': request, 'login_result': result_str}))
128-
result_dict = {'loginbox_html': content}
129-
130-
if request.user.isAdministrator():
131-
admin_home_url = Tag.getTag('admin_home_page')
132-
if admin_home_url:
133-
result_dict['script'] = render_to_string('users/loginbox_redirect.js', {'target': admin_home_url})
134-
135-
return HttpResponse(json.dumps(result_dict))
136-
137-
138100
def signout(request):
139101
""" This view merges Django's logout view with our own "Goodbye" message. """
140102
auth_logout(request)

0 commit comments

Comments
 (0)