Skip to content

Commit

Permalink
Merge 8280e7a into 4f6ae46
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-o committed Oct 13, 2019
2 parents 4f6ae46 + 8280e7a commit b2e35b0
Show file tree
Hide file tree
Showing 31 changed files with 10 additions and 223 deletions.
16 changes: 3 additions & 13 deletions intranet/apps/announcements/notifications.py
Expand Up @@ -25,19 +25,15 @@ def request_announcement_email(request, form, obj):
"""

logger.debug(form.data)
teacher_ids = form.data["teachers_requested"]
if not isinstance(teacher_ids, list):
teacher_ids = [teacher_ids]
logger.debug(teacher_ids)
teachers = get_user_model().objects.filter(id__in=teacher_ids)
logger.debug(teachers)

subject = "News Post Confirmation Request from {}".format(request.user.full_name)
emails = []
for teacher in teachers:
emails.append(teacher.tj_email)
logger.debug(emails)
logger.info("%s: Announcement request to %s, %s", request.user, teachers, emails)
base_url = request.build_absolute_uri(reverse("index"))
data = {
Expand Down Expand Up @@ -131,9 +127,6 @@ def announcement_posted_email(request, obj, send_all=False):
emails.append(u.notification_email)
users_send.append(u)

logger.debug(users_send)
logger.debug(emails)

if not settings.PRODUCTION and len(emails) > 3:
raise exceptions.PermissionDenied("You're about to email a lot of people, and you aren't in production!")

Expand All @@ -145,12 +138,11 @@ def announcement_posted_email(request, obj, send_all=False):
)
messages.success(request, "Sent email to {} users".format(len(users_send)))
else:
logger.debug("Emailing announcements disabled")
logger.info("Emailing announcements disabled")


def announcement_posted_twitter(request, obj):
if obj.groups.count() == 0 and settings.TWITTER_KEYS is not None:
logger.debug("Publicly available")
title = obj.title
title = title.replace(" ", " ")
url = request.build_absolute_uri(reverse("view_announcement", args=[obj.id]))
Expand All @@ -161,24 +153,22 @@ def announcement_posted_twitter(request, obj):
text = "{}: {}... - {}".format(title, content[:content_len], url)
else:
text = "{}... - {}".format(title[:110], url)
logger.debug("Posting tweet: %s", text)
logger.info("Posting tweet: %s", text)

try:
resp = notify_twitter(text)
respobj = json.loads(resp)
except (ValueError, requests.RequestException, json.JSONDecodeError) as e:
# requests_oauthlib exceptions inherit from ValueError
messages.error(request, f"Error posting to Twitter: {e}")
logger.debug("Error posting to Twitter: %s: %s", e.__class__, e)
logger.error("Error posting to Twitter: %s: %s", e.__class__, e)
capture_exception(e)
else:
if respobj and "id" in respobj:
messages.success(request, "Posted tweet: {}".format(text))
messages.success(request, "https://twitter.com/tjintranet/status/{}".format(respobj["id"]))
else:
messages.error(request, resp)
logger.debug(resp)
logger.debug(respobj)
try:
assert respobj and "id" in respobj
except AssertionError as e:
Expand Down
16 changes: 0 additions & 16 deletions intranet/apps/announcements/views.py
Expand Up @@ -39,10 +39,7 @@ def announcement_posted_hook(request, obj):
obj: The Announcement object
"""
logger.debug("Announcement posted")

if obj.notify_post:
logger.debug("Announcement notify on")
announcement_posted_twitter(request, obj)
try:
notify_all = obj.notify_email_all
Expand Down Expand Up @@ -78,13 +75,9 @@ def request_announcement_view(request):
"""The request announcement page."""
if request.method == "POST":
form = AnnouncementRequestForm(request.POST)
logger.debug(form)
logger.debug(form.data)

if form.is_valid():
teacher_objs = form.cleaned_data["teachers_requested"]
logger.debug("teacher objs:")
logger.debug(teacher_objs)

if len(teacher_objs) > 2:
messages.error(request, "Please select a maximum of 2 teachers to approve this post.")
Expand All @@ -97,7 +90,6 @@ def request_announcement_view(request):
obj.save()

ann = AnnouncementRequest.objects.get(id=obj.id)
logger.debug(teacher_objs)
approve_self = False
for teacher in teacher_objs:
ann.teachers_requested.add(teacher)
Expand Down Expand Up @@ -148,7 +140,6 @@ def approve_announcement_view(request, req_id):
req = get_object_or_404(AnnouncementRequest, id=req_id)

requested_teachers = req.teachers_requested.all()
logger.debug(requested_teachers)
if request.user not in requested_teachers:
messages.error(request, "You do not have permission to approve this announcement.")
return redirect("index")
Expand Down Expand Up @@ -202,9 +193,6 @@ def admin_approve_announcement_view(request, req_id):
"""
req = get_object_or_404(AnnouncementRequest, id=req_id)

requested_teachers = req.teachers_requested.all()
logger.debug(requested_teachers)

if request.method == "POST":
form = AnnouncementRequestForm(request.POST, instance=req)
if form.is_valid():
Expand All @@ -216,7 +204,6 @@ def admin_approve_announcement_view(request, req_id):
if "groups" in request.POST:
group_ids = request.POST.getlist("groups")
groups = Group.objects.filter(id__in=group_ids)
logger.debug(groups)
announcement = Announcement.objects.create(
title=req.title, content=req.content, author=req.author, user=req.user, expiration_date=req.expiration_date
)
Expand Down Expand Up @@ -265,7 +252,6 @@ def add_announcement_view(request):
"""Add an announcement."""
if request.method == "POST":
form = AnnouncementForm(request.POST)
logger.debug(form)
if form.is_valid():
obj = form.save()
obj.user = request.user
Expand Down Expand Up @@ -307,9 +293,7 @@ def modify_announcement_view(request, announcement_id=None):
form = AnnouncementForm(request.POST, instance=announcement)
if form.is_valid():
obj = form.save()
logger.debug(form.cleaned_data)
if "update_added_date" in form.cleaned_data and form.cleaned_data["update_added_date"]:
logger.debug("Update added date")
obj.added = timezone.now()
# SAFE HTML
obj.content = safe_html(obj.content)
Expand Down
3 changes: 0 additions & 3 deletions intranet/apps/context_processors.py
Expand Up @@ -72,8 +72,6 @@ def mobile_app(request):
ua = request.META.get("HTTP_USER_AGENT", "")

if "IonAndroid: gcmFrame" in ua:
logger.debug("IonAndroid %s", request.user)

ctx["is_android_client"] = True
registered = "appRegistered:False" in ua
ctx["android_client_registered"] = registered
Expand All @@ -89,7 +87,6 @@ def mobile_app(request):
rand = ncfg.android_gcm_rand
ncfg.android_gcm_time = timezone.localtime()

logger.debug("GCM random token generated: %s", rand)
ncfg.save()
ctx["android_client_rand"] = rand

Expand Down
5 changes: 0 additions & 5 deletions intranet/apps/dashboard/views.py
Expand Up @@ -141,8 +141,6 @@ def gen_sponsor_schedule(user, sponsor=None, num_blocks=6, surrounding_blocks=No
else:
num_acts += 1

logger.debug(acts)

cur_date = surrounding_blocks[0].date if acts else given_date if given_date else timezone.localdate()

last_block = surrounding_blocks[len(surrounding_blocks) - 1] if surrounding_blocks else None
Expand Down Expand Up @@ -195,11 +193,8 @@ def find_birthdays(request):
cached = cache.get(key)

if cached:
logger.debug("Birthdays on %s loaded from cache.", today)
logger.debug(cached)
return cached
else:
logger.debug("Loading and caching birthday info for %s", today)
tomorrow = today + timedelta(days=1)
try:
data = {
Expand Down
4 changes: 0 additions & 4 deletions intranet/apps/eighth/forms/admin/activities.py
Expand Up @@ -17,9 +17,7 @@ class ActivityDisplayField(forms.ModelChoiceField):
def __init__(self, *args, **kwargs):
if "block" in kwargs:
block = kwargs.pop("block")
logger.debug(block)
self.cancelled_acts = [s.activity for s in EighthScheduledActivity.objects.filter(block=block, cancelled=True)]
logger.debug(self.cancelled_acts)

super(ActivityDisplayField, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -81,7 +79,6 @@ class ScheduledActivityMultiSelectForm(forms.Form):

def __init__(self, *args, label="Activities", block=None, **kwargs): # pylint: disable=unused-argument
super(ScheduledActivityMultiSelectForm, self).__init__(*args, **kwargs)
logger.debug(block)
if block is not None:
activity_ids = (
EighthScheduledActivity.objects.exclude(activity__deleted=True)
Expand All @@ -92,7 +89,6 @@ def __init__(self, *args, label="Activities", block=None, **kwargs): # pylint:
else:
queryset = EighthActivity.undeleted_objects.all().order_by("name")

logger.debug(queryset)
self.fields["activities"].queryset = queryset


Expand Down
4 changes: 0 additions & 4 deletions intranet/apps/eighth/models.py
Expand Up @@ -1431,7 +1431,6 @@ def add_user(
existing_blocks = [existing_signup.scheduled_activity.block]
if sibling:
existing_blocks.append(sibling.block)
logger.debug(existing_blocks)

add_breadcrumb(
category="eighth-signup",
Expand Down Expand Up @@ -1552,10 +1551,8 @@ def cancel(self):
for the B-block activity in both-block activities.)
"""
logger.debug("Running cancel hooks: %s", self)

if not self.cancelled:
logger.debug("Cancelling %s", self)
self.cancelled = True
self.save(update_fields=["cancelled"])

Expand All @@ -1573,7 +1570,6 @@ def uncancel(self):
"""

if self.cancelled:
logger.debug("Uncancelling %s", self)
self.cancelled = False
self.save(update_fields=["cancelled"])

Expand Down
2 changes: 0 additions & 2 deletions intranet/apps/eighth/serializers.py
Expand Up @@ -46,7 +46,6 @@ def fetch_scheduled_on(self, act):
"url": reverse("api_eighth_scheduled_activity_signup_list", args=[scheduled_activity.id], request=self.context["request"]),
},
}
logger.debug(scheduled_on)
return scheduled_on

class Meta:
Expand Down Expand Up @@ -358,7 +357,6 @@ class EighthScheduledActivitySerializer(serializers.ModelSerializer):

def __init__(self, *args, **kwargs):
super(EighthScheduledActivitySerializer, self).__init__(*args, **kwargs)
logger.debug(kwargs)
if "context" in kwargs and "request" in kwargs["context"]:
self.request = kwargs["context"]["request"]
else:
Expand Down
1 change: 0 additions & 1 deletion intranet/apps/eighth/views/admin/activities.py
Expand Up @@ -171,7 +171,6 @@ def edit_activity_view(request, activity_id):
if "add_group" in request.POST:
grp_name = "Activity: {}".format(activity.name)
grp, status = Group.objects.get_or_create(name=grp_name)
logger.debug(grp)
activity.restricted = True
activity.groups_allowed.add(grp)
activity.save()
Expand Down
3 changes: 0 additions & 3 deletions intranet/apps/eighth/views/admin/blocks.py
Expand Up @@ -41,7 +41,6 @@ def add_block_view(request):
if date:
date_format = re.compile(r"([0-9]{2})\/([0-9]{2})\/([0-9]{4})")
fmtdate = date_format.sub(r"\3-\1-\2", date)
logger.debug(fmtdate)
title_suffix = " - {}".format(fmtdate)
show_letters = True

Expand All @@ -51,8 +50,6 @@ def add_block_view(request):
blocks_day = EighthBlock.objects.filter(date=fmtdate)
for day in blocks_day:
current_letters.append(day.block_letter)
logger.debug(letters)
logger.debug(current_letters)
for l in letters:
if not l:
continue
Expand Down
14 changes: 0 additions & 14 deletions intranet/apps/eighth/views/admin/groups.py
Expand Up @@ -183,7 +183,6 @@ def get_user_info(key, val):


def handle_group_input(filetext):
logger.debug(filetext)
lines = filetext.splitlines()

return find_users_input(lines)
Expand Down Expand Up @@ -232,11 +231,6 @@ def find_users_input(lines):
if not done:
unsure_users.append([line, r])

logger.debug("Sure users:")
logger.debug(sure_users)
logger.debug("Unsure users:")
logger.debug(unsure_users)

return sure_users, unsure_users


Expand All @@ -251,7 +245,6 @@ def upload_group_members_view(request, group_id):
filetext = False
if request.method == "POST":
form = UploadGroupForm(request)
logger.debug(request.FILES)
if "file" in request.FILES:
fileobj = request.FILES["file"]
if "text/" not in fileobj.content_type:
Expand Down Expand Up @@ -475,7 +468,6 @@ def get_form_kwargs(self, step=None):
if step == "block":
kwargs.update({"exclude_before_date": get_start_date(self.request)})
if step == "activity":
logger.debug("cleaned block: %s", self.get_cleaned_data_for_step("block")["block"])
block = self.get_cleaned_data_for_step("block")
if block:
block = block["block"]
Expand Down Expand Up @@ -514,9 +506,6 @@ def done(self, form_list, **kwargs):
block = form_list[0].cleaned_data["block"]
activities = form_list[1].cleaned_data["activities"]

logger.debug(block)
logger.debug(activities)

schact_ids = []
for act in activities:
try:
Expand Down Expand Up @@ -547,7 +536,6 @@ def done(self, form_list, **kwargs):
@eighth_admin_required
def eighth_admin_distribute_action(request):
if "users" in request.POST:
logger.debug(request.POST)
activity_user_map = {}
for item in request.POST:
if item[:6] == "schact":
Expand All @@ -561,7 +549,6 @@ def eighth_admin_distribute_action(request):
activity_user_map[schact] = userids

changes = 0
logger.debug(activity_user_map)
for schact, userids in activity_user_map.items():
for uid in userids:
changes += 1
Expand Down Expand Up @@ -664,7 +651,6 @@ def add_member_to_group_view(request, group_id):
if errors:
messages.error(request, "Could not process search query.")
return redirect(next_url + "?error=n")
logger.debug(results)
if not results:
return redirect(next_url + "?error=n")
else:
Expand Down
4 changes: 0 additions & 4 deletions intranet/apps/eighth/views/admin/maintenance.py
Expand Up @@ -38,8 +38,6 @@ def __init__(self, email, folder):
threading.Thread.__init__(self)
self.email = email
self.folder = folder
logger.debug(self.folder)
logger.debug(self.email)

def handle_user(self, u, row, index_dict, content):
# pylint: disable=protected-access
Expand Down Expand Up @@ -131,8 +129,6 @@ def run(self):
content.write("\n=== The import process has been aborted.")
shutil.rmtree(self.folder)
content.seek(0)
logger.debug(content.read())
content.seek(0)

data = {"log": content.read(), "failure": failure, "help_email": settings.FEEDBACK_EMAIL, "date": start_time.strftime("%I:%M:%S %p %m/%d/%Y")}
email_send_task.delay(
Expand Down

0 comments on commit b2e35b0

Please sign in to comment.