Skip to content

Commit

Permalink
Merge branch 'master' of github.com:COSC-499-W2023/year-long-project-…
Browse files Browse the repository at this point in the history
…team-7 into reprompt
  • Loading branch information
Ferdinand737 committed Mar 25, 2024
2 parents 79e224f + c215f3e commit 9636db7
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 28 deletions.
11 changes: 10 additions & 1 deletion app/capstone/transformer/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ def extract_text_from_pdf(filename: str) -> str:
return text


def extract_text_from_md(filename: str) -> str:
file_system = FileSystemStorage()
file_path = file_system.path(filename)
text = open(file_path, 'r').read()
return text

def generate_output(files: list[File], conversion: Conversion) -> str:
input_file_text = ""

for file in files:
ext = os.path.splitext(file.file.name)[1].lower()
if "pdf" in file.type:
input_file_text += extract_text_from_pdf(file.file.name)
elif ext == ".md":
input_file_text += extract_text_from_md(file.file.name)
else:
try:
input_file_text += extract_text_from_pdf(to_pdf(file.file.name))
Expand Down
31 changes: 25 additions & 6 deletions app/capstone/transformer/presentationGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from .prompts import *
from serpapi import GoogleSearch # type: ignore
from .utils import error
from urllib3.exceptions import MaxRetryError
import re


class PresentationGenerator:
Expand All @@ -30,6 +32,8 @@ def __init__(self, input_file_text: str, conversion: Conversion):
self.template = conversion.template

def image_search(self, query: str) -> File:
query = re.sub("<|>", "", query)

params = {
"engine": "google_images",
"q": query,
Expand All @@ -41,20 +45,35 @@ def image_search(self, query: str) -> File:

results = search.get_dict()["images_results"]

image_url = results[random.randint(0, len(results) - 1)]["original"]
jpegs_results = [
result for result in results if str(result["original"]).endswith(".jpg")
]

file_system = FileSystemStorage()
while True:
random_image_url = results[random.randint(0, len(jpegs_results) - 1)][
"original"
]

try:
response = requests.head(random_image_url)

image = requests.get(image_url).content
if "image/jpeg" in response.headers.get("content-type", ""):
image = requests.get(random_image_url).content
break

except MaxRetryError as e:
continue

file_system = FileSystemStorage()

rel_path = f"{query[:30]}.jpg"
file_system.save(rel_path, ContentFile(image))
name = f"{query[:30]}.jpg"
path = file_system.save(name, ContentFile(image))

image_file = File(
user=self.conversion.user,
conversion=self.conversion,
type=".jpg",
file=rel_path,
file=path,
is_output=False,
)

Expand Down
6 changes: 3 additions & 3 deletions app/capstone/transformer/presentationManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ def add_slide_to_presentation(self, slide_content: SlideContent) -> None:

elif field.field_type == FieldTypes.IMAGE:
if isinstance(field.value, File):
slide.shapes[field.field_index].insert_picture(
field.value.file.file
)
file_system = FileSystemStorage()
path = file_system.path(field.value.file.name)
slide.shapes[field.field_index].insert_picture(path)
20 changes: 13 additions & 7 deletions app/capstone/transformer/subscriptionManager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .models import Subscription, Product
from datetime import date
from django.contrib.auth.models import User
from datetime import timedelta


def has_valid_subscription(user_id: int) -> bool:
Expand All @@ -21,13 +22,18 @@ def give_subscription_to_user(
user: User, start_date: date, end_date: date, product: Product | None
) -> None:
subscription, created = Subscription.objects.get_or_create(user=user)
subscription.has_subscription = True
subscription.start_date = start_date
subscription.end_date = end_date
if product is not None:
if product.name == "Premium Subscription":
subscription.is_premium = True
subscription.save()
if created:
subscription.has_subscription = True
subscription.start_date = start_date
subscription.end_date = end_date
if product is not None:
if product.name == "Premium Subscription":
subscription.is_premium = True
subscription.save()
else:
old_end = subscription.end_date
subscription.end_date = old_end + timedelta(days=product.length_days) # type: ignore
subscription.save()


def delete_subscription(user: User) -> None:
Expand Down
3 changes: 0 additions & 3 deletions app/capstone/transformer/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@
{% load static %}
{% block content %}
{% include "login_form_template.html" with form=form form_title="Login" form_action="/login" submit_text="Login" form_alt_action="/register" form_alt_text="Create a new account" %}
<div class="text-center">
<a href="{% url 'password_reset' %}">Forgot Password?</a>
</div>
{% endblock content %}
3 changes: 3 additions & 0 deletions app/capstone/transformer/templates/login_form_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ <h1 class="h3 mb-3 mt-3 font-weight-normal" tabindex="0">{{ form_title }}</h1>
{% endfor %}
<button class="btn btn-primary mt-3 mx-auto login-button" type="submit">{{ submit_text }}</button>
</form>
<div class="text-center mt-3">
<a href="{% url 'password_reset' %}">Forgot Password?</a>
</div>
<div class="line mb-3"></div>
<a class="custom-signin" href="{{ form_alt_action }}">
<button class="btn btn-primary mb-3" type="submit">{{ form_alt_text }}</button>
Expand Down
13 changes: 8 additions & 5 deletions app/capstone/transformer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,15 @@ def store(request: HttpRequest) -> HttpResponse:
class CreateCheckoutSessionView(View):
def post(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: # type: ignore
if request.user.is_authenticated:
if has_valid_subscription(request.user.id):
messages.error(request, "You already have an active subscription.")
product_id = self.kwargs["pk"]
product = Product.objects.get(id=product_id)
if has_valid_subscription(request.user.id) and has_premium_subscription(request.user.id) and product.name != "Premium Subscription":
messages.error(request, "Please purchase another premium subscription or cancel your existing subscription.")
return redirect("store")
elif has_valid_subscription(request.user.id) and has_premium_subscription(request.user.id) is False and product.name == "Premium Subscription":
messages.error(request, "Please cancel your existing subscription before purchasing a premium subscription.")
return redirect("store")
else:
product_id = self.kwargs["pk"]
product = Product.objects.get(id=product_id)
stripe.api_key = settings.STRIPE_SECRET_KEY # type: ignore
YOUR_DOMAIN = settings.DOMAIN # type: ignore
checkout_session = stripe.checkout.Session.create(
Expand Down Expand Up @@ -580,7 +583,7 @@ def profile(request: HttpRequest) -> HttpResponse:
)
elif "delete" in request.POST:
subscription_form = SubscriptionDeletionForm(request.POST)
if subscription_form.is_valid() and subscription_form.cleaned_data.get("delete") and has_valid_subscription(request.user.id): # type: ignore
if subscription_form.is_valid() and subscription_form.cleaned_data.get("delete"):
user = User.objects.get(id=request.user.id) # type: ignore
delete_subscription(user)
messages.success(request, f"Your subscription has been deleted.")
Expand Down
Binary file added docs/img/burnup-22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/burnup-23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/esteban-eval-21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/esteban-eval-22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/esteban-tasks-21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/esteban-tasks-22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/keiran-eval-22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/keiran-w22-tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/liam-eval-22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/liam-eval-23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/liam-w22-tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/liam-w23-tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/table-22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 50 additions & 2 deletions docs/weekly-logs/personal-logs/esteban.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,54 @@ _Team Evaluation Screenshot_

### Self Reflection and Learning

This week the team decided to foxus on merging the multiple large features that had been getting worked on over the break. We mostly focused on more intensive code review and fixing merge conflict with the master branch, as well as locating bugs that arose later as a result of the merging. We also had a couple of meetings to discuss the peer testing tasks for the upcoming session and prepare the deployed site.
This week the team decided to focus on merging the multiple large features that had been getting worked on over the break. We mostly focused on more intensive code review and fixing merge conflict with the master branch, as well as locating bugs that arose later as a result of the merging. We also had a couple of meetings to discuss the peer testing tasks for the upcoming session and prepare the deployed site.

I also took some time to reorganize the tasks we had set up in the Github Project and organize them into new milestones which cover progress up until the end of the project. I also added start and end dates to every issue in the project so we could best use the timeline feature of the board and follow a schedule which let us cover all the work we want by the end of the project.
I also took some time to reorganize the tasks we had set up in the Github Project and organize them into new milestones which cover progress up until the end of the project. I also added start and end dates to every issue in the project so we could best use the timeline feature of the board and follow a schedule which let us cover all the work we want by the end of the project.

## Feb 04 2024 -> Mar 10 2024

![evaluation-screenshot](../../img/esteban-eval-21.png)
<br>
_Team Evaluation Screenshot_

<br>

### Tasks

![tasks-screenshot](../../img/esteban-tasks-21.png)

### Goals

- [x] Re-prompting tasks meeting
- [x] Bug fixes
- [x] Peer testing issues
- [ ] Front-end Reprompt
- [x] PDF Rework (`iframe`)
- [ ] Slide selection form (WIP)

### Self Reflection and Learning

This week we focused on the second peer testing round, which included some new UI changes and bugfixes. I also continued work on the frontend of the re-prompting feature by reworking our PDF preview system to use an `<iframe>` element instead of the previous method with JavaScript. I will continue working on a method to specify which slides to re-prompt that will hopefully be part of the PDF preview system.

## Mar 11 2024 -> Mar 18 2024

![evaluation-screenshot](../../img/esteban-eval-22.png)
<br>
_Team Evaluation Screenshot_

<br>

### Tasks

![tasks-screenshot](../../img/esteban-tasks-22.png)

### Goals

- [x] Frontend Formset
- [x] Variable form fields
- [x] Variable form values (slide numbers)
- [x] View routing

### Self Reflection and Learning

This week I completed work on the frontend to process the form we will use for the reprompting system. This entailed working with the Django FromSet to manage multiple forms in the frontend. The user will be able to add more forms to do multiple reprompts. I also had to read the appropriate PDF slides to generate a variable form value.
19 changes: 18 additions & 1 deletion docs/weekly-logs/personal-logs/keiran.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,21 @@ _Tasks Screenshot_
1. Fix Stripe payments (subscription_checkout branch)
2. Stripe user permissions (subscription_checkout branch)

[16]: https://github.com/orgs/COSC-499-W2023/projects/1/views/8?filterQuery=+assignee%3A%40me
[16]: https://github.com/orgs/COSC-499-W2023/projects/1/views/8?filterQuery=+assignee%3A%40me

## Feb 5 -> Mar 10

Missed these logs.

## Mar 11 -> 17

![evaluation screenshot](../../img/keiran-w22-tasks.png)
_Team evaluation Screenshot_

![w17 tasks screenshot](../../img/keiran-eval-22.png)
_Tasks Screenshot_

### Goals this week
1. Start exercise creation backend
2. Add markdown input
3. Finish subscription issues
44 changes: 44 additions & 0 deletions docs/weekly-logs/personal-logs/liam.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,48 @@ Note: I forgot to do my log for week 20. I was working on implementing the forgo
<br>


<br>


## Mar 4 2024 -> Mar 10 2024

![evaluation-screenshot](../../img/liam-eval-22.png)
<br>
_Team Evaluation Screenshot_

<br>

### Goals/Features this week

![tasks-screenshot](../../img/liam-w22-tasks.png)
<br>
Note: This week I added input validation for the transformer page.

<br>
[Individual Tasks](https://github.com/orgs/COSC-499-W2023/projects/1/views/8?filterQuery=liamras&sortedBy%5Bdirection%5D=asc&sortedBy%5BcolumnId%5D=Milestone)
<br>
[Latest PR](https://github.com/COSC-499-W2023/year-long-project-team-7/pull/262)


<br>


## Mar 11 2024 -> Mar 17 2024

![evaluation-screenshot](../../img/liam-eval-23.png)
<br>
_Team Evaluation Screenshot_

<br>

### Goals/Features this week

![tasks-screenshot](../../img/liam-w23-tasks.png)

<br>
[Individual Tasks](https://github.com/orgs/COSC-499-W2023/projects/1/views/8?filterQuery=liamras&sortedBy%5Bdirection%5D=asc&sortedBy%5BcolumnId%5D=Milestone)
<br>
[Latest PR](https://github.com/COSC-499-W2023/year-long-project-team-7/pull/269)


<br>
26 changes: 26 additions & 0 deletions docs/weekly-logs/team-logs/teamlog-W22.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Team 7 Log

| Full Name | GitHub username |
| ---------------- | ----------------------------------------------- |
| Esteban Martinez | [PatchFact](https://github.com/PatchFact) |
| Ferdinand Haaben | [Ferdinand737](https://github.com/Ferdinand737) |
| Keiran Malott | [kmalott](https://github.com/kmalott) |
| Liam Rasmussen | [liamras](https://github.com/liamras) |

## Feb 26 2024 -> Mar 03 2024

### Recap of goals

<br>

![table-screenshot](../../img/burnup-22.png)
<br>
_Burnup chart Screenshot_

![table-screenshot](../../img/table-22.png)
<br>
[_Tasks Screenshot_](https://github.com/orgs/COSC-499-W2023/projects/1/views/8?filterQuery=milestone%3A%22Backlog%22%2C%22Before+Peer+2%22)

<br>

[Test Outputs](https://github.com/COSC-499-W2023/year-long-project-team-7/actions)

0 comments on commit 9636db7

Please sign in to comment.